LCOV - code coverage report
Current view: top level - src/microsim - MSStop.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 76.9 % 143 110
Test Date: 2026-10-12 15:53:19 Functions: 100.0 % 16 16

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2005-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    MSStop.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 13.12.2005
      18              : ///
      19              : // A lane area vehicles can halt at
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <mesosim/MESegment.h>
      24              : #include <mesosim/MELoop.h>
      25              : #include "MSLane.h"
      26              : #include "MSEdge.h"
      27              : #include "MSNet.h"
      28              : #include "MSParkingArea.h"
      29              : #include "MSStoppingPlace.h"
      30              : #include "MSRouteHandler.h"
      31              : #include "MSStop.h"
      32              : 
      33              : // ===========================================================================
      34              : // method definitions
      35              : // ===========================================================================
      36              : 
      37              : double
      38     15981303 : MSStop::getEndPos(const SUMOVehicle& veh) const {
      39     15981303 :     const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
      40     15981303 :     if ((pars.parametersSet & STOP_END_SET) != 0) {
      41      4260927 :         return pars.endPos;
      42     11720376 :     } else if (busstop != nullptr) {
      43      3572683 :         return busstop->getLastFreePos(veh, brakePos);
      44      8147693 :     } else if (containerstop != nullptr) {
      45      3986631 :         return containerstop->getLastFreePos(veh, brakePos);
      46      4161062 :     } else if (parkingarea != nullptr) {
      47      1826158 :         return parkingarea->getLastFreePos(veh, brakePos);
      48      2334904 :     } else if (chargingStation != nullptr) {
      49      1042077 :         return chargingStation->getLastFreePos(veh);
      50      1292827 :     } else if (overheadWireSegment != nullptr) {
      51            0 :         return overheadWireSegment->getLastFreePos(veh);
      52              :     }
      53      1292827 :     return pars.endPos;
      54              : }
      55              : 
      56              : const MSEdge*
      57     16234584 : MSStop::getEdge() const {
      58     16234584 :     if (lane != nullptr) {
      59     16234584 :         return &lane->getEdge();
      60            0 :     } else if (segment != nullptr) {
      61            0 :         return &segment->getEdge();
      62              :     }
      63              :     return nullptr;
      64              : }
      65              : 
      66              : double
      67      3224229 : MSStop::getReachedThreshold() const {
      68      3224229 :     return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
      69              : }
      70              : 
      71              : std::string
      72           37 : MSStop::getDescription(bool nameOnly) const {
      73              :     std::string result;
      74           37 :     if (parkingarea != nullptr) {
      75            0 :         if (nameOnly) {
      76              :             return parkingarea->getID();
      77              :         }
      78            0 :         result = "parkingArea:" + parkingarea->getID();
      79           37 :     } else if (containerstop != nullptr) {
      80            0 :         if (nameOnly) {
      81              :             return containerstop->getID();
      82              :         }
      83            0 :         result = "containerStop:" + containerstop->getID();
      84           37 :     } else if (busstop != nullptr) {
      85           36 :         if (nameOnly) {
      86              :             return busstop->getID();
      87              :         }
      88            0 :         result = "busStop:" + busstop->getID();
      89            1 :     } else if (chargingStation != nullptr) {
      90            0 :         if (nameOnly) {
      91              :             return chargingStation->getID();
      92              :         }
      93            0 :         result = "chargingStation:" + chargingStation->getID();
      94            1 :     } else if (overheadWireSegment != nullptr) {
      95            0 :         if (nameOnly) {
      96              :             return overheadWireSegment->getID();
      97              :         }
      98            0 :         result = "overheadWireSegment:" + overheadWireSegment->getID();
      99              :     } else {
     100            1 :         if (nameOnly) {
     101            0 :             return "";
     102              :         }
     103            3 :         result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
     104              :     }
     105            1 :     if (pars.actType != "") {
     106            0 :         result += " actType:" + pars.actType;
     107              :     }
     108            1 :     return result;
     109              : }
     110              : 
     111              : 
     112              : std::pair<std::string, SumoXMLTag>
     113        71520 : MSStop::getStoppingPlaceName() const {
     114        71520 :     if (busstop != nullptr && !busstop->getMyName().empty()) {
     115         1393 :         return std::make_pair(busstop->getMyName(), SUMO_TAG_BUS_STOP);
     116        70127 :     } else if (containerstop != nullptr && !containerstop->getMyName().empty()) {
     117           48 :         return std::make_pair(containerstop->getMyName(), SUMO_TAG_CONTAINER_STOP);
     118        70079 :     } else if (parkingarea != nullptr && !parkingarea->getMyName().empty()) {
     119            0 :         return std::make_pair(parkingarea->getMyName(), SUMO_TAG_PARKING_AREA);
     120        70079 :     } else if (chargingStation != nullptr && !chargingStation->getMyName().empty()) {
     121            0 :         return std::make_pair(chargingStation->getMyName(), SUMO_TAG_CHARGING_STATION);
     122        70079 :     } else if (overheadWireSegment != nullptr && !overheadWireSegment->getMyName().empty()) {
     123            0 :         return std::make_pair(overheadWireSegment->getMyName(), SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
     124              :     }
     125              :     return std::make_pair("", SUMO_TAG_NOTHING);
     126              : }
     127              : 
     128              : 
     129              : void
     130          876 : MSStop::write(OutputDevice& dev) const {
     131          876 :     SUMOVehicleParameter::Stop tmp = pars;
     132          876 :     tmp.duration = duration;
     133          876 :     if (!triggered && !containerTriggered) {
     134              :         // we are writing in the context of saveState. All required
     135              :         // transportables have entered and we must prevent the trigger condition
     136              :         // to be renewed on loading
     137          859 :         tmp.triggered = false;
     138          859 :         tmp.containerTriggered = false;
     139              :     }
     140          876 :     tmp.write(dev, false);
     141              :     // if the stop has already started but hasn't ended yet we are writing it in
     142              :     // the context of saveState (but we do not want to write the attribute twice
     143          876 :     if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
     144          519 :         dev.writeAttr(SUMO_ATTR_STARTED, time2string(pars.started));
     145              :     }
     146          876 :     pars.writeParams(dev);
     147          876 :     dev.closeTag();
     148          876 : }
     149              : 
     150              : void
     151       149969 : MSStop::initPars(const SUMOVehicleParameter::Stop& stopPar) {
     152       149969 :     busstop = MSNet::getInstance()->getStoppingPlace(stopPar.busstop, SUMO_TAG_BUS_STOP);
     153       149969 :     containerstop = MSNet::getInstance()->getStoppingPlace(stopPar.containerstop, SUMO_TAG_CONTAINER_STOP);
     154       149969 :     parkingarea = static_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stopPar.parkingarea, SUMO_TAG_PARKING_AREA));
     155       149969 :     chargingStation = MSNet::getInstance()->getStoppingPlace(stopPar.chargingStation, SUMO_TAG_CHARGING_STATION);
     156       149969 :     overheadWireSegment = MSNet::getInstance()->getStoppingPlace(stopPar.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
     157       149969 :     duration = stopPar.durationDist.isVariable() ? TIME2STEPS(stopPar.durationDist.sample(MSRouteHandler::getParsingRNG())) : stopPar.duration;
     158       149969 :     triggered = stopPar.triggered;
     159       149969 :     containerTriggered = stopPar.containerTriggered;
     160       149969 :     joinTriggered = stopPar.joinTriggered || stopPar.join != "";
     161       149969 :     numExpectedPerson = (int)stopPar.awaitedPersons.size();
     162       149969 :     numExpectedContainer = (int)stopPar.awaitedContainers.size();
     163       149969 : }
     164              : 
     165              : 
     166              : int
     167          237 : MSStop::getStateFlagsOld() const {
     168          237 :     return ((reached ? 1 : 0) + 2 * pars.getFlags());
     169              : }
     170              : 
     171              : 
     172              : SUMOTime
     173       127340 : MSStop::getMinDuration(SUMOTime time) const {
     174       127340 :     if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
     175           53 :         return pars.ended - time;
     176              :     }
     177       127287 :     if (pars.until >= 0) {
     178        55509 :         if (duration == -1) {
     179        38432 :             return pars.until - time;
     180              :         } else {
     181        17077 :             return MAX2(duration, pars.until - time);
     182              :         }
     183              :     } else {
     184        71778 :         return duration;
     185              :     }
     186              : }
     187              : 
     188              : 
     189              : SUMOTime
     190       668371 : MSStop::getUntil() const {
     191       668371 :     return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
     192              : }
     193              : 
     194              : 
     195              : SUMOTime
     196       143677 : MSStop::getArrival() const {
     197       143677 :     return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
     198              : }
     199              : 
     200              : 
     201              : SUMOTime
     202        85924 : MSStop::getArrivalFallback() const {
     203        85924 :     SUMOTime result = getArrival();
     204        85924 :     if (result < 0) {
     205        85843 :         result = getUntil();
     206        85843 :         if (result >= 0 && pars.duration >= 0) {
     207        17211 :             result -= pars.duration;
     208              :         }
     209              :     }
     210        85924 :     return result;
     211              : }
     212              : 
     213              : 
     214              : double
     215    141394784 : MSStop::getSpeed() const {
     216    141394784 :     return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
     217              : }
     218              : 
     219              : 
     220              : bool
     221        90539 : MSStop::isInRange(const double pos, const double tolerance) const {
     222        90539 :     return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
     223              : }
     224              : 
     225              : 
     226              : std::vector<MSStoppingPlace*>
     227           15 : MSStop::getPlaces() const {
     228              :     std::vector<MSStoppingPlace*> result;
     229           15 :     if (busstop != nullptr) {
     230           15 :         result.push_back(busstop);
     231              :     }
     232           15 :     if (containerstop != nullptr) {
     233            0 :         result.push_back(containerstop);
     234              :     }
     235           15 :     if (parkingarea != nullptr) {
     236            0 :         result.push_back(parkingarea);
     237              :     }
     238           15 :     if (chargingStation != nullptr) {
     239            0 :         result.push_back(chargingStation);
     240              :     }
     241           15 :     if (overheadWireSegment != nullptr) {
     242            0 :         result.push_back(overheadWireSegment);
     243              :     }
     244           15 :     return result;
     245            0 : }
     246              : 
     247              : 
     248              : void
     249           36 : MSStop::replaceStoppingPlace(MSStoppingPlace* sp) {
     250              :     // @note: assume iterator edge is handled elsewhere
     251              :     assert(*edge == &sp->getLane().getEdge());
     252           36 :     lane = &sp->getLane();
     253              :     SUMOVehicleParameter::Stop& ncPars = const_cast<SUMOVehicleParameter::Stop&>(pars);
     254           36 :     ncPars.edge = lane->getEdge().getID();
     255           36 :     ncPars.lane = lane->getID();
     256           36 :     ncPars.startPos = sp->getBeginLanePosition();
     257           36 :     ncPars.endPos = sp->getEndLanePosition();
     258           36 :     if (MSGlobals::gUseMesoSim) {
     259           12 :         segment = MSGlobals::gMesoNet->getSegmentForEdge(lane->getEdge(), sp->getEndLanePosition());
     260              :     }
     261           36 :     switch (sp->getElement()) {
     262           36 :         case SUMO_TAG_BUS_STOP:
     263              :         case SUMO_TAG_TRAIN_STOP:
     264           36 :             busstop = sp;
     265           36 :             ncPars.busstop = sp->getID();
     266              :             break;
     267            0 :         case SUMO_TAG_CONTAINER_STOP:
     268            0 :             containerstop = sp;
     269            0 :             ncPars.containerstop = sp->getID();
     270              :             break;
     271              :         case SUMO_TAG_PARKING_AREA:
     272            0 :             parkingarea = dynamic_cast<MSParkingArea*>(sp);
     273            0 :             ncPars.parkingarea = sp->getID();
     274              :             break;
     275            0 :         case SUMO_TAG_CHARGING_STATION:
     276            0 :             chargingStation = sp;
     277            0 :             ncPars.chargingStation = sp->getID();
     278              :             break;
     279            0 :         case SUMO_TAG_OVERHEAD_WIRE_SEGMENT:
     280            0 :             overheadWireSegment = sp;
     281            0 :             ncPars.overheadWireSegment = sp->getID();
     282              :             break;
     283           36 :         default:
     284              :             // should not happen
     285              :             assert(false);
     286              :     }
     287           36 : }
     288              : 
     289              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1