Skip to content

Commit

Permalink
improving meso notifications, fix #4593
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Sep 13, 2018
1 parent 8c80c8e commit 5fc383e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/mesosim/MELoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ MELoop::changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSeg
MESegment* const onSegment = veh->getSegment();
if (MESegment::isInvalid(toSegment)) {
if (onSegment != 0) {
onSegment->send(veh, toSegment, leaveTime);
onSegment->send(veh, toSegment, leaveTime, toSegment == nullptr ? MSMoveReminder::NOTIFICATION_TELEPORT_ARRIVED : MSMoveReminder::NOTIFICATION_VAPORIZED);
} else {
WRITE_WARNING("Vehicle '" + veh->getID() + "' teleports beyond arrival edge '" + veh->getEdge()->getID() + "', time " + time2string(leaveTime) + ".");
}
Expand All @@ -92,7 +92,7 @@ MELoop::changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSeg
}
if (toSegment->hasSpaceFor(veh, leaveTime) && (ignoreLink || veh->mayProceed())) {
if (onSegment != 0) {
onSegment->send(veh, toSegment, leaveTime);
onSegment->send(veh, toSegment, leaveTime, toSegment->getNextSegment() == nullptr ? MSMoveReminder::NOTIFICATION_JUNCTION : MSMoveReminder::NOTIFICATION_SEGMENT);
toSegment->receive(veh, leaveTime, false, ignoreLink);
} else {
WRITE_WARNING("Vehicle '" + veh->getID() + "' ends teleporting on edge '" + toSegment->getEdge().getID()
Expand Down Expand Up @@ -173,7 +173,7 @@ MELoop::teleportVehicle(MEVehicle* veh, MESegment* const toSegment) {
+ "':" + toString(onSegment->getIndex()) + ", time " + time2string(leaveTime) + ".");
MSNet::getInstance()->getVehicleControl().registerTeleportJam();
// remove from current segment
onSegment->send(veh, 0, leaveTime);
onSegment->send(veh, 0, leaveTime, MSMoveReminder::NOTIFICATION_TELEPORT);
// mark veh as teleporting
veh->setSegment(0, 0);
}
Expand Down
26 changes: 5 additions & 21 deletions src/mesosim/MESegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,6 @@ MESegment::removeDetector(MSMoveReminder* data) {
}


void
MESegment::updateDetectorsOnLeave(MEVehicle* v, SUMOTime currentTime, MESegment* next) {
MSMoveReminder::Notification reason;
if (next == 0) {
reason = MSMoveReminder::NOTIFICATION_ARRIVED;
} else if (next == &myVaporizationTarget) {
reason = MSMoveReminder::NOTIFICATION_VAPORIZED;
} else if (myNextSegment == 0) {
reason = MSMoveReminder::NOTIFICATION_JUNCTION;
} else {
reason = MSMoveReminder::NOTIFICATION_SEGMENT;
}
v->updateDetectors(currentTime, true, reason);
}


void
MESegment::prepareDetectorForWriting(MSMoveReminder& data) {
const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
Expand Down Expand Up @@ -352,12 +336,12 @@ MESegment::writeVehicles(OutputDevice& of) const {


MEVehicle*
MESegment::removeCar(MEVehicle* v, SUMOTime leaveTime, MESegment* next) {
MESegment::removeCar(MEVehicle* v, SUMOTime leaveTime, const MSMoveReminder::Notification reason) {
myOccupancy = MAX2(0., myOccupancy - v->getVehicleType().getLengthWithGap());
std::vector<MEVehicle*>& cars = myCarQues[v->getQueIndex()];
assert(std::find(cars.begin(), cars.end(), v) != cars.end());
// One could be tempted to do v->setSegment(next); here but position on lane will be invalid if next == 0
updateDetectorsOnLeave(v, leaveTime, next);
v->updateDetectors(leaveTime, true, reason);
myEdge.lock();
if (v == cars.back()) {
cars.pop_back();
Expand Down Expand Up @@ -480,13 +464,13 @@ MESegment::limitedControlOverride(const MSLink* link) const {


void
MESegment::send(MEVehicle* veh, MESegment* next, SUMOTime time) {
MESegment::send(MEVehicle* veh, MESegment* next, SUMOTime time, const MSMoveReminder::Notification reason) {
assert(isInvalid(next) || time >= myBlockTimes[veh->getQueIndex()]);
MSLink* link = getLink(veh);
if (link != 0) {
link->removeApproaching(veh);
}
MEVehicle* lc = removeCar(veh, time, next); // new leaderCar
MEVehicle* lc = removeCar(veh, time, reason); // new leaderCar
myBlockTimes[veh->getQueIndex()] = time;
if (!isInvalid(next)) {
myLastHeadway = next->getTimeHeadway(this, veh);
Expand Down Expand Up @@ -529,7 +513,7 @@ MESegment::receive(MEVehicle* veh, SUMOTime time, bool isDepart, bool afterTelep
veh->setEventTime(time + TIME2STEPS(myLength / speed)); // for correct arrival speed
addReminders(veh);
veh->activateReminders(MSMoveReminder::NOTIFICATION_JUNCTION);
updateDetectorsOnLeave(veh, time, 0);
veh->updateDetectors(time, true, MSMoveReminder::NOTIFICATION_ARRIVED);
MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(veh);
return;
}
Expand Down
14 changes: 3 additions & 11 deletions src/mesosim/MESegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ class MESegment : public Named {
*
* @param[in] v The vehicle to remove
* @param[in] leaveTime The time at which the vehicle is leaving the que
* @param[in] next The next segment for this vehicle
* @param[in] reason The reason for removing to send to reminders
* @return The next first vehicle to add to the net's que
*/
MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, MESegment* next);
MEVehicle* removeCar(MEVehicle* v, SUMOTime leaveTime, const MSMoveReminder::Notification reason);

/** @brief Returns the link the given car will use when passing the next junction
*
Expand Down Expand Up @@ -239,7 +239,7 @@ class MESegment : public Named {
* @param[in] time the leave time
* @todo Isn't always time == veh->getEventTime?
*/
void send(MEVehicle* veh, MESegment* next, SUMOTime time);
void send(MEVehicle* veh, MESegment* next, SUMOTime time, const MSMoveReminder::Notification reason);

/** @brief Adds the vehicle to the segment, adapting its parameters
*
Expand Down Expand Up @@ -392,14 +392,6 @@ class MESegment : public Named {
double getTLSCapacity(const MEVehicle* veh) const;

private:
/** @brief Updates data of all detectors for a leaving vehicle
*
* @param[in] v The vehicle to update values for
* @param[in] currentTime The leave time of the vehicle
* @param[in] next The next segment on this vehicles route
*/
void updateDetectorsOnLeave(MEVehicle* v, SUMOTime currentTime, MESegment* next);

bool overtake();

SUMOTime getTimeHeadway(const MESegment* pred, const MEVehicle* veh);
Expand Down

0 comments on commit 5fc383e

Please sign in to comment.