Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 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 402664 : MSStageMoving::~MSStageMoving() {
39 402664 : if (myPState != nullptr && myPState->isFinished()) {
40 397957 : delete myPState;
41 : }
42 402664 : }
43 :
44 : const MSEdge*
45 5539995 : MSStageMoving::getEdge() const {
46 5539995 : if (myCurrentInternalEdge != nullptr) {
47 : return myCurrentInternalEdge;
48 : } else {
49 3948182 : return myRouteStep == myRoute.end() ? nullptr : *myRouteStep;
50 : }
51 : }
52 :
53 : const MSEdge*
54 156990 : MSStageMoving::getFromEdge() const {
55 156990 : return myRoute.front();
56 : }
57 :
58 : ConstMSEdgeVector
59 347100 : MSStageMoving::getEdges() const {
60 347100 : return myRoute;
61 : }
62 :
63 :
64 : double
65 11849794 : MSStageMoving::getEdgePos(SUMOTime now) const {
66 11849794 : return myPState == nullptr ? myDepartPos : myPState->getEdgePos(now);
67 : }
68 :
69 : int
70 368032 : MSStageMoving::getDirection() const {
71 368032 : return myPState == nullptr ? MSPModel::UNDEFINED_DIRECTION : myPState->getDirection();
72 : }
73 :
74 :
75 : Position
76 4859788 : MSStageMoving::getPosition(SUMOTime now) const {
77 4859788 : return myPState == nullptr ? Position::INVALID : myPState->getPosition(*this, now);
78 : }
79 :
80 : double
81 2814618 : MSStageMoving::getAngle(SUMOTime now) const {
82 2814618 : return myPState == nullptr ? 0. : myPState->getAngle(*this, now);
83 : }
84 :
85 : SUMOTime
86 11267466 : MSStageMoving::getWaitingTime() const {
87 11267466 : return myPState == nullptr ? 0 : myPState->getWaitingTime();
88 : }
89 :
90 : SUMOTime
91 110800 : MSStageMoving::getTotalWaitingTime() const {
92 110800 : return myPState == nullptr ? 0 : myPState->getTotalWaitingTime();
93 : }
94 :
95 : double
96 732612 : MSStageMoving::getSpeed() const {
97 732612 : return myPState == nullptr ? 0. : myPState->getSpeed(*this);
98 : }
99 :
100 : const MSLane*
101 938315 : MSStageMoving::getLane() const {
102 938315 : return myPState == nullptr ? nullptr : myPState->getLane();
103 : }
104 :
105 : void
106 10908 : MSStageMoving::setRouteIndex(MSTransportable* const transportable, int routeOffset) {
107 : assert(routeOffset >= 0);
108 : assert(routeOffset < (int)myRoute.size());
109 10908 : getEdge()->removeTransportable(transportable);
110 10908 : myRouteStep = myRoute.begin() + routeOffset;
111 10908 : getEdge()->addTransportable(transportable);
112 10908 : }
113 :
114 : void
115 49 : MSStageMoving::replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset) {
116 : assert(routeOffset >= 0);
117 : assert(routeOffset < (int)edges.size());
118 49 : getEdge()->removeTransportable(transportable);
119 49 : myRoute = edges;
120 49 : myRouteStep = myRoute.begin() + routeOffset;
121 49 : getEdge()->addTransportable(transportable);
122 49 : }
123 :
124 :
125 : const MSLane*
126 243028 : MSStageMoving::checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id) {
127 243028 : const MSLane* lane = getSidewalk<MSEdge, MSLane>(edge, svc);
128 243028 : if (laneIndex > 0) {
129 : const std::vector<MSLane*>& departLanes = edge->getLanes();
130 4 : if ((int)departLanes.size() <= laneIndex || !departLanes[laneIndex]->allowsVehicleClass(svc)) {
131 0 : std::string error = "Invalid departLane '" + toString(laneIndex) + "' for person '" + id + "'";
132 0 : if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
133 0 : WRITE_WARNING(error);
134 : return nullptr;
135 : } else {
136 0 : throw ProcessError(error);
137 : }
138 : } else {
139 : lane = departLanes[laneIndex];
140 : }
141 : }
142 : return lane;
143 : }
144 :
145 :
146 : /****************************************************************************/
|