Skip to content

Commit

Permalink
adapting parameter stuff for jupedsim to make model configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Feb 14, 2024
1 parent ce0c66e commit b4a731b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/microsim/MSFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,18 @@ MSFrame::fillOptions() {

oc.doRegister("pedestrian.jupedsim.step-length", new Option_String("0.01", "TIME"));
oc.addDescription("pedestrian.jupedsim.step-length", "Processing", TL("The update interval of the JuPedSim simulation (in seconds)"));

oc.doRegister("pedestrian.jupedsim.exit-tolerance", new Option_Float(1.));
oc.addDescription("pedestrian.jupedsim.exit-tolerance", "Processing", TL("The distance to the destination point considered as arrival (in meters)"));
oc.doRegister("pedestrian.jupedsim.model", new Option_String("CollisionFreeSpeed"));
oc.addDescription("pedestrian.jupedsim.model", "Processing", TL("The submodel to use in jupedsim"));
oc.doRegister("pedestrian.jupedsim.strength-neighbor-repulsion", new Option_Float(8.));
oc.addDescription("pedestrian.jupedsim.strength-neighbor-repulsion", "Processing", TL("The distance to the destination point considered as arrival (in meters)"));
oc.doRegister("pedestrian.jupedsim.range-neighbor-repulsion", new Option_Float(.1));
oc.addDescription("pedestrian.jupedsim.range-neighbor-repulsion", "Processing", TL("The distance to the destination point considered as arrival (in meters)"));
oc.doRegister("pedestrian.jupedsim.strength-geometry-repulsion", new Option_Float(5.));
oc.addDescription("pedestrian.jupedsim.strength-geometry-repulsion", "Processing", TL("The distance to the destination point considered as arrival (in meters)"));
oc.doRegister("pedestrian.jupedsim.range-geometry-repulsion", new Option_Float(.02));
oc.addDescription("pedestrian.jupedsim.range-geometry-repulsion", "Processing", TL("The distance to the destination point considered as arrival (in meters)"));

oc.doRegister("ride.stop-tolerance", new Option_Float(10.));
oc.addDescription("ride.stop-tolerance", "Processing", TL("Tolerance to apply when matching pedestrian and vehicle positions on boarding at individual stops"));
Expand Down
38 changes: 28 additions & 10 deletions src/microsim/transportables/MSPModel_JuPedSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const double MSPModel_JuPedSim::GEOS_BUFFERED_SEGMENT_WIDTH = 0.5 * SUMO_const_l
MSPModel_JuPedSim::MSPModel_JuPedSim(const OptionsCont& oc, MSNet* net) :
myNetwork(net), myJPSDeltaT(string2time(oc.getString("pedestrian.jupedsim.step-length"))),
myExitTolerance(oc.getFloat("pedestrian.jupedsim.exit-tolerance")), myHaveAdditionalWalkableAreas(false) {
initialize();
initialize(oc);
net->getBeginOfTimestepEvents()->addEvent(new Event(this), net->getCurrentTimeStep() + DELTA_T);
}

Expand All @@ -73,7 +73,7 @@ MSPModel_JuPedSim::~MSPModel_JuPedSim() {
if (myJPSGeometryWithTrains != nullptr) {
JPS_Geometry_Free(myJPSGeometryWithTrains);
}

GEOSGeom_destroy(myGEOSPedestrianNetwork);
finishGEOS();
}
Expand Down Expand Up @@ -769,7 +769,7 @@ MSPModel_JuPedSim::preparePolygonForDrawing(const GEOSGeometry* polygon, const s
}


JPS_Geometry
JPS_Geometry
MSPModel_JuPedSim::buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon) {
// For the moment, JuPedSim only supports one connected component, select the one with max area.
int nbrConnectedComponents = GEOSGetNumGeometries(polygon);
Expand Down Expand Up @@ -806,7 +806,7 @@ MSPModel_JuPedSim::buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon)
JPS_ErrorMessage_Free(message);
throw ProcessError(error);
} else {
WRITE_MESSAGE("Geometry generation done.");
PROGRESS_DONE_MESSAGE();
}
JPS_GeometryBuilder_Free(geometryBuilder);
return geometry;
Expand All @@ -827,15 +827,33 @@ MSPModel_JuPedSim::dumpGeometry(const GEOSGeometry* polygon, const std::string&


void
MSPModel_JuPedSim::initialize() {
MSPModel_JuPedSim::initialize(const OptionsCont& oc) {
initGEOS(nullptr, nullptr);
WRITE_MESSAGE("Generating initial JuPedSim geometry for pedestrian network...");
PROGRESS_BEGIN_MESSAGE("Generating initial JuPedSim geometry for pedestrian network");
myGEOSPedestrianNetwork = buildPedestrianNetwork(myNetwork);
myJPSGeometry = buildJPSGeometryFromGEOSGeometry(myGEOSPedestrianNetwork);
myJPSGeometryWithTrains = nullptr;
myJPSModelBuilder = JPS_CollisionFreeSpeedModelBuilder_Create(8.0, 0.1, 5.0, 0.02);
JPS_ErrorMessage message = nullptr;
myJPSModel = JPS_CollisionFreeSpeedModelBuilder_Build(myJPSModelBuilder, &message);

double strengthGeometryRepulsion = oc.getFloat("pedestrian.jupedsim.strength-geometry-repulsion");
double rangeGeometryRepulsion = oc.getFloat("pedestrian.jupedsim.range-geometry-repulsion");
if (myJPSDeltaT == 20) {
if (oc.isDefault("pedestrian.jupedsim.strength-geometry-repulsion") && oc.isDefault("pedestrian.jupedsim.range-geometry-repulsion")) {
WRITE_MESSAGE(TL("Adapting geometry repulsion default values for jupedsim timestep of 0.02."));
strengthGeometryRepulsion = 35.;
rangeGeometryRepulsion = 0.019;
}
}
if (oc.getString("pedestrian.jupedsim.model") == "CollisionFreeSpeed") {
JPS_CollisionFreeSpeedModelBuilder modelBuilder = JPS_CollisionFreeSpeedModelBuilder_Create(oc.getFloat("pedestrian.jupedsim.strength-neighbor-repulsion"),
oc.getFloat("pedestrian.jupedsim.range-neighbor-repulsion"),
strengthGeometryRepulsion, rangeGeometryRepulsion);
myJPSModel = JPS_CollisionFreeSpeedModelBuilder_Build(modelBuilder, &message);
JPS_CollisionFreeSpeedModelBuilder_Free(modelBuilder);
} else {
throw ProcessError(TLF("Unknown JuPedSim model: %", oc.getString("pedestrian.jupedsim.model")));
}

if (myJPSModel == nullptr) {
const std::string error = TLF("Error creating the pedestrian model: %", JPS_ErrorMessage_GetMessage(message));
JPS_ErrorMessage_Free(message);
Expand All @@ -850,8 +868,8 @@ MSPModel_JuPedSim::initialize() {
// Polygons that define vanishing areas aren't part of the regular JuPedSim geometry.
for (const auto& polygonWithID : myNetwork->getShapeContainer().getPolygons()) {
if (polygonWithID.second->getShapeType() == "jupedsim.vanishing_area") {
std::vector<JPS_Point> vanishingAreaBoundary = convertToJPSPoints(polygonWithID.second->getShape());
SUMOTime period = (SUMOTime)(1.0 / std::stod(polygonWithID.second->getParameter("frequency", "1.0"))) * 1000; // SUMOTime is in ms.
const std::vector<JPS_Point>& vanishingAreaBoundary = convertToJPSPoints(polygonWithID.second->getShape());
const SUMOTime period = string2time(polygonWithID.second->getParameter("period", "1"));
myVanishingAreas.insert(std::make_pair(polygonWithID.second->getID(), VanishingAreaData{vanishingAreaBoundary, period}));
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/microsim/transportables/MSPModel_JuPedSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ class MSPModel_JuPedSim : public MSPModel {

JPS_Geometry myJPSGeometry;
JPS_Geometry myJPSGeometryWithTrains;
JPS_CollisionFreeSpeedModelBuilder myJPSModelBuilder;
JPS_OperationalModel myJPSModel;
JPS_Simulation myJPSSimulation;
struct VanishingAreaData {
std::vector<JPS_Point> vanishingAreaBoundary;
const std::vector<JPS_Point> vanishingAreaBoundary;
SUMOTime period;
};
std::map<std::string, VanishingAreaData> myVanishingAreas;
Expand All @@ -175,7 +174,7 @@ class MSPModel_JuPedSim : public MSPModel {
static const double GEOS_MIN_AREA;
static const double GEOS_BUFFERED_SEGMENT_WIDTH;

void initialize();
void initialize(const OptionsCont& oc);
void tryPedestrianInsertion(PState* state, const Position& p);
bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const Position& point, const std::string& agentID);
static MSLane* getNextPedestrianLane(const MSLane* const currentLane);
Expand Down

2 comments on commit b4a731b

@namdre
Copy link
Contributor

@namdre namdre commented on b4a731b Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a jupedsim ticket to which this may be linked?

@behrisch
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.