Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSStageMoving.cpp
Go to the documentation of this file.
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/****************************************************************************/
21// The common superclass for modelling walking and tranship
22/****************************************************************************/
23#include <config.h>
24
27#include <microsim/MSNet.h>
28#include <microsim/MSEdge.h>
29#include <microsim/MSLane.h>
33
34
35/* -------------------------------------------------------------------------
36* MSStageMoving - methods
37* ----------------------------------------------------------------------- */
39 if (myPState != nullptr && myPState->isFinished()) {
40 delete myPState;
41 }
42}
43
44const MSEdge*
46 if (myCurrentInternalEdge != nullptr) {
48 } else {
49 return myRouteStep == myRoute.end() ? nullptr : *myRouteStep;
50 }
51}
52
53const MSEdge*
55 return myRoute.front();
56}
57
60 return myRoute;
61}
62
63
64double
66 return myPState == nullptr ? myDepartPos : myPState->getEdgePos(now);
67}
68
69int
73
74
77 return myPState == nullptr ? Position::INVALID : myPState->getPosition(*this, now);
78}
79
80double
82 return myPState == nullptr ? 0. : myPState->getAngle(*this, now);
83}
84
87 return myPState == nullptr ? 0 : myPState->getWaitingTime();
88}
89
92 return myPState == nullptr ? 0 : myPState->getTotalWaitingTime();
93}
94
95double
97 return myPState == nullptr ? 0. : myPState->getSpeed(*this);
98}
99
100const MSLane*
102 return myPState == nullptr ? nullptr : myPState->getLane();
103}
104
105void
106MSStageMoving::setRouteIndex(MSTransportable* const transportable, int routeOffset) {
107 assert(routeOffset >= 0);
108 assert(routeOffset < (int)myRoute.size());
109 getEdge()->removeTransportable(transportable);
110 myRouteStep = myRoute.begin() + routeOffset;
111 getEdge()->addTransportable(transportable);
112}
113
114void
115MSStageMoving::replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset) {
116 assert(routeOffset >= 0);
117 assert(routeOffset < (int)edges.size());
118 getEdge()->removeTransportable(transportable);
119 myRoute = edges;
120 myRouteStep = myRoute.begin() + routeOffset;
121 getEdge()->addTransportable(transportable);
122}
123
124
125const MSLane*
126MSStageMoving::checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id) {
127 const MSLane* lane = getSidewalk<MSEdge, MSLane>(edge, svc);
128 if (laneIndex > 0) {
129 const std::vector<MSLane*>& departLanes = edge->getLanes();
130 if ((int)departLanes.size() <= laneIndex || !departLanes[laneIndex]->allowsVehicleClass(svc)) {
131 std::string error = "Invalid departLane '" + toString(laneIndex) + "' for person '" + id + "'";
132 if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
133 WRITE_WARNING(error);
134 return nullptr;
135 } else {
136 throw ProcessError(error);
137 }
138 } else {
139 lane = departLanes[laneIndex];
140 }
141 }
142 return lane;
143}
144
145
146/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A road/street connecting two junctions.
Definition MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
virtual void removeTransportable(MSTransportable *t) const
Definition MSEdge.cpp:1207
virtual void addTransportable(MSTransportable *t) const
Definition MSEdge.cpp:1198
Representation of a lane in the micro simulation.
Definition MSLane.h:84
static const int UNDEFINED_DIRECTION
Definition MSPModel.h:56
double getAngle(SUMOTime now) const
Returns the angle of the transportable.
const MSLane * getLane() const
Returns the current lane.
static const MSLane * checkDepartLane(const MSEdge *edge, SUMOVehicleClass svc, int laneIndex, const std::string &id)
interpret custom depart lane
double getEdgePos(SUMOTime now) const
Returns the offset from the start of the current edge measured in its natural direction.
int getDirection() const
Return the movement directon on the edge.
ConstMSEdgeVector getEdges() const
the edges of the current stage
double getSpeed() const
Returns the speed of the transportable.
std::vector< constMSEdge * >::iterator myRouteStep
current step
MSEdge * myCurrentInternalEdge
The current internal edge this transportable is on or nullptr.
Position getPosition(SUMOTime now) const
Returns the position of the container.
const MSEdge * getEdge() const
Returns the current edge.
MSTransportableStateAdapter * myPState
state that is to be manipulated by MSPModel
SUMOTime getWaitingTime() const
Returns the time the transportable spent waiting.
virtual void setRouteIndex(MSTransportable *const transportable, int routeOffset)
place transportable on a previously passed edge
SUMOTime getTotalWaitingTime() const
Returns the cumulative time the transportable spent waiting.
std::vector< const MSEdge * > myRoute
The route of the container.
double myDepartPos
the depart position
const MSEdge * getFromEdge() const
Returns first edge of the containers route.
virtual void replaceRoute(MSTransportable *const transportable, const ConstMSEdgeVector &edges, int routeOffset)
virtual ~MSStageMoving()
destructor
virtual SUMOTime getTotalWaitingTime() const
Definition MSPModel.h:173
virtual double getSpeed(const MSStageMoving &stage) const =0
return the current speed of the transportable
virtual Position getPosition(const MSStageMoving &stage, SUMOTime now) const =0
return the network coordinate of the transportable
virtual const MSLane * getLane() const
the current lane of the transportable
Definition MSPModel.h:220
virtual SUMOTime getWaitingTime() const =0
return the time the transportable spent standing consecutively
virtual int getDirection() const =0
return the walking direction (FORWARD, BACKWARD, UNDEFINED_DIRECTION)
virtual bool isFinished() const
whether the transportable has finished walking
Definition MSPModel.h:215
virtual double getAngle(const MSStageMoving &stage, SUMOTime now) const =0
return the direction in which the transportable faces in degrees
virtual double getEdgePos(SUMOTime now=0) const =0
return the offset from the start of the current edge measured in its natural direction
static OptionsCont & getOptions()
Retrieves the options.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:323