Skip to content

Commit

Permalink
making radius configurable #14514
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Mar 15, 2024
1 parent c20a770 commit 135dd86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
23 changes: 12 additions & 11 deletions src/microsim/transportables/MSPModel_JuPedSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ MSPModel_JuPedSim::tryPedestrianInsertion(PState* state, const Position& p) {


bool
MSPModel_JuPedSim::addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const Position& point, const std::string& agentID) {
MSPModel_JuPedSim::addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const Position& point, const std::string& agentID, const double radius) {
JPS_ErrorMessage message = nullptr;
const JPS_StageId waypointId = JPS_Simulation_AddStageWaypoint(myJPSSimulation, {point.x(), point.y()}, myExitTolerance, &message);
const JPS_StageId waypointId = JPS_Simulation_AddStageWaypoint(myJPSSimulation, {point.x(), point.y()}, radius, &message);
if (message != nullptr) {
WRITE_WARNINGF(TL("Error while adding waypoint for person '%': %"), agentID, JPS_ErrorMessage_GetMessage(message));
JPS_ErrorMessage_Free(message);
Expand Down Expand Up @@ -185,23 +185,24 @@ MSPModel_JuPedSim::add(MSTransportable* person, MSStageMoving* stage, SUMOTime n
departurePosition = departureLane->getShape().positionAtOffset(stage->getDepartPos(), -departureRelativePositionY); // Minus sign is here for legacy reasons.
}

PositionVector waypoints;
std::vector<std::pair<Position, double> >waypoints;
for (const MSEdge* const e : stage->getEdges()) {
waypoints.push_back(getSidewalk<MSEdge, MSLane>(e)->getShape().positionAtOffset(e->getLength() / 2.));
const MSLane* const lane = getSidewalk<MSEdge, MSLane>(e);
waypoints.push_back(std::make_pair(lane->getShape().positionAtOffset(e->getLength() / 2.), lane->getWidth() / 2.));
}
waypoints.pop_back(); // arrival waypoint comes later
if (!waypoints.empty()) {
waypoints.erase(waypoints.begin()); // departure edge also does not need a waypoint
}
const MSLane* const arrivalLane = getSidewalk<MSEdge, MSLane>(stage->getDestination());
const Position arrivalPosition = arrivalLane->getShape().positionAtOffset(stage->getArrivalPos());
waypoints.push_back(arrivalPosition);
waypoints.push_back(std::make_pair(arrivalPosition, stage->getDouble("jupedsim.waypoint.radius", myExitTolerance)));

JPS_JourneyDescription journeyDesc = JPS_JourneyDescription_Create();
JPS_StageId startingStage = 0;
JPS_StageId predecessor = 0;
for (const Position& p : waypoints) {
if (!addWaypoint(journeyDesc, predecessor, p, person->getID())) {
for (const std::pair<Position, double>& p : waypoints) {
if (!addWaypoint(journeyDesc, predecessor, p.first, person->getID(), p.second)) {
JPS_JourneyDescription_Free(journeyDesc);
return nullptr;
}
Expand Down Expand Up @@ -340,7 +341,7 @@ MSPModel_JuPedSim::execute(SUMOTime time) {
}
}

if (newPosition.distanceTo2D(state->getNextWaypoint()) < 2 * myExitTolerance) {
if (newPosition.distanceTo2D(state->getNextWaypoint().first) < 2 * state->getNextWaypoint().second) {
// If near the last waypoint, remove the agent.
if (state->advanceNextWaypoint()) {
// TODO this only works if the final stage is actually a walk
Expand Down Expand Up @@ -1004,15 +1005,15 @@ MSLane* MSPModel_JuPedSim::getNextPedestrianLane(const MSLane* const currentLane
// ===========================================================================
MSPModel_JuPedSim::PState::PState(MSPerson* person, MSStageMoving* stage,
JPS_JourneyId journeyId, JPS_StageId stageId,
const PositionVector& waypoints)
const std::vector<std::pair<Position, double> >& waypoints)
: myPerson(person), myStage(stage), myJourneyId(journeyId), myStageId(stageId), myWaypoints(waypoints),
myAgentId(0), myPosition(0, 0), myAngle(0), myWaitingToEnter(true) {
}


void
MSPModel_JuPedSim::PState::reinit(MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId,
const PositionVector& waypoints) {
const std::vector<std::pair<Position, double> >& waypoints) {
if (myStage != nullptr) {
myStage->setPState(nullptr); // we need to remove the old state reference to avoid double deletion
}
Expand Down Expand Up @@ -1098,7 +1099,7 @@ const MSEdge* MSPModel_JuPedSim::PState::getNextEdge(const MSStageMoving& stage)
}


const Position& MSPModel_JuPedSim::PState::getNextWaypoint() const {
const std::pair<Position, double>& MSPModel_JuPedSim::PState::getNextWaypoint() const {
return myWaypoints.front();
}

Expand Down
12 changes: 6 additions & 6 deletions src/microsim/transportables/MSPModel_JuPedSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class MSPModel_JuPedSim : public MSPModel {
*/
class PState : public MSTransportableStateAdapter {
public:
PState(MSPerson* person, MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const PositionVector& waypoints);
PState(MSPerson* person, MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<std::pair<Position, double> >& waypoints);
~PState() override;

void reinit(MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const PositionVector& waypoints);
void reinit(MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<std::pair<Position, double> >& waypoints);

Position getPosition(const MSStageMoving& stage, SUMOTime now) const override;
void setPosition(double x, double y);
Expand All @@ -100,7 +100,7 @@ class MSPModel_JuPedSim : public MSPModel {
SUMOTime getWaitingTime(const MSStageMoving& stage, SUMOTime now) const override;
double getSpeed(const MSStageMoving& stage) const override;
const MSEdge* getNextEdge(const MSStageMoving& stage) const override;
const Position& getNextWaypoint() const;
const std::pair<Position, double>& getNextWaypoint() const;
JPS_AgentId getAgentId() const;

/// @brief whether the transportable has finished walking
Expand Down Expand Up @@ -137,7 +137,7 @@ class MSPModel_JuPedSim : public MSPModel {
/// @brief id of the journey, needed for modifying it
JPS_JourneyId myJourneyId;
JPS_StageId myStageId;
PositionVector myWaypoints;
std::vector<std::pair<Position, double> > myWaypoints;
JPS_AgentId myAgentId;
Position myPosition;
Position myPreviousPosition; // Will be initialized to zero automatically.
Expand Down Expand Up @@ -192,7 +192,7 @@ class MSPModel_JuPedSim : public MSPModel {

/// @brief Array of special areas.
std::vector<AreaData> myAreas;

/// @brief Array of stopped trains, used to detect whether to add carriages and ramps to the geometry.
std::vector<SUMOTrafficObject::NumericalID> myAllStoppedTrainIDs;

Expand All @@ -208,7 +208,7 @@ class MSPModel_JuPedSim : public MSPModel {

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);
bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const Position& point, const std::string& agentID, const double radius);
static MSLane* getNextPedestrianLane(const MSLane* const currentLane);
static const Position& getAnchor(const MSLane* const lane, const MSEdge* const edge, MSEdgeVector incoming);
static const MSEdgeVector getAdjacentEdgesOfEdge(const MSEdge* const edge);
Expand Down

0 comments on commit 135dd86

Please sign in to comment.