LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageWaiting.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 90 107 84.1 %
Date: 2024-05-07 15:28:01 Functions: 15 17 88.2 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-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    MSStageWaiting.cpp
      15             : /// @author  Melanie Weber
      16             : /// @author  Andreas Kendziorra
      17             : /// @author  Michael Behrisch
      18             : /// @author  Jakob Erdmann
      19             : /// @date    Wed, 1 Jun 2022
      20             : ///
      21             : // An stage for planned waiting (stopping)
      22             : /****************************************************************************/
      23             : #include <config.h>
      24             : 
      25             : #include <utils/vehicle/SUMOVehicleParameter.h>
      26             : #include <utils/geom/GeomHelper.h>
      27             : #include <microsim/MSEdge.h>
      28             : #include <microsim/MSLane.h>
      29             : #include <microsim/MSNet.h>
      30             : #include <microsim/MSStoppingPlace.h>
      31             : #include <microsim/transportables/MSTransportable.h>
      32             : #include <microsim/transportables/MSTransportableControl.h>
      33             : #include <microsim/transportables/MSStageWaiting.h>
      34             : 
      35             : /* -------------------------------------------------------------------------
      36             : * MSStageWaiting - methods
      37             : * ----------------------------------------------------------------------- */
      38      466685 : MSStageWaiting::MSStageWaiting(const MSEdge* destination, MSStoppingPlace* toStop,
      39             :                                SUMOTime duration, SUMOTime until, double pos, const std::string& actType,
      40      466685 :                                const bool initial) :
      41             :     MSStage(initial ? MSStageType::WAITING_FOR_DEPART : MSStageType::WAITING,
      42             :             destination,
      43             :             toStop,
      44      933370 :             SUMOVehicleParameter::interpretEdgePos(pos, destination->getLength(), SUMO_ATTR_DEPARTPOS, "stopping at " + destination->getID())),
      45      466685 :     myWaitingDuration(duration),
      46      466685 :     myWaitingUntil(until),
      47      466685 :     myStopWaitPos(Position::INVALID),
      48      466685 :     myActType(actType),
      49     1409626 :     myStopEndTime(-1) {
      50      466685 : }
      51             : 
      52             : 
      53      933699 : MSStageWaiting::~MSStageWaiting() {}
      54             : 
      55             : MSStage*
      56      424876 : MSStageWaiting::clone() const {
      57      424876 :     MSStage* const clon = new MSStageWaiting(myDestination, myDestinationStop, myWaitingDuration, myWaitingUntil, myArrivalPos,
      58      424876 :             myActType, myType == MSStageType::WAITING_FOR_DEPART);
      59      424876 :     clon->setParameters(*this);
      60      424876 :     return clon;
      61             : }
      62             : 
      63             : SUMOTime
      64           0 : MSStageWaiting::getUntil() const {
      65           0 :     return myWaitingUntil;
      66             : }
      67             : 
      68             : SUMOTime
      69          37 : MSStageWaiting::getPlannedDuration() const {
      70          37 :     return myWaitingDuration;
      71             : }
      72             : 
      73             : SUMOTime
      74       49860 : MSStageWaiting::getDuration() const {
      75       49860 :     return myType == MSStageType::WAITING_FOR_DEPART ? 0 : MSStage::getDuration();
      76             : }
      77             : 
      78             : Position
      79      104810 : MSStageWaiting::getPosition(SUMOTime /* now */) const {
      80             :     if (myStopWaitPos != Position::INVALID) {
      81         275 :         return myStopWaitPos;
      82             :     }
      83      104535 :     return getEdgePosition(myDestination, myArrivalPos,
      84      208990 :                            ROADSIDE_OFFSET * (MSGlobals::gLefthand ? -1 : 1));
      85             : }
      86             : 
      87             : 
      88             : double
      89        3040 : MSStageWaiting::getAngle(SUMOTime /* now */) const {
      90        3040 :     return getEdgeAngle(myDestination, myArrivalPos) + M_PI / 2 * (MSGlobals::gLefthand ? -1 : 1);
      91             : }
      92             : 
      93             : 
      94             : void
      95        9473 : MSStageWaiting::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
      96        9473 :     myDeparted = now;
      97        9473 :     myStopEndTime = MAX3(now, now + myWaitingDuration, myWaitingUntil);
      98        9473 :     if (myDestinationStop != nullptr) {
      99        4865 :         myDestinationStop->addTransportable(transportable);
     100        4865 :         myStopWaitPos = myDestinationStop->getWaitPosition(transportable);
     101             :     }
     102             : 
     103        9473 :     previous->getEdge()->addTransportable(transportable);
     104        9473 :     if (transportable->isPerson()) {
     105        5638 :         net->getPersonControl().setWaitEnd(myStopEndTime, transportable);
     106             :     } else {
     107        3835 :         net->getContainerControl().setWaitEnd(myStopEndTime, transportable);
     108             :     }
     109        9473 : }
     110             : 
     111             : 
     112             : void
     113       48442 : MSStageWaiting::tripInfoOutput(OutputDevice& os, const MSTransportable* const) const {
     114       48442 :     if (myType != MSStageType::WAITING_FOR_DEPART) {
     115         710 :         os.openTag(SUMO_TAG_STOP);
     116        1420 :         os.writeAttr("duration", getDuration() != SUMOTime_MAX ? time2string(getDuration()) : "-1");
     117        1420 :         os.writeAttr("arrival", time2string(myArrived));
     118        1420 :         os.writeAttr("arrivalPos", toString(myArrivalPos));
     119        1573 :         os.writeAttr("actType", myActType == "" ? "waiting" : myActType);
     120        1420 :         os.closeTag();
     121             :     }
     122       48442 : }
     123             : 
     124             : 
     125             : void
     126        3013 : MSStageWaiting::routeOutput(const bool /* isPerson */, OutputDevice& os, const bool, const MSStage* const /* previous */) const {
     127        3013 :     if (myType != MSStageType::WAITING_FOR_DEPART) {
     128         272 :         os.openTag(SUMO_TAG_STOP);
     129         272 :         std::string comment = "";
     130         272 :         if (myDestinationStop != nullptr) {
     131         124 :             os.writeAttr(toString(myDestinationStop->getElement()), myDestinationStop->getID());
     132         248 :             if (myDestinationStop->getMyName() != "") {
     133          60 :                 comment =  " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
     134             :             }
     135             :         } else {
     136             :             // lane index is arbitrary
     137         148 :             os.writeAttr(SUMO_ATTR_LANE, getDestination()->getID() + "_0");
     138         296 :             os.writeAttr(SUMO_ATTR_ENDPOS, getArrivalPos());
     139             :         }
     140         272 :         if (myWaitingDuration >= 0) {
     141         484 :             os.writeAttr(SUMO_ATTR_DURATION, time2string(myWaitingDuration));
     142             :         }
     143         272 :         if (myWaitingUntil >= 0) {
     144          72 :             os.writeAttr(SUMO_ATTR_UNTIL, time2string(myWaitingUntil));
     145             :         }
     146         544 :         if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
     147          30 :             os.writeAttr(SUMO_ATTR_STARTED, myDeparted >= 0 ? time2string(myDeparted) : "-1");
     148          60 :             os.writeAttr(SUMO_ATTR_ENDED, myArrived >= 0 ? time2string(myArrived) : "-1");
     149             :         }
     150         272 :         if (myActType != "") {
     151             :             os.writeAttr(SUMO_ATTR_ACTTYPE, myActType);
     152             :         }
     153             :         // Write rest of parameters
     154         272 :         writeParams(os);
     155         272 :         os.closeTag(comment);
     156             :     }
     157        3013 : }
     158             : 
     159             : 
     160             : void
     161          53 : MSStageWaiting::abort(MSTransportable* t) {
     162          53 :     MSTransportableControl& tc = (t->isPerson() ?
     163          53 :                                   MSNet::getInstance()->getPersonControl() :
     164           0 :                                   MSNet::getInstance()->getContainerControl());
     165          53 :     tc.abortWaiting(t);
     166          53 :     if (myType == MSStageType::WAITING_FOR_DEPART) {
     167          53 :         tc.forceDeparture();
     168             :     }
     169          53 : }
     170             : 
     171             : std::string
     172        1699 : MSStageWaiting::getStageDescription(const bool isPerson) const {
     173             :     UNUSED_PARAMETER(isPerson);
     174        1699 :     if (myActType != "") {
     175         198 :         return "waiting (" + myActType + ")";
     176             :     } else {
     177        1600 :         return "waiting";
     178             :     }
     179             : }
     180             : 
     181             : std::string
     182           0 : MSStageWaiting::getStageSummary(const bool /* isPerson */) const {
     183             :     std::string timeInfo;
     184           0 :     if (myWaitingUntil >= 0) {
     185           0 :         timeInfo += " until " + time2string(myWaitingUntil);
     186             :     }
     187           0 :     if (myWaitingDuration >= 0) {
     188           0 :         timeInfo += " duration " + time2string(myWaitingDuration);
     189             :     }
     190           0 :     if (getDestinationStop() != nullptr) {
     191           0 :         std::string nameMsg = "";
     192           0 :         if (getDestinationStop()->getMyName() != "") {
     193           0 :             nameMsg = "(" + getDestinationStop()->getMyName() + ") ";
     194             :         }
     195           0 :         return "stopping at stop '" + getDestinationStop()->getID() + "' " + nameMsg + timeInfo + " (" + myActType + ")";
     196             :     }
     197           0 :     return "stopping at edge '" + getDestination()->getID() + "' " + timeInfo + " (" + myActType + ")";
     198             : }
     199             : 
     200             : void
     201          12 : MSStageWaiting::saveState(std::ostringstream& out) {
     202          12 :     out << " " << myDeparted;
     203          12 : }
     204             : 
     205             : void
     206          12 : MSStageWaiting::loadState(MSTransportable* transportable, std::istringstream& state) {
     207          12 :     state >> myDeparted;
     208          12 :     const SUMOTime until = MAX3(myDeparted, myDeparted + myWaitingDuration, myWaitingUntil);
     209          12 :     if (myDestinationStop != nullptr) {
     210           0 :         myDestinationStop->addTransportable(transportable);
     211           0 :         myStopWaitPos = myDestinationStop->getWaitPosition(transportable);
     212             :     }
     213          12 :     if (myDeparted >= 0) {
     214           3 :         myDestination->addTransportable(transportable);
     215           3 :         MSNet* net = MSNet::getInstance();
     216           3 :         if (transportable->isPerson()) {
     217           3 :             net->getPersonControl().setWaitEnd(until, transportable);
     218             :         } else {
     219           0 :             net->getContainerControl().setWaitEnd(until, transportable);
     220             :         }
     221             :     }
     222          12 : }

Generated by: LCOV version 1.14