LCOV - code coverage report
Current view: top level - src/mesosim - MEVehicle.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 86.8 % 326 283
Test Date: 2026-10-12 15:53:19 Functions: 85.3 % 34 29

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MEVehicle.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Tue, May 2005
      18              : ///
      19              : // A vehicle from the mesoscopic point of view
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <iostream>
      24              : #include <cassert>
      25              : #include <utils/common/StdDefs.h>
      26              : #include <utils/common/FileHelpers.h>
      27              : #include <utils/common/MsgHandler.h>
      28              : #include <utils/geom/GeomHelper.h>
      29              : #include <utils/iodevices/OutputDevice.h>
      30              : #include <utils/xml/SUMOSAXAttributes.h>
      31              : #include <microsim/devices/MSDevice_Tripinfo.h>
      32              : #include <microsim/devices/MSDevice_Vehroutes.h>
      33              : #include <microsim/devices/MSDevice_Taxi.h>
      34              : #include <microsim/output/MSStopOut.h>
      35              : #include <microsim/MSGlobals.h>
      36              : #include <microsim/MSEdge.h>
      37              : #include <microsim/MSLane.h>
      38              : #include <microsim/MSNet.h>
      39              : #include <microsim/MSVehicleType.h>
      40              : #include <microsim/MSLink.h>
      41              : #include <microsim/MSStop.h>
      42              : #include <microsim/MSVehicleControl.h>
      43              : #include <microsim/transportables/MSTransportableControl.h>
      44              : #include <microsim/devices/MSDevice.h>
      45              : #include "MELoop.h"
      46              : #include "MEVehicle.h"
      47              : #include "MESegment.h"
      48              : 
      49              : 
      50              : // ===========================================================================
      51              : // method definitions
      52              : // ===========================================================================
      53       906901 : MEVehicle::MEVehicle(SUMOVehicleParameter* pars, ConstMSRoutePtr route,
      54       906901 :                      MSVehicleType* type, const double speedFactor) :
      55              :     MSBaseVehicle(pars, route, type, speedFactor),
      56       906901 :     mySegment(nullptr),
      57       906901 :     myQueIndex(0),
      58       906901 :     myEventTime(SUMOTime_MIN),
      59       906901 :     myLastEntryTime(SUMOTime_MIN),
      60       906901 :     myBlockTime(SUMOTime_MAX),
      61       906901 :     myWasJammed(false),
      62       906901 :     myInfluencer(nullptr) {
      63       906901 : }
      64              : 
      65              : 
      66              : double
      67            0 : MEVehicle::getBackPositionOnLane(const MSLane* /* lane */) const {
      68            0 :     return getPositionOnLane() - getVehicleType().getLength();
      69              : }
      70              : 
      71              : 
      72              : double
      73      8161141 : MEVehicle::getPositionOnLane() const {
      74      8161141 :     if (MSGlobals::gMesoInterpolatePos) {
      75              :         // interpolation may cause problems with arrivals and calibrators
      76            0 :         const auto& mesoPos = getEdge()->getMesoPositions();
      77              :         const auto& posIt = mesoPos.find(this);
      78            0 :         if (posIt != mesoPos.end()) {
      79            0 :             return posIt->second.first;
      80              :         }
      81              :     }
      82      8161141 :     return mySegment == nullptr ? 0. : (double)mySegment->getIndex() * mySegment->getLength();
      83              : }
      84              : 
      85              : 
      86              : double
      87        73713 : MEVehicle::getAngle() const {
      88        73713 :     const MSLane* const lane = getEdge()->getLanes()[MAX2(0, getQueIndex())];
      89        73713 :     return lane->getShape().rotationAtOffset(lane->interpolateLanePosToGeometryPos(getPositionOnLane()));
      90              : }
      91              : 
      92              : 
      93              : double
      94       180787 : MEVehicle::getSlope() const {
      95       180787 :     const MSLane* const lane = getEdge()->getLanes()[MAX2(0, getQueIndex())];
      96       361574 :     return lane->getShape().slopeDegreeAtOffset(lane->interpolateLanePosToGeometryPos(getPositionOnLane()
      97       180787 :                 - (MSGlobals::gSlopeCentered ? getLength() / 2 : 0)));
      98              : }
      99              : 
     100              : 
     101              : const MSEdge*
     102      3704594 : MEVehicle::getCurrentEdge() const {
     103      3704594 :     return mySegment != nullptr ? &mySegment->getEdge() : getEdge();
     104              : }
     105              : 
     106              : 
     107              : Position
     108       440135 : MEVehicle::getPosition(const double offset) const {
     109       440135 :     const MSLane* const lane = getEdge()->getLanes()[MAX2(0, getQueIndex())];
     110       440135 :     return lane->geometryPositionAtOffset(getPositionOnLane() + offset);
     111              : }
     112              : 
     113              : 
     114              : PositionVector
     115            0 : MEVehicle::getBoundingBox(double offset) const {
     116            0 :     double a = getAngle() + M_PI; // angle pointing backwards
     117            0 :     double l = getLength();
     118            0 :     Position pos = getPosition();
     119            0 :     Position backPos = pos + Position(l * cos(a), l * sin(a));
     120            0 :     PositionVector centerLine;
     121            0 :     centerLine.push_back(pos);
     122            0 :     centerLine.push_back(backPos);
     123            0 :     if (offset != 0) {
     124            0 :         centerLine.extrapolate2D(offset);
     125              :     }
     126              :     PositionVector result = centerLine;
     127            0 :     result.move2side(MAX2(0.0, 0.5 * myType->getWidth() + offset));
     128            0 :     centerLine.move2side(MIN2(0.0, -0.5 * myType->getWidth() - offset));
     129            0 :     result.append(centerLine.reverse(), POSITION_EPS);
     130            0 :     return result;
     131            0 : }
     132              : 
     133              : 
     134              : double
     135   1047518714 : MEVehicle::getSpeed() const {
     136   1047518714 :     if (getWaitingTime() > 0 || isStopped()) {
     137   1015130782 :         return 0;
     138              :     } else {
     139     32387932 :         return getAverageSpeed();
     140              :     }
     141              : }
     142              : 
     143              : 
     144              : double
     145     32387932 : MEVehicle::getAverageSpeed() const {
     146              :     // cache for thread safety
     147     32387932 :     MESegment* s = mySegment;
     148     32387932 :     if (s == nullptr || myQueIndex == MESegment::PARKING_QUEUE) {
     149              :         return 0;
     150              :     } else {
     151     32382435 :         return MIN2(s->getLength() / STEPS2TIME(myEventTime - myLastEntryTime),
     152     32382435 :                     getEdge()->getLanes()[myQueIndex]->getVehicleMaxSpeed(this));
     153              :     }
     154              : }
     155              : 
     156              : 
     157              : double
     158      1333187 : MEVehicle::estimateLeaveSpeed(const MSLink* link) const {
     159              :     /// @see MSVehicle.cpp::estimateLeaveSpeed
     160      1333187 :     const double v = getSpeed();
     161      1333187 :     return MIN2(link->getViaLaneOrLane()->getVehicleMaxSpeed(this),
     162      1333187 :                 (double)sqrt(2 * link->getLength() * getVehicleType().getCarFollowModel().getMaxAccel() + v * v));
     163              : }
     164              : 
     165              : 
     166              : double
     167    153750400 : MEVehicle::getConservativeSpeed(SUMOTime& earliestArrival) const {
     168    153750400 :     earliestArrival = MAX2(myEventTime, earliestArrival - DELTA_T); // event times have subsecond resolution
     169    153750400 :     return mySegment->getLength() / STEPS2TIME(earliestArrival - myLastEntryTime);
     170              : }
     171              : 
     172              : 
     173              : bool
     174      3127284 : MEVehicle::moveRoutePointer() {
     175              :     // vehicle has just entered a new edge. Position is 0
     176      3127284 :     if (myCurrEdge == myRoute->end() - 1 || (myParameter->arrivalEdge >= 0 && getRoutePosition() >= myParameter->arrivalEdge)) { // may happen during teleport
     177          119 :         return true;
     178              :     }
     179              :     ++myCurrEdge;
     180      3127165 :     if ((*myCurrEdge)->isVaporizing()) {
     181              :         return true;
     182              :     }
     183              :     // update via
     184      3127061 :     if (myParameter->via.size() > 0 && (*myCurrEdge)->getID() == myParameter->via.front()) {
     185         2918 :         myParameter->via.erase(myParameter->via.begin());
     186              :     }
     187      3127061 :     return hasArrived();
     188              : }
     189              : 
     190              : 
     191              : bool
     192     29166245 : MEVehicle::hasArrived() const {
     193              :     // mySegment may be 0 due to teleporting or arrival
     194     29166245 :     return (myCurrEdge == myRoute->end() - 1 || (myParameter->arrivalEdge >= 0 && getRoutePosition() >= myParameter->arrivalEdge)) && (
     195      5217446 :                (mySegment == nullptr)
     196      5213318 :                || myEventTime == SUMOTime_MIN
     197      5213318 :                || getPositionOnLane() > myArrivalPos - POSITION_EPS);
     198              : }
     199              : 
     200              : 
     201              : bool
     202    505774720 : MEVehicle::isOnRoad() const {
     203    505774720 :     return getSegment() != nullptr;
     204              : }
     205              : 
     206              : 
     207              : bool
     208        22360 : MEVehicle::isIdling() const {
     209        22360 :     return false;
     210              : }
     211              : 
     212              : 
     213              : void
     214    540421059 : MEVehicle::setApproaching(MSLink* link) {
     215    540421059 :     if (link != nullptr) {
     216    508373917 :         const double speed = getSpeed();
     217    508432428 :         link->setApproaching(this, getEventTime() + (link->getState() == LINKSTATE_ALLWAY_STOP ?
     218              :                              (SUMOTime)RandHelper::rand((int)2) : 0), // tie braker
     219              :                              speed, link->getViaLaneOrLane()->getVehicleMaxSpeed(this), true,
     220    508373917 :                              speed, getWaitingTime(),
     221              :                              // @note: dist is not used by meso (getZipperSpeed is never called)
     222              :                              getSegment()->getLength(), 0);
     223              :     }
     224    540421059 : }
     225              : 
     226              : 
     227              : bool
     228       337858 : MEVehicle::replaceRoute(ConstMSRoutePtr newRoute, const std::string& info,  bool onInit, int offset, bool addRouteStops, bool removeStops, std::string* msgReturn) {
     229       337858 :     MSLink* const oldLink = mySegment != nullptr ? mySegment->getLink(this) : nullptr;
     230       675716 :     if (MSBaseVehicle::replaceRoute(newRoute, info, onInit, offset, addRouteStops, removeStops, msgReturn)) {
     231       337826 :         if (mySegment != nullptr) {
     232       142937 :             MSLink* const newLink = mySegment->getLink(this);
     233              :             // update approaching vehicle information
     234       142937 :             if (oldLink != newLink) {
     235         1172 :                 if (oldLink != nullptr) {
     236         1122 :                     oldLink->removeApproaching(this);
     237              :                 }
     238         1172 :                 setApproaching(newLink);
     239              :             }
     240              :         }
     241       337826 :         return true;
     242              :     }
     243              :     return false;
     244              : }
     245              : 
     246              : 
     247              : SUMOTime
     248     26802963 : MEVehicle::checkStop(SUMOTime time) {
     249              :     const SUMOTime initialTime = time;
     250              :     bool hadStop = false;
     251              :     bool reachedStop = false;
     252     26819181 :     for (MSStop& stop : myStops) {
     253       152697 :         if (stop.joinTriggered) {
     254         1494 :             WRITE_WARNINGF(TL("Join stops are not available in meso yet (vehicle '%', segment '%')."),
     255              :                            getID(), mySegment->getID());
     256          498 :             continue;
     257              :         }
     258       152199 :         if (stop.edge != myCurrEdge || stop.segment != mySegment) {
     259              :             break;
     260              :         }
     261              :         const SUMOTime cur = time;
     262        15720 :         if (stop.duration > 0) { // it might be a triggered stop with duration -1
     263         7716 :             time += stop.duration;
     264              :         }
     265        15720 :         if (stop.pars.until > time) {
     266              :             // @note: this assumes the stop is reached at time. With the way this is called in MESegment (time == entryTime),
     267              :             // travel time is overestimated of the stop is not at the start of the segment
     268              :             time = stop.pars.until;
     269              :         }
     270        15720 :         if (MSGlobals::gUseStopEnded && stop.pars.ended >= 0) {
     271              :             time = MAX2(cur, stop.pars.ended);
     272              :         }
     273        15720 :         if (!stop.reached) {
     274              :             reachedStop = true;
     275        15720 :             stop.reached = true;
     276        15720 :             stop.pars.started = myLastEntryTime;
     277        15720 :             stop.endBoarding = stop.pars.extension >= 0 ? time + stop.pars.extension : SUMOTime_MAX;
     278        15720 :             if (MSStopOut::active()) {
     279         1319 :                 if (!hadStop) {
     280         1279 :                     MSStopOut::getInstance()->stopStarted(this, getPersonNumber(), getContainerNumber(), myLastEntryTime);
     281              :                 } else {
     282          120 :                     WRITE_WARNINGF(TL("Vehicle '%' has multiple stops on segment '%', time=% (stop-output will be merged)."),
     283              :                                    getID(), mySegment->getID(), time2string(time));
     284              :                 }
     285              :             }
     286              :         }
     287        15720 :         if (stop.triggered || stop.containerTriggered || stop.joinTriggered) {
     288         1000 :             time = MAX2(time, cur + DELTA_T);
     289              :         }
     290              :         hadStop = true;
     291              :     }
     292     26802963 :     if (reachedStop) {
     293        14882 :         MSDevice_Taxi* taxi = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
     294              :         if (taxi != nullptr) {
     295         1543 :             taxi->notifyMove(*this, 0, 0, 0);
     296              :         }
     297              :     }
     298     26802963 :     MSDevice_Tripinfo* tripinfo = static_cast<MSDevice_Tripinfo*>(getDevice(typeid(MSDevice_Tripinfo)));
     299              :     if (tripinfo != nullptr) {
     300     14974584 :         tripinfo->updateStopTime(time - initialTime);
     301              :     }
     302     26802963 :     return time;
     303              : }
     304              : 
     305              : 
     306              : bool
     307        14878 : MEVehicle::resumeFromStopping() {
     308        14878 :     if (isStopped()) {
     309        14869 :         const SUMOTime now = SIMSTEP;
     310              :         MSStop& stop = myStops.front();
     311        14869 :         stop.pars.ended = now;
     312        31988 :         for (const auto& rem : myMoveReminders) {
     313        17119 :             rem.first->notifyStopEnded();
     314              :         }
     315        14869 :         if (MSStopOut::active()) {
     316         1266 :             MSStopOut::getInstance()->stopEnded(this, stop);
     317              :         }
     318        14869 :         myPastStops.push_back(stop.pars);
     319        14869 :         myPastStops.back().routeIndex = (int)(stop.edge - myRoute->begin());
     320        14869 :         if (myAmRegisteredAsWaiting && (stop.triggered || stop.containerTriggered || stop.joinTriggered)) {
     321           31 :             MSNet::getInstance()->getVehicleControl().unregisterOneWaiting();
     322           31 :             myAmRegisteredAsWaiting = false;
     323              :         }
     324        14869 :         myStops.pop_front();
     325        14869 :         if (myEventTime > now) {
     326              :             // if this is an aborted stop we need to change the event time of the vehicle
     327           14 :             const bool isLeader = mySegment->getQueue(myQueIndex).back() == this;
     328           14 :             if (isLeader) {
     329            6 :                 MSGlobals::gMesoNet->removeLeaderCar(this);
     330            6 :                 myEventTime = now + 1;
     331            6 :                 MSGlobals::gMesoNet->addLeaderCar(this, nullptr);
     332              :             }
     333              :         }
     334        14869 :         return true;
     335              :     }
     336              :     return false;
     337              : }
     338              : 
     339              : 
     340              : double
     341            0 : MEVehicle::getCurrentStoppingTimeSeconds() const {
     342            0 :     SUMOTime time = myLastEntryTime;
     343            0 :     for (const MSStop& stop : myStops) {
     344            0 :         if (stop.reached) {
     345            0 :             time += stop.duration;
     346            0 :             if (stop.pars.until > time) {
     347              :                 // @note: this assumes the stop is reached at time. With the way this is called in MESegment (time == entryTime),
     348              :                 // travel time is overestimated of the stop is not at the start of the segment
     349              :                 time = stop.pars.until;
     350              :             }
     351              :         } else {
     352              :             break;
     353              :         }
     354              :     }
     355            0 :     return STEPS2TIME(time - myLastEntryTime);
     356              : }
     357              : 
     358              : 
     359              : void
     360        14185 : MEVehicle::processStop() {
     361              :     assert(isStopped());
     362              :     double lastPos = -1;
     363              :     bool hadStop = false;
     364        29046 :     while (!myStops.empty()) {
     365              :         MSStop& stop = myStops.front();
     366        23229 :         if (stop.edge != myCurrEdge || stop.segment != mySegment || stop.pars.endPos <= lastPos) {
     367              :             break;
     368              :         }
     369              :         lastPos = stop.pars.endPos;
     370        14861 :         MSNet* const net = MSNet::getInstance();
     371        14861 :         SUMOTime dummy = -1; // boarding- and loading-time are not considered
     372        14861 :         if (hadStop && MSStopOut::active()) {
     373           40 :             stop.reached = true;
     374           40 :             MSStopOut::getInstance()->stopStarted(this, getPersonNumber(), getContainerNumber(), myLastEntryTime);
     375              :         }
     376        14861 :         if (net->hasPersons()) {
     377         5819 :             net->getPersonControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy);
     378              :         }
     379        14861 :         if (net->hasContainers()) {
     380          242 :             net->getContainerControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy);
     381              :         }
     382        14861 :         resumeFromStopping();
     383              :         hadStop = true;
     384              :     }
     385        14185 :     if (getWaitingTime() > 0) {
     386              :         // entry back onto the road was blocked for some time
     387          155 :         MSDevice_Tripinfo* tripinfoDevice = static_cast<MSDevice_Tripinfo*>(getDevice(typeid(MSDevice_Tripinfo)));
     388              :         if (tripinfoDevice != nullptr) {
     389            5 :             tripinfoDevice->recordMesoParkingTimeLoss(getWaitingTime());
     390              :         }
     391              :     }
     392        14185 :     mySegment->getEdge().removeWaiting(this);
     393        14185 : }
     394              : 
     395              : 
     396              : bool
     397     27244161 : MEVehicle::endTriggeredStop() {
     398     27244161 :     MSNet* const net = MSNet::getInstance();
     399     27244161 :     SUMOTime dummy = -1; // boarding- and loading-time are not considered
     400     27257356 :     for (MSStop& stop : myStops) {
     401       405660 :         if (!stop.reached) {
     402              :             break;
     403              :         }
     404       259356 :         if (net->getCurrentTimeStep() > stop.endBoarding) {
     405           63 :             if (stop.triggered || stop.containerTriggered) {
     406           27 :                 MSDevice_Taxi* taxiDevice = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
     407              :                 if (taxiDevice != nullptr) {
     408           24 :                     taxiDevice->cancelCurrentCustomers();
     409              :                 }
     410           27 :                 stop.triggered = false;
     411           27 :                 stop.containerTriggered = false;
     412              :             }
     413           63 :             if (myAmRegisteredAsWaiting) {
     414              :                 net->getVehicleControl().unregisterOneWaiting();
     415           27 :                 myAmRegisteredAsWaiting = false;
     416              :             }
     417              :         }
     418       259356 :         if (stop.triggered) {
     419       230845 :             if (getVehicleType().getPersonCapacity() == getPersonNumber()) {
     420              :                 // we could not check this on entering the segment because there may be persons who still want to leave
     421            0 :                 WRITE_WARNINGF(TL("Vehicle '%' ignores triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
     422            0 :                 stop.triggered = false;
     423            0 :                 if (myAmRegisteredAsWaiting) {
     424              :                     net->getVehicleControl().unregisterOneWaiting();
     425            0 :                     myAmRegisteredAsWaiting = false;
     426              :                 }
     427       230845 :             } else if (!net->hasPersons() || !net->getPersonControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy)) {
     428       230221 :                 if (!myAmRegisteredAsWaiting) {
     429          746 :                     MSNet::getInstance()->getVehicleControl().registerOneWaiting();
     430          746 :                     myAmRegisteredAsWaiting = true;
     431              :                 }
     432       230221 :                 return false;
     433              :             }
     434              :         }
     435        29135 :         if (stop.containerTriggered) {
     436        16014 :             if (getVehicleType().getContainerCapacity() == getContainerNumber()) {
     437              :                 // we could not check this on entering the segment because there may be containers who still want to leave
     438            6 :                 WRITE_WARNINGF(TL("Vehicle '%' ignores container triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
     439            2 :                 stop.containerTriggered = false;
     440            2 :                 if (myAmRegisteredAsWaiting) {
     441              :                     net->getVehicleControl().unregisterOneWaiting();
     442            0 :                     myAmRegisteredAsWaiting = false;
     443              :                 }
     444        16012 :             } else if (!net->hasContainers() || !net->getContainerControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy)) {
     445        15940 :                 if (!myAmRegisteredAsWaiting) {
     446           80 :                     MSNet::getInstance()->getVehicleControl().registerOneWaiting();
     447           80 :                     myAmRegisteredAsWaiting = true;
     448              :                 }
     449        15940 :                 return false;
     450              :             }
     451              :         }
     452        13195 :         if (stop.joinTriggered) {
     453              :             // TODO do something useful here
     454              :             return false;
     455              :         }
     456              :     }
     457              :     return true;
     458              : }
     459              : 
     460              : 
     461              : bool
     462     27215681 : MEVehicle::mayProceed() {
     463     27215681 :     if (mySegment == nullptr) {
     464              :         return true;
     465              :     }
     466     27215681 :     if (!endTriggeredStop()) {
     467              :         return false;
     468              :     }
     469     26997904 :     return mySegment->isOpen(this);
     470              : }
     471              : 
     472              : 
     473              : double
     474            0 : MEVehicle::getCurrentLinkPenaltySeconds() const {
     475            0 :     if (mySegment == nullptr) {
     476              :         return 0;
     477              :     } else {
     478            0 :         return STEPS2TIME(mySegment->getLinkPenalty(this));
     479              :     }
     480              : }
     481              : 
     482              : 
     483              : void
     484      1307909 : MEVehicle::updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime) {
     485      2195916 :     for (MoveReminderCont::iterator i = myMoveReminders.begin(); i != myMoveReminders.end(); ++i) {
     486      2184602 :         if (i->first == rem) {
     487      1296595 :             rem->updateDetector(*this, mySegment->getIndex() * mySegment->getLength(),
     488      1296595 :                                 (mySegment->getIndex() + 1) * mySegment->getLength(),
     489              :                                 getLastEntryTime(), currentTime, exitTime, false);
     490              : #ifdef _DEBUG
     491              :             if (myTraceMoveReminders) {
     492              :                 traceMoveReminder("notifyMove", i->first, i->second, true);
     493              :             }
     494              : #endif
     495              :             return;
     496              :         }
     497              :     }
     498              : }
     499              : 
     500              : 
     501              : void
     502     26793039 : MEVehicle::updateDetectors(const SUMOTime currentTime, const SUMOTime exitTime, const bool isLeave, const MSMoveReminder::Notification reason) {
     503              :     // segments of the same edge have the same reminder so no cleaning up must take place
     504     26793039 :     const bool cleanUp = isLeave && (reason != MSMoveReminder::NOTIFICATION_SEGMENT);
     505     60674411 :     for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
     506     33881372 :         if (currentTime != getLastEntryTime() && reason < MSMoveReminder::NOTIFICATION_VAPORIZED_CALIBRATOR) {
     507     33823752 :             rem->first->updateDetector(*this, mySegment->getIndex() * mySegment->getLength(),
     508     33823752 :                                        (mySegment->getIndex() + 1) * mySegment->getLength(),
     509              :                                        getLastEntryTime(), currentTime, exitTime, cleanUp);
     510              : #ifdef _DEBUG
     511              :             if (myTraceMoveReminders) {
     512              :                 traceMoveReminder("notifyMove", rem->first, rem->second, true);
     513              :             }
     514              : #endif
     515              :         }
     516     67759112 :         if (!isLeave || rem->first->notifyLeave(*this, mySegment == nullptr ? 0 : mySegment->getLength(), reason)) {
     517              : #ifdef _DEBUG
     518              :             if (isLeave && myTraceMoveReminders) {
     519              :                 traceMoveReminder("notifyLeave", rem->first, rem->second, true);
     520              :             }
     521              : #endif
     522              : 
     523     24371590 :             if (isLeave) {
     524     24369283 :                 rem->second += getEdge()->getLength();
     525              : #ifdef _DEBUG
     526              :                 if (myTraceMoveReminders) {
     527              :                     traceMoveReminder("adaptedPos", rem->first, rem->second, true);
     528              :                 }
     529              : #endif
     530              :             }
     531              :             ++rem;
     532              :         } else {
     533              : #ifdef _DEBUG
     534              :             if (myTraceMoveReminders) {
     535              :                 traceMoveReminder("remove", rem->first, rem->second, false);
     536              :             }
     537              : #endif
     538              :             rem = myMoveReminders.erase(rem);
     539              :         }
     540              :     }
     541     26793039 :     if (reason == MSMoveReminder::NOTIFICATION_JUNCTION || reason == MSMoveReminder::NOTIFICATION_TELEPORT) {
     542      5080671 :         myOdometer += getEdge()->getLength();
     543              :     }
     544     26793039 : }
     545              : 
     546              : 
     547              : MEVehicle::BaseInfluencer&
     548            3 : MEVehicle::getBaseInfluencer() {
     549            3 :     if (myInfluencer == nullptr) {
     550            2 :         myInfluencer = new BaseInfluencer();
     551              :     }
     552            3 :     return *myInfluencer;
     553              : }
     554              : 
     555              : 
     556              : const MEVehicle::BaseInfluencer*
     557           46 : MEVehicle::getBaseInfluencer() const {
     558           46 :     return myInfluencer;
     559              : }
     560              : 
     561              : 
     562              : void
     563            2 : MEVehicle::onRemovalFromNet(const MSMoveReminder::Notification reason) {
     564            2 :     MSGlobals::gMesoNet->removeLeaderCar(this);
     565            2 :     MSGlobals::gMesoNet->changeSegment(this, MSNet::getInstance()->getCurrentTimeStep(), nullptr, reason);
     566            2 : }
     567              : 
     568              : 
     569              : int
     570         5732 : MEVehicle::getSegmentIndex() const {
     571         5732 :     return getSegment() != nullptr ? getSegment()->getIndex() : -1;
     572              : }
     573              : 
     574              : 
     575              : double
     576            0 : MEVehicle::getRightSideOnEdge(const MSLane* /*lane*/) const {
     577            0 :     if (mySegment == nullptr || mySegment->getIndex() >= getEdge()->getNumLanes()) {
     578            0 :         return 0;
     579              :     }
     580            0 :     const MSLane* lane = getEdge()->getLanes()[mySegment->getIndex()];
     581            0 :     return lane->getRightSideOnEdge() + lane->getWidth() * 0.5 - 0.5 * getVehicleType().getWidth();
     582              : 
     583              : }
     584              : 
     585              : 
     586              : void
     587         1850 : MEVehicle::saveState(OutputDevice& out) {
     588         1850 :     if (mySegment != nullptr && MESegment::isInvalid(mySegment)) {
     589              :         // segment is vaporization target, do not write this vehicle
     590            0 :         return;
     591              :     }
     592         1850 :     MSBaseVehicle::saveState(out);
     593              :     assert(mySegment == nullptr || *myCurrEdge == &mySegment->getEdge() || mySegment->getEdge().isInternal());
     594              :     std::vector<SUMOTime> internals;
     595         1850 :     internals.push_back(myParameter->parametersSet);
     596         1850 :     internals.push_back(myDeparture);
     597         1850 :     internals.push_back((SUMOTime)distance(myRoute->begin(), myCurrEdge));
     598         1850 :     internals.push_back((SUMOTime)myDepartPos * 1000); // store as mm
     599         1850 :     internals.push_back(mySegment == nullptr ? (SUMOTime) - 1 : (SUMOTime)mySegment->getIndex());
     600         1850 :     internals.push_back((SUMOTime)getQueIndex());
     601         1850 :     internals.push_back(myEventTime);
     602         1850 :     internals.push_back(myLastEntryTime);
     603         1850 :     internals.push_back(myBlockTime);
     604         1850 :     internals.push_back(isStopped());
     605         1850 :     internals.push_back(myPastStops.size());
     606         1850 :     out.writeAttr(SUMO_ATTR_STATE, toString(internals));
     607              :     // save past stops
     608         4910 :     for (SUMOVehicleParameter::Stop stop : myPastStops) {
     609         3060 :         stop.write(out, false);
     610              :         // do not write started and ended twice
     611         3060 :         if ((stop.parametersSet & STOP_STARTED_SET) == 0) {
     612         3060 :             out.writeAttr(SUMO_ATTR_STARTED, time2string(stop.started));
     613              :         }
     614         3060 :         if ((stop.parametersSet & STOP_ENDED_SET) == 0) {
     615         3060 :             out.writeAttr(SUMO_ATTR_ENDED, time2string(stop.ended));
     616              :         }
     617         3060 :         out.closeTag();
     618         3060 :     }
     619              :     // save upcoming stops
     620         2237 :     for (const MSStop& stop : myStops) {
     621          387 :         stop.write(out);
     622              :     }
     623              :     // save parameters
     624         1850 :     myParameter->writeParams(out);
     625         4761 :     for (MSDevice* dev : myDevices) {
     626         2911 :         dev->saveState(out);
     627              :     }
     628         4347 :     for (const auto& item : myMoveReminders) {
     629         2497 :         item.first->saveReminderState(out, *this);
     630              :     }
     631         1850 :     out.closeTag();
     632         1850 : }
     633              : 
     634              : 
     635              : void
     636         1444 : MEVehicle::loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) {
     637         1444 :     if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
     638           10 :         throw ProcessError(TL("Error: Invalid vehicles in state (may be a micro state)!"));
     639              :     }
     640              :     int routeOffset;
     641              :     bool stopped;
     642              :     int pastStops;
     643              :     int segIndex;
     644              :     int queIndex;
     645         1439 :     std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
     646         1439 :     bis >> myParameter->parametersSet;
     647         1439 :     bis >> myDeparture;
     648         1439 :     bis >> routeOffset;
     649         1439 :     bis >> myDepartPos;
     650         1439 :     bis >> segIndex;
     651         1439 :     bis >> queIndex;
     652         1439 :     bis >> myEventTime;
     653         1439 :     bis >> myLastEntryTime;
     654         1439 :     bis >> myBlockTime;
     655              :     bis >> stopped;
     656         1439 :     bis >> pastStops;
     657         1439 :     myDepartPos /= 1000.; // was stored as mm
     658              : 
     659         1439 :     if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS_RANDOMIZED)) {
     660              :         bool ok;
     661            9 :         myArrivalPos = attrs.get<double>(SUMO_ATTR_ARRIVALPOS_RANDOMIZED, getID().c_str(), ok);
     662              :     }
     663              : 
     664              :     // load stops
     665              :     myStops.clear();
     666         1439 :     addStops(!MSGlobals::gCheckRoutes, &myCurrEdge, false);
     667              : 
     668         1439 :     if (hasDeparted()) {
     669          763 :         myDeparture -= offset;
     670          763 :         myEventTime -= offset;
     671          763 :         myLastEntryTime -= offset;
     672          763 :         myCurrEdge = myRoute->begin() + routeOffset;
     673              :         // fix stops
     674         3819 :         while (pastStops > 0) {
     675         6161 :             for (const auto& rem : myMoveReminders) {
     676         3105 :                 rem.first->notifyStopEnded();
     677              :             }
     678         3056 :             myPastStops.push_back(myStops.front().pars);
     679         3056 :             myPastStops.back().routeIndex = (int)(myStops.front().edge - myRoute->begin());
     680         3056 :             myStops.pop_front();
     681         3056 :             pastStops--;
     682              :         }
     683          763 :         if (segIndex >= 0) {
     684          763 :             MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(**myCurrEdge);
     685         1071 :             while (seg->getIndex() != (int)segIndex) {
     686              :                 seg = seg->getNextSegment();
     687          309 :                 if (seg == nullptr) {
     688            4 :                     throw ProcessError(TLF("Unknown segment '%:%' for vehicle '%' in loaded state.", (*myCurrEdge)->getID(), segIndex, getID()));
     689              :                 }
     690              :             }
     691          762 :             setSegment(seg, queIndex);
     692          762 :             if (queIndex == MESegment::PARKING_QUEUE) {
     693          265 :                 MSGlobals::gMesoNet->addLeaderCar(this, nullptr);
     694          265 :                 getCurrentEdge()->getLanes()[0]->addParking(this);
     695              :             }
     696              :         } else {
     697              :             // on teleport
     698            0 :             setSegment(nullptr, 0);
     699              :             assert(myEventTime != SUMOTime_MIN);
     700            0 :             MSGlobals::gMesoNet->addLeaderCar(this, nullptr);
     701              :         }
     702              :         // see MSBaseVehicle constructor
     703          762 :         if (myParameter->wasSet(VEHPARS_FORCE_REROUTE)) {
     704          415 :             calculateArrivalParams(true);
     705              :         }
     706              :     }
     707         1438 :     if (myBlockTime != SUMOTime_MAX) {
     708           30 :         myBlockTime -= offset;
     709              :     }
     710         1438 :     std::istringstream dis(attrs.getString(SUMO_ATTR_DISTANCE));
     711         1438 :     dis >> myOdometer >> myNumberReroutes;
     712         1438 :     if (stopped) {
     713          279 :         myStops.front().startedFromState = true;
     714          279 :         myStops.front().reached = true;
     715              :     }
     716         1439 : }
     717              : 
     718              : 
     719              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1