LCOV - code coverage report
Current view: top level - src/microsim - MSStop.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 73.1 % 145 106
Test Date: 2026-03-27 16:39:44 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 "MSStop.h"
      31              : 
      32              : // ===========================================================================
      33              : // method definitions
      34              : // ===========================================================================
      35              : double
      36     11541194 : MSStop::getEndPos(const SUMOVehicle& veh) const {
      37     11541194 :     const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
      38     11541194 :     if ((pars.parametersSet & STOP_END_SET) != 0) {
      39      4097940 :         return pars.endPos;
      40      7443254 :     } else if (busstop != nullptr) {
      41      3218848 :         return busstop->getLastFreePos(veh, brakePos);
      42      4224406 :     } else if (containerstop != nullptr) {
      43        33746 :         return containerstop->getLastFreePos(veh, brakePos);
      44      4190660 :     } else if (parkingarea != nullptr) {
      45      1801089 :         return parkingarea->getLastFreePos(veh, brakePos);
      46      2389571 :     } else if (chargingStation != nullptr) {
      47      1037418 :         return chargingStation->getLastFreePos(veh);
      48      1352153 :     } else if (overheadWireSegment != nullptr) {
      49            0 :         return overheadWireSegment->getLastFreePos(veh);
      50              :     }
      51      1352153 :     return pars.endPos;
      52              : }
      53              : 
      54              : const MSEdge*
      55     11633799 : MSStop::getEdge() const {
      56     11633799 :     if (lane != nullptr) {
      57     11633799 :         return &lane->getEdge();
      58            0 :     } else if (segment != nullptr) {
      59            0 :         return &segment->getEdge();
      60              :     }
      61              :     return nullptr;
      62              : }
      63              : 
      64              : double
      65      3170624 : MSStop::getReachedThreshold() const {
      66      3170624 :     return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
      67              : }
      68              : 
      69              : std::string
      70           41 : MSStop::getDescription(bool nameOnly) const {
      71              :     std::string result;
      72           41 :     if (parkingarea != nullptr) {
      73            0 :         if (nameOnly) {
      74              :             return parkingarea->getID();
      75              :         }
      76            0 :         result = "parkingArea:" + parkingarea->getID();
      77           41 :     } else if (containerstop != nullptr) {
      78            0 :         if (nameOnly) {
      79              :             return containerstop->getID();
      80              :         }
      81            0 :         result = "containerStop:" + containerstop->getID();
      82           41 :     } else if (busstop != nullptr) {
      83           41 :         if (nameOnly) {
      84              :             return busstop->getID();
      85              :         }
      86            0 :         result = "busStop:" + busstop->getID();
      87            0 :     } else if (chargingStation != nullptr) {
      88            0 :         if (nameOnly) {
      89              :             return chargingStation->getID();
      90              :         }
      91            0 :         result = "chargingStation:" + chargingStation->getID();
      92            0 :     } else if (overheadWireSegment != nullptr) {
      93            0 :         if (nameOnly) {
      94              :             return overheadWireSegment->getID();
      95              :         }
      96            0 :         result = "overheadWireSegment:" + overheadWireSegment->getID();
      97              :     } else {
      98            0 :         if (nameOnly) {
      99            0 :             return "";
     100              :         }
     101            0 :         result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
     102              :     }
     103            0 :     if (pars.actType != "") {
     104            0 :         result += " actType:" + pars.actType;
     105              :     }
     106            0 :     return result;
     107              : }
     108              : 
     109              : 
     110              : std::pair<std::string, SumoXMLTag>
     111        85452 : MSStop::getStoppingPlaceName() const {
     112        85452 :     if (busstop != nullptr && !busstop->getMyName().empty()) {
     113         1403 :         return std::make_pair(busstop->getMyName(), SUMO_TAG_BUS_STOP);
     114        84049 :     } else if (containerstop != nullptr && !containerstop->getMyName().empty()) {
     115           48 :         return std::make_pair(containerstop->getMyName(), SUMO_TAG_CONTAINER_STOP);
     116        84001 :     } else if (parkingarea != nullptr && !parkingarea->getMyName().empty()) {
     117            0 :         return std::make_pair(parkingarea->getMyName(), SUMO_TAG_PARKING_AREA);
     118        84001 :     } else if (chargingStation != nullptr && !chargingStation->getMyName().empty()) {
     119            0 :         return std::make_pair(chargingStation->getMyName(), SUMO_TAG_CHARGING_STATION);
     120        84001 :     } else if (overheadWireSegment != nullptr && !overheadWireSegment->getMyName().empty()) {
     121            0 :         return std::make_pair(overheadWireSegment->getMyName(), SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
     122              :     }
     123              :     return std::make_pair("", SUMO_TAG_NOTHING);
     124              : }
     125              : 
     126              : 
     127              : void
     128          833 : MSStop::write(OutputDevice& dev) const {
     129          833 :     SUMOVehicleParameter::Stop tmp = pars;
     130          833 :     tmp.duration = duration;
     131          833 :     if (busstop == nullptr
     132          800 :             && containerstop == nullptr
     133          800 :             && parkingarea == nullptr
     134          269 :             && chargingStation == nullptr) {
     135          269 :         tmp.parametersSet |= STOP_START_SET | STOP_END_SET;
     136              :     }
     137          833 :     tmp.write(dev, false);
     138              :     // if the stop has already started but hasn't ended yet we are writing it in
     139              :     // the context of saveState (but we do not want to write the attribute twice
     140          833 :     if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
     141          486 :         dev.writeAttr(SUMO_ATTR_STARTED, time2string(pars.started));
     142              :     }
     143          833 :     pars.writeParams(dev);
     144          833 :     dev.closeTag();
     145          833 : }
     146              : 
     147              : void
     148       141320 : MSStop::initPars(const SUMOVehicleParameter::Stop& stopPar) {
     149       141320 :     busstop = MSNet::getInstance()->getStoppingPlace(stopPar.busstop, SUMO_TAG_BUS_STOP);
     150       141320 :     containerstop = MSNet::getInstance()->getStoppingPlace(stopPar.containerstop, SUMO_TAG_CONTAINER_STOP);
     151       141320 :     parkingarea = static_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stopPar.parkingarea, SUMO_TAG_PARKING_AREA));
     152       141320 :     chargingStation = MSNet::getInstance()->getStoppingPlace(stopPar.chargingStation, SUMO_TAG_CHARGING_STATION);
     153       141320 :     overheadWireSegment = MSNet::getInstance()->getStoppingPlace(stopPar.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
     154       141320 :     duration = stopPar.duration;
     155       141320 :     triggered = stopPar.triggered;
     156       141320 :     containerTriggered = stopPar.containerTriggered;
     157       141320 :     joinTriggered = stopPar.joinTriggered || stopPar.join != "";
     158       141320 :     numExpectedPerson = (int)stopPar.awaitedPersons.size();
     159       141320 :     numExpectedContainer = (int)stopPar.awaitedContainers.size();
     160       141320 : }
     161              : 
     162              : 
     163              : int
     164          237 : MSStop::getStateFlagsOld() const {
     165          237 :     return ((reached ? 1 : 0) + 2 * pars.getFlags());
     166              : }
     167              : 
     168              : 
     169              : SUMOTime
     170       136822 : MSStop::getMinDuration(SUMOTime time) const {
     171       136822 :     if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
     172           53 :         return pars.ended - time;
     173              :     }
     174       136769 :     if (pars.until >= 0) {
     175        71127 :         if (duration == -1) {
     176        56472 :             return pars.until - time;
     177              :         } else {
     178        14655 :             return MAX2(duration, pars.until - time);
     179              :         }
     180              :     } else {
     181        65642 :         return duration;
     182              :     }
     183              : }
     184              : 
     185              : 
     186              : SUMOTime
     187       652920 : MSStop::getUntil() const {
     188       652920 :     return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
     189              : }
     190              : 
     191              : 
     192              : SUMOTime
     193       154418 : MSStop::getArrival() const {
     194       154418 :     return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
     195              : }
     196              : 
     197              : 
     198              : SUMOTime
     199       101258 : MSStop::getArrivalFallback() const {
     200       101258 :     SUMOTime result = getArrival();
     201       101258 :     if (result < 0) {
     202       101177 :         result = getUntil();
     203       101177 :         if (result >= 0 && pars.duration >= 0) {
     204        14832 :             result -= pars.duration;
     205              :         }
     206              :     }
     207       101258 :     return result;
     208              : }
     209              : 
     210              : 
     211              : double
     212    115748437 : MSStop::getSpeed() const {
     213    115748437 :     return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
     214              : }
     215              : 
     216              : 
     217              : bool
     218        26764 : MSStop::isInRange(const double pos, const double tolerance) const {
     219        26764 :     return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
     220              : }
     221              : 
     222              : 
     223              : std::vector<MSStoppingPlace*>
     224           12 : MSStop::getPlaces() const {
     225              :     std::vector<MSStoppingPlace*> result;
     226           12 :     if (busstop != nullptr) {
     227           12 :         result.push_back(busstop);
     228              :     }
     229           12 :     if (containerstop != nullptr) {
     230            0 :         result.push_back(containerstop);
     231              :     }
     232           12 :     if (parkingarea != nullptr) {
     233            0 :         result.push_back(parkingarea);
     234              :     }
     235           12 :     if (chargingStation != nullptr) {
     236            0 :         result.push_back(chargingStation);
     237              :     }
     238           12 :     if (overheadWireSegment != nullptr) {
     239            0 :         result.push_back(overheadWireSegment);
     240              :     }
     241           12 :     return result;
     242            0 : }
     243              : 
     244              : 
     245              : void
     246           41 : MSStop::replaceStoppingPlace(MSStoppingPlace* sp) {
     247              :     // @note: assume iterator edge is handled elsewhere
     248              :     assert(*edge == &sp->getLane().getEdge());
     249           41 :     lane = &sp->getLane();
     250              :     SUMOVehicleParameter::Stop& ncPars = const_cast<SUMOVehicleParameter::Stop&>(pars);
     251           41 :     ncPars.edge = lane->getEdge().getID();
     252           41 :     ncPars.lane = lane->getID();
     253           41 :     ncPars.startPos = sp->getBeginLanePosition();
     254           41 :     ncPars.endPos = sp->getEndLanePosition();
     255           41 :     if (MSGlobals::gUseMesoSim) {
     256           12 :         segment = MSGlobals::gMesoNet->getSegmentForEdge(lane->getEdge(), sp->getEndLanePosition());
     257              :     }
     258           41 :     switch (sp->getElement()) {
     259           41 :         case SUMO_TAG_BUS_STOP:
     260              :         case SUMO_TAG_TRAIN_STOP:
     261           41 :             busstop = sp;
     262           41 :             ncPars.busstop = sp->getID();
     263              :             break;
     264            0 :         case SUMO_TAG_CONTAINER_STOP:
     265            0 :             containerstop = sp;
     266            0 :             ncPars.containerstop = sp->getID();
     267              :             break;
     268              :         case SUMO_TAG_PARKING_AREA:
     269            0 :             parkingarea = dynamic_cast<MSParkingArea*>(sp);
     270            0 :             ncPars.parkingarea = sp->getID();
     271              :             break;
     272            0 :         case SUMO_TAG_CHARGING_STATION:
     273            0 :             chargingStation = sp;
     274            0 :             ncPars.chargingStation = sp->getID();
     275              :             break;
     276            0 :         case SUMO_TAG_OVERHEAD_WIRE_SEGMENT:
     277            0 :             overheadWireSegment = sp;
     278            0 :             ncPars.overheadWireSegment = sp->getID();
     279              :             break;
     280           41 :         default:
     281              :             // should not happen
     282              :             assert(false);
     283              :     }
     284           41 : }
     285              : 
     286              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1