LCOV - code coverage report
Current view: top level - src/microsim - MSStop.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.2 % 82 74
Test Date: 2024-11-22 15:46:21 Functions: 100.0 % 12 12

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2005-2024 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 "MSLane.h"
      25              : #include "MSNet.h"
      26              : #include "MSParkingArea.h"
      27              : #include "MSStoppingPlace.h"
      28              : #include "MSStop.h"
      29              : 
      30              : 
      31              : // ===========================================================================
      32              : // method definitions
      33              : // ===========================================================================
      34              : double
      35      7441415 : MSStop::getEndPos(const SUMOVehicle& veh) const {
      36      7441415 :     const double brakePos = veh.getEdge() == getEdge() ? veh.getPositionOnLane() + veh.getBrakeGap() : 0;
      37      7441415 :     if ((pars.parametersSet & STOP_END_SET) != 0) {
      38      3780518 :         return pars.endPos;
      39      3660897 :     } else if (busstop != nullptr) {
      40       843626 :         return busstop->getLastFreePos(veh, brakePos);
      41      2817271 :     } else if (containerstop != nullptr) {
      42        23973 :         return containerstop->getLastFreePos(veh, brakePos);
      43      2793298 :     } else if (parkingarea != nullptr) {
      44       790690 :         return parkingarea->getLastFreePos(veh, brakePos);
      45      2002608 :     } else if (chargingStation != nullptr) {
      46       479858 :         return chargingStation->getLastFreePos(veh);
      47      1522750 :     } else if (overheadWireSegment != nullptr) {
      48            0 :         return overheadWireSegment->getLastFreePos(veh);
      49              :     }
      50      1522750 :     return pars.endPos;
      51              : }
      52              : 
      53              : const MSEdge*
      54      7517543 : MSStop::getEdge() const {
      55      7517543 :     if (lane != nullptr) {
      56      7517543 :         return &lane->getEdge();
      57            0 :     } else if (segment != nullptr) {
      58            0 :         return &segment->getEdge();
      59              :     }
      60              :     return nullptr;
      61              : }
      62              : 
      63              : double
      64      2992875 : MSStop::getReachedThreshold() const {
      65      2992875 :     return isOpposite ? lane->getOppositePos(pars.endPos) - (pars.endPos - pars.startPos) : pars.startPos;
      66              : }
      67              : 
      68              : std::string
      69            2 : MSStop::getDescription() const {
      70              :     std::string result;
      71            2 :     if (parkingarea != nullptr) {
      72            0 :         result = "parkingArea:" + parkingarea->getID();
      73            2 :     } else if (containerstop != nullptr) {
      74            0 :         result = "containerStop:" + containerstop->getID();
      75            2 :     } else if (busstop != nullptr) {
      76            2 :         result = "busStop:" + busstop->getID();
      77            1 :     } else if (chargingStation != nullptr) {
      78            0 :         result = "chargingStation:" + chargingStation->getID();
      79            1 :     } else if (overheadWireSegment != nullptr) {
      80            0 :         result = "overheadWireSegment:" + overheadWireSegment->getID();
      81              :     } else {
      82            3 :         result = "lane:" + lane->getID() + " pos:" + toString(pars.endPos);
      83              :     }
      84            2 :     if (pars.actType != "") {
      85            0 :         result += " actType:" + pars.actType;
      86              :     }
      87            2 :     return result;
      88              : }
      89              : 
      90              : 
      91              : void
      92          568 : MSStop::write(OutputDevice& dev) const {
      93          568 :     SUMOVehicleParameter::Stop tmp = pars;
      94          568 :     tmp.duration = duration;
      95          568 :     if (busstop == nullptr
      96          545 :             && containerstop == nullptr
      97          545 :             && parkingarea == nullptr
      98          254 :             && chargingStation == nullptr) {
      99          254 :         tmp.parametersSet |= STOP_START_SET | STOP_END_SET;
     100              :     }
     101          568 :     tmp.write(dev, false);
     102              :     // if the stop has already started but hasn't ended yet we are writing it in
     103              :     // the context of saveState (but we do not want to write the attribute twice
     104          568 :     if (pars.started >= 0 && (pars.parametersSet & STOP_STARTED_SET) == 0) {
     105          426 :         dev.writeAttr(SUMO_ATTR_STARTED, time2string(pars.started));
     106              :     }
     107          568 :     pars.writeParams(dev);
     108          568 :     dev.closeTag();
     109          568 : }
     110              : 
     111              : void
     112       127345 : MSStop::initPars(const SUMOVehicleParameter::Stop& stopPar) {
     113       127345 :     busstop = MSNet::getInstance()->getStoppingPlace(stopPar.busstop, SUMO_TAG_BUS_STOP);
     114       127345 :     containerstop = MSNet::getInstance()->getStoppingPlace(stopPar.containerstop, SUMO_TAG_CONTAINER_STOP);
     115       127345 :     parkingarea = static_cast<MSParkingArea*>(MSNet::getInstance()->getStoppingPlace(stopPar.parkingarea, SUMO_TAG_PARKING_AREA));
     116       127345 :     chargingStation = MSNet::getInstance()->getStoppingPlace(stopPar.chargingStation, SUMO_TAG_CHARGING_STATION);
     117       127345 :     overheadWireSegment = MSNet::getInstance()->getStoppingPlace(stopPar.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
     118       127345 :     duration = stopPar.duration;
     119       127345 :     triggered = stopPar.triggered;
     120       127345 :     containerTriggered = stopPar.containerTriggered;
     121       127345 :     joinTriggered = stopPar.joinTriggered || stopPar.join != "";
     122       127345 :     numExpectedPerson = (int)stopPar.awaitedPersons.size();
     123       127345 :     numExpectedContainer = (int)stopPar.awaitedContainers.size();
     124       127345 : }
     125              : 
     126              : 
     127              : int
     128          158 : MSStop::getStateFlagsOld() const {
     129          158 :     return ((reached ? 1 : 0) + 2 * pars.getFlags());
     130              : }
     131              : 
     132              : 
     133              : SUMOTime
     134        54391 : MSStop::getMinDuration(SUMOTime time) const {
     135        54391 :     if (MSGlobals::gUseStopEnded && pars.ended >= 0) {
     136           48 :         return pars.ended - time;
     137              :     }
     138        54343 :     if (pars.until >= 0) {
     139        17745 :         if (duration == -1) {
     140        12896 :             return pars.until - time;
     141              :         } else {
     142         4849 :             return MAX2(duration, pars.until - time);
     143              :         }
     144              :     } else {
     145        36598 :         return duration;
     146              :     }
     147              : }
     148              : 
     149              : 
     150              : SUMOTime
     151       486330 : MSStop::getUntil() const {
     152       486330 :     return MSGlobals::gUseStopEnded && pars.ended >= 0 ? pars.ended : pars.until;
     153              : }
     154              : 
     155              : 
     156              : SUMOTime
     157        41043 : MSStop::getArrival() const {
     158        41043 :     return MSGlobals::gUseStopStarted && pars.started >= 0 ? pars.started : pars.arrival;
     159              : }
     160              : 
     161              : 
     162              : double
     163     95357383 : MSStop::getSpeed() const {
     164     95357383 :     return skipOnDemand ? std::numeric_limits<double>::max() : pars.speed;
     165              : }
     166              : 
     167              : 
     168              : bool
     169        19426 : MSStop::isInRange(const double pos, const double tolerance) const {
     170        19426 :     return pars.startPos - tolerance <= pos && pars.endPos + tolerance >= pos;
     171              : }
     172              : 
     173              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1