Skip to content

Commit

Permalink
some fixes for persons on inductionLoop. refs #5252
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Sep 27, 2021
1 parent bd6bce8 commit 16bd3d8
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/microsim/output/MSDetectorFileOutput.cpp
Expand Up @@ -65,10 +65,9 @@ MSDetectorFileOutput::vehicleApplies(const SUMOTrafficObject& veh) const {
}

bool
MSDetectorFileOutput::personApplies(const MSTransportable& p) const {
MSDetectorFileOutput::personApplies(const MSTransportable& p, int dir) const {
//std::cout << getID() << " p=" << p.getID() << " veh=" << Named::getIDSecure(p.getVehicle()) << "\n";
if (p.getVehicle() == nullptr) {
const int dir = p.getDirection();
const int dirCode = dir < 0 ? 2 : dir;
//std::cout << " dir=" << dir << " dirCode=" << dirCode << " myDetectPersons=" << myDetectPersons << "\n";
if ((dirCode & myDetectPersons) == 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/microsim/output/MSDetectorFileOutput.h
Expand Up @@ -61,7 +61,7 @@ enum DetectorUsage {
class MSDetectorFileOutput : public Named {
public:
/// @brief Constructor
MSDetectorFileOutput(const std::string& id, const std::string& vTypes, const int detectPersons = false);
MSDetectorFileOutput(const std::string& id, const std::string& vTypes, const int detectPersons = false);

/// @brief Constructor
MSDetectorFileOutput(const std::string& id, const std::set<std::string>& vTypes, const int detectPersons = false);
Expand Down Expand Up @@ -129,9 +129,9 @@ class MSDetectorFileOutput : public Named {
* @param[in] veh the vehicle of which the type is checked.
* @return whether it should be measured
*/
bool vehicleApplies(const SUMOTrafficObject& veh) const;
bool vehicleApplies(const SUMOTrafficObject& veh) const;

bool personApplies(const MSTransportable& p) const;
bool personApplies(const MSTransportable& p, int dir) const;


/** @brief Checks whether the detector is type specific.
Expand Down
38 changes: 23 additions & 15 deletions src/microsim/output/MSInductLoop.cpp
Expand Up @@ -155,8 +155,12 @@ MSInductLoop::notifyMove(SUMOTrafficObject& veh, double oldPos,


bool
MSInductLoop::notifyLeave(SUMOTrafficObject& veh, double /* lastPos */, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
if (reason != MSMoveReminder::NOTIFICATION_JUNCTION) {
MSInductLoop::notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
if (veh.isPerson() && myDetectPersons != (int)PersonMode::NONE) {
const int lastDir = lastPos < 0 ? MSPModel::BACKWARD : MSPModel::FORWARD;
notifyMovePerson(dynamic_cast<MSTransportable*>(&veh), lastDir, lastPos);
}
if (reason != MSMoveReminder::NOTIFICATION_JUNCTION || (veh.isPerson() && myDetectPersons != (int)PersonMode::NONE)) {
#ifdef HAVE_FOX
FXConditionalLock lock(myNotificationMutex, myNeedLock);
#endif
Expand Down Expand Up @@ -289,19 +293,23 @@ MSInductLoop::detectorUpdate(const SUMOTime /* step */) {
if (p->getLane() != myLane) {
continue;
}
if (personApplies(*p)) {
const int dir = p->getDirection();
const double newSpeed = p->getSpeed();
const double newPos = p->getPositionOnLane();
const double oldPos = newPos - dir * newSpeed;
if (dir == MSPModel::FORWARD) {
notifyMove(*p, oldPos, newPos, newSpeed);
} else {
// ensure that newPos > oldPos even if the person walks
// against edge direction
notifyMove(*p, newPos, oldPos, newSpeed);
}
}
notifyMovePerson(p, p->getDirection(), p->getPositionOnLane());
}
}
}


void
MSInductLoop::notifyMovePerson(MSTransportable* p, int dir, double pos) {
if (personApplies(*p, dir)) {
const double newSpeed = p->getSpeed();
const double newPos = (dir == MSPModel::FORWARD
? pos
// position relative to detector
: myPosition - (pos - myPosition));
const double oldPos = newPos - SPEED2DIST(newSpeed);
if (oldPos - p->getVehicleType().getLength() <= myPosition) {
notifyMove(*p, oldPos, newPos, newSpeed);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/microsim/output/MSInductLoop.h
Expand Up @@ -315,6 +315,8 @@ class MSInductLoop
}
///@}

/// @brief helper function for mapping person movement
void notifyMovePerson(MSTransportable* p, int dir, double pos);

protected:
/// @brief Detector's position on lane [m]
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSPModel_NonInteracting.cpp
Expand Up @@ -102,7 +102,7 @@ MSPModel_NonInteracting::MoveToNextEdge::execute(SUMOTime currentTime) {
return 0; // descheduled
}
const MSEdge* old = myParent.getEdge();
const bool arrived = myParent.moveToNextEdge(myTransportable, currentTime);
const bool arrived = myParent.moveToNextEdge(myTransportable, currentTime, myParent.getState()->getDirection(myParent, currentTime));
if (arrived) {
myModel->registerArrived();
return 0;
Expand Down
8 changes: 4 additions & 4 deletions src/microsim/transportables/MSPModel_Striping.cpp
Expand Up @@ -1096,7 +1096,7 @@ MSPModel_Striping::arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTi
myActiveLanes[p->myLane].push_back(p);
} else {
// end walking stage and destroy PState
p->myStage->moveToNextEdge(p->myPerson, currentTime);
p->myStage->moveToNextEdge(p->myPerson, currentTime, dir);
myNumActivePedestrians--;
}
}
Expand Down Expand Up @@ -1635,7 +1635,7 @@ MSPModel_Striping::PState::moveToNextLane(SUMOTime currentTime) {
if (myStage->getRouteStep() == myStage->getRoute().end() - 1) {
myLane = nullptr;
} else {
const bool arrived = myStage->moveToNextEdge(myPerson, currentTime, normalLane ? nullptr : &myLane->getEdge());
const bool arrived = myStage->moveToNextEdge(myPerson, currentTime, oldDir, normalLane ? nullptr : &myLane->getEdge());
UNUSED_PARAMETER(arrived);
assert(!arrived);
assert(myDir != UNDEFINED_DIRECTION);
Expand Down Expand Up @@ -1664,7 +1664,7 @@ MSPModel_Striping::PState::moveToNextLane(SUMOTime currentTime) {
|| nextRouteEdge->getFromJunction() == currRouteEdge->getToJunction()) {
myDir = FORWARD;
}
myStage->moveToNextEdge(myPerson, currentTime, nullptr);
myStage->moveToNextEdge(myPerson, currentTime, oldDir, nullptr);
myLane = myNLI.lane;
assert(myLane != 0);
assert(myLane->getEdge().getFunction() == SumoXMLEdgeFunc::NORMAL);
Expand Down Expand Up @@ -2108,7 +2108,7 @@ MSPModel_Striping::PState::moveToXY(MSPerson* p, Position pos, MSLane* lane, dou
myStage->replaceRoute(myPerson, edges, routeOffset);
}
if (!lane->getEdge().isNormal()) {
myStage->moveToNextEdge(myPerson, t, &lane->getEdge());
myStage->moveToNextEdge(myPerson, t, myDir, &lane->getEdge());
}

myLane = lane;
Expand Down
14 changes: 10 additions & 4 deletions src/microsim/transportables/MSPerson.cpp
Expand Up @@ -270,16 +270,22 @@ MSPerson::MSPersonStage_Walking::routeOutput(const bool /* isPerson */, OutputDe


bool
MSPerson::MSPersonStage_Walking::moveToNextEdge(MSTransportable* person, SUMOTime currentTime, MSEdge* nextInternal) {
MSPerson::MSPersonStage_Walking::moveToNextEdge(MSTransportable* person, SUMOTime currentTime, int prevDir, MSEdge* nextInternal) {
((MSEdge*)getEdge())->removePerson(person);
const MSLane* lane = getSidewalk<MSEdge, MSLane>(getEdge());
const bool arrived = myRouteStep == myRoute.end() - 1;
if (lane != nullptr) {
const double tl = person->getVehicleType().getLength();
const double lastPos = (arrived
? (prevDir == MSPModel::FORWARD
? getArrivalPos() + tl
: getArrivalPos() - tl)
: (prevDir == MSPModel::FORWARD
? lane->getLength() + tl
: -tl));
for (MSMoveReminder* rem : myMoveReminders) {
rem->updateDetector(*person, 0.0, lane->getLength(), myLastEdgeEntryTime, currentTime, currentTime, true);
rem->notifyLeave(*person,
arrived ? getArrivalPos() : lane->getLength(),
arrived ? MSMoveReminder::NOTIFICATION_ARRIVED : MSMoveReminder::NOTIFICATION_JUNCTION);
rem->notifyLeave(*person, lastPos, arrived ? MSMoveReminder::NOTIFICATION_ARRIVED : MSMoveReminder::NOTIFICATION_JUNCTION);
}
}
if (myExitTimes != nullptr && nextInternal == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSPerson.h
Expand Up @@ -118,7 +118,7 @@ class MSPerson : public MSTransportable {
virtual void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const;

/// @brief move forward and return whether the person arrived
bool moveToNextEdge(MSTransportable* person, SUMOTime currentTime, MSEdge* nextInternal = nullptr);
bool moveToNextEdge(MSTransportable* person, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = nullptr);

/// @brief accessors to be used by MSPModel
//@{
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSStage.h
Expand Up @@ -504,7 +504,7 @@ class MSStageMoving : public MSStage {
virtual double getMaxSpeed(const MSTransportable* const transportable = nullptr) const = 0;

/// @brief move forward and return whether the transportable arrived
virtual bool moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, MSEdge* nextInternal = 0) = 0;
virtual bool moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = 0) = 0;

/// @brief place transportable on a previously passed edge
virtual void setRouteIndex(MSTransportable* const transportable, int routeOffset);
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSStageTranship.cpp
Expand Up @@ -132,7 +132,7 @@ MSStageTranship::routeOutput(const bool /*isPerson*/, OutputDevice& os, const bo


bool
MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, MSEdge* /* nextInternal */) {
MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int /*prevDir*/, MSEdge* /* nextInternal */) {
if (transportable->isPerson()) {
getEdge()->removePerson(transportable);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSStageTranship.h
Expand Up @@ -94,7 +94,7 @@ class MSStageTranship : public MSStageMoving {
void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const;

/// @brief move forward and return whether the container arrived
bool moveToNextEdge(MSTransportable* container, SUMOTime currentTime, MSEdge* nextInternal = 0);
bool moveToNextEdge(MSTransportable* container, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = 0);


/// @brief the maximum speed of the transportable
Expand Down

0 comments on commit 16bd3d8

Please sign in to comment.