Skip to content

Commit

Permalink
first mini example with person rerouter working #1722
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Jan 2, 2024
1 parent 2c9189d commit f0c3f02
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/microsim/transportables/MSPerson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@ MSPerson::MSPersonStage_Walking::proceed(MSNet* net, MSTransportable* person, SU
pControl.erase(person);
return;
}
const MSLane* const lane = getSidewalk<MSEdge, MSLane>(getEdge());
if (lane != nullptr) {
for (MSMoveReminder* rem : lane->getMoveReminders()) {
if (rem->notifyEnter(*person, MSMoveReminder::NOTIFICATION_DEPARTED, lane)) {
myMoveReminders.push_back(rem);
if (previous->getStageType() != MSStageType::WALKING || previous->getEdge() != getEdge()) {
// we only need new move reminders if we are walking a different edge (else it is probably a rerouting)
const MSLane* const lane = getSidewalk<MSEdge, MSLane>(getEdge());
if (lane != nullptr) {
for (MSMoveReminder* rem : lane->getMoveReminders()) {
if (rem->notifyEnter(*person, MSMoveReminder::NOTIFICATION_DEPARTED, lane)) {
myMoveReminders.push_back(rem);
}
}
}
}
Expand Down Expand Up @@ -633,7 +636,7 @@ MSPerson::getNextEdgePtr() const {


void
MSPerson::reroute(ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex) {
MSPerson::reroute(const ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex) {
assert(nextIndex > firstIndex);
//std::cout << SIMTIME << " reroute person " << getID()
// << " newEdges=" << toString(newEdges)
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSPerson.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class MSPerson : public MSTransportable {
bool isJammed() const;

/// @brief set new walk and replace the stages with relative indices in the interval [firstIndex, nextIndex[
void reroute(ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex);
void reroute(const ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex);


/** @class Influencer
Expand Down
7 changes: 5 additions & 2 deletions src/microsim/transportables/MSTransportable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,11 @@ MSTransportable::setSpeed(double speed) {

bool
MSTransportable::replaceRoute(ConstMSRoutePtr newRoute, const std::string& /* info */, bool /* onInit */, int /* offset */, bool /* addRouteStops */, bool /* removeStops */, std::string* /* msgReturn */) {
const ConstMSEdgeVector& edges = newRoute->getEdges();
return true;
if (isPerson()) {
static_cast<MSPerson*>(this)->reroute(newRoute->getEdges(), getPositionOnLane(), 0, 1);
return true;
}
return false;
}


Expand Down
19 changes: 15 additions & 4 deletions src/microsim/trigger/MSTriggeredRerouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <microsim/MSGlobals.h>
#include <microsim/MSParkingArea.h>
#include <microsim/MSStop.h>
#include <microsim/transportables/MSTransportable.h>
#include <microsim/transportables/MSPerson.h>
#include <microsim/devices/MSDevice_Routing.h>
#include <microsim/devices/MSRoutingEngine.h>
#include "MSTriggeredRerouter.h"
Expand Down Expand Up @@ -566,12 +566,21 @@ MSTriggeredRerouter::notifyEnter(SUMOTrafficObject& tObject, MSMoveReminder::Not
}
} else {
// person rerouting here
std::vector<MSTransportableRouter::TripItem> result;
std::vector<MSTransportableRouter::TripItem> items;
MSTransportableRouter& router = hasReroutingDevice
? MSRoutingEngine::getIntermodalRouterTT(tObject.getRNGIndex(), rerouteDef->closed)
: MSNet::getInstance()->getIntermodalRouter(tObject.getRNGIndex(), 0, rerouteDef->closed);
router.compute(tObject.getEdge(), newEdge, tObject.getPositionOnLane(), "", tObject.getParameter().arrivalPos, "",
tObject.getMaxSpeed(), nullptr, 0, now, result);
const bool success = router.compute(tObject.getEdge(), newEdge, tObject.getPositionOnLane(), "",
tObject.getParameter().arrivalPos, "",
tObject.getMaxSpeed(), nullptr, 0, now, items);
if (success) {
MSPerson& p = static_cast<MSPerson&>(tObject);
for (const MSTransportableRouter::TripItem& it : items) {
if (!it.edges.empty()) {
p.reroute(it.edges, tObject.getPositionOnLane(), 0, 1);
}
}
}
}
}
return false; // XXX another interval could appear later but we would have to track whether the currenty interval was already used
Expand Down Expand Up @@ -1261,4 +1270,6 @@ MSTriggeredRerouter::checkParkingRerouteConsistency() {
}
}
}


/****************************************************************************/

0 comments on commit f0c3f02

Please sign in to comment.