LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageMoving.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 40 44 90.9 %
Date: 2024-05-06 15:32:35 Functions: 14 15 93.3 %

          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    MSStageMoving.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             : // The common superclass for modelling walking and tranship
      22             : /****************************************************************************/
      23             : #include <config.h>
      24             : 
      25             : #include <utils/options/OptionsCont.h>
      26             : #include <utils/router/IntermodalEdge.h>
      27             : #include <microsim/MSNet.h>
      28             : #include <microsim/MSEdge.h>
      29             : #include <microsim/MSLane.h>
      30             : #include <microsim/transportables/MSPModel.h>
      31             : #include <microsim/transportables/MSTransportable.h>
      32             : #include <microsim/transportables/MSStageMoving.h>
      33             : 
      34             : 
      35             : /* -------------------------------------------------------------------------
      36             : * MSStageMoving - methods
      37             : * ----------------------------------------------------------------------- */
      38      402609 : MSStageMoving::~MSStageMoving() {
      39      402609 :     if (myPState != nullptr && myPState->isFinished()) {
      40      402123 :         delete myPState;
      41             :     }
      42      402609 : }
      43             : 
      44             : const MSEdge*
      45     5439659 : MSStageMoving::getEdge() const {
      46     5439659 :     if (myCurrentInternalEdge != nullptr) {
      47             :         return myCurrentInternalEdge;
      48             :     } else {
      49     4360066 :         return myRouteStep == myRoute.end() ? nullptr : *myRouteStep;
      50             :     }
      51             : }
      52             : 
      53             : const MSEdge*
      54      116324 : MSStageMoving::getFromEdge() const {
      55      116324 :     return myRoute.front();
      56             : }
      57             : 
      58             : ConstMSEdgeVector
      59      328535 : MSStageMoving::getEdges() const {
      60      328535 :     return myRoute;
      61             : }
      62             : 
      63             : 
      64             : double
      65    11944081 : MSStageMoving::getEdgePos(SUMOTime now) const {
      66    11944081 :     return myPState == nullptr ? myDepartPos : myPState->getEdgePos(*this, now);
      67             : }
      68             : 
      69             : int
      70      359922 : MSStageMoving::getDirection() const {
      71      359922 :     return myPState == nullptr ? MSPModel::UNDEFINED_DIRECTION : myPState->getDirection(*this, MSNet::getInstance()->getCurrentTimeStep());
      72             : }
      73             : 
      74             : 
      75             : Position
      76     4569745 : MSStageMoving::getPosition(SUMOTime now) const {
      77     4569745 :     return myPState == nullptr ? Position::INVALID : myPState->getPosition(*this, now);
      78             : }
      79             : 
      80             : double
      81     2510727 : MSStageMoving::getAngle(SUMOTime now) const {
      82     2510727 :     return myPState == nullptr ? 0. : myPState->getAngle(*this, now);
      83             : }
      84             : 
      85             : SUMOTime
      86     9679645 : MSStageMoving::getWaitingTime(SUMOTime now) const {
      87     9679645 :     return myPState == nullptr ? 0 : myPState->getWaitingTime(*this, now);
      88             : }
      89             : 
      90             : double
      91      733403 : MSStageMoving::getSpeed() const {
      92      733403 :     return myPState == nullptr ? 0. : myPState->getSpeed(*this);
      93             : }
      94             : 
      95             : const MSLane*
      96      930598 : MSStageMoving::getLane() const {
      97      930598 :     return myPState == nullptr ? nullptr : myPState->getLane();
      98             : }
      99             : 
     100             : void
     101       16268 : MSStageMoving::setRouteIndex(MSTransportable* const transportable, int routeOffset) {
     102             :     assert(routeOffset >= 0);
     103             :     assert(routeOffset < (int)myRoute.size());
     104       16268 :     getEdge()->removeTransportable(transportable);
     105       16268 :     myRouteStep = myRoute.begin() + routeOffset;
     106       16268 :     getEdge()->addTransportable(transportable);
     107       16268 : }
     108             : 
     109             : void
     110          84 : MSStageMoving::replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset) {
     111             :     assert(routeOffset >= 0);
     112             :     assert(routeOffset < (int)edges.size());
     113          84 :     getEdge()->removeTransportable(transportable);
     114          84 :     myRoute = edges;
     115          84 :     myRouteStep = myRoute.begin() + routeOffset;
     116          84 :     getEdge()->addTransportable(transportable);
     117          84 : }
     118             : 
     119             : 
     120             : const MSLane*
     121      269580 : MSStageMoving::checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id) {
     122      269580 :     const MSLane* lane = getSidewalk<MSEdge, MSLane>(edge, svc);
     123      269580 :     if (laneIndex > 0) {
     124             :         const std::vector<MSLane*>& departLanes = edge->getLanes();
     125           4 :         if ((int)departLanes.size() <= laneIndex || !departLanes[laneIndex]->allowsVehicleClass(svc)) {
     126           0 :             std::string error = "Invalid departLane '" + toString(laneIndex) + "' for person '" + id + "'";
     127           0 :             if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
     128           0 :                 WRITE_WARNING(error);
     129             :                 return nullptr;
     130             :             } else {
     131           0 :                 throw ProcessError(error);
     132             :             }
     133             :         } else {
     134             :             lane = departLanes[laneIndex];
     135             :         }
     136             :     }
     137             :     return lane;
     138             : }
     139             : 
     140             : 
     141             : /****************************************************************************/

Generated by: LCOV version 1.14