Eclipse SUMO - Simulation of Urban MObility
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-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 /****************************************************************************/
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 
44 const MSEdge*
46  if (myCurrentInternalEdge != nullptr) {
47  return myCurrentInternalEdge;
48  } else {
49  return myRouteStep == myRoute.end() ? nullptr : *myRouteStep;
50  }
51 }
52 
53 const MSEdge*
55  return myRoute.front();
56 }
57 
60  return myRoute;
61 }
62 
63 
64 double
66  return myPState == nullptr ? myDepartPos : myPState->getEdgePos(*this, now);
67 }
68 
69 int
71  return myPState == nullptr ? MSPModel::UNDEFINED_DIRECTION : myPState->getDirection(*this, MSNet::getInstance()->getCurrentTimeStep());
72 }
73 
74 
77  return myPState == nullptr ? Position::INVALID : myPState->getPosition(*this, now);
78 }
79 
80 double
82  return myPState == nullptr ? 0. : myPState->getAngle(*this, now);
83 }
84 
87  return myPState == nullptr ? 0 : myPState->getWaitingTime(*this, now);
88 }
89 
90 double
92  return myPState == nullptr ? 0. : myPState->getSpeed(*this);
93 }
94 
95 const MSLane*
97  return myPState == nullptr ? nullptr : myPState->getLane();
98 }
99 
100 void
101 MSStageMoving::setRouteIndex(MSTransportable* const transportable, int routeOffset) {
102  assert(routeOffset >= 0);
103  assert(routeOffset < (int)myRoute.size());
104  getEdge()->removeTransportable(transportable);
105  myRouteStep = myRoute.begin() + routeOffset;
106  getEdge()->addTransportable(transportable);
107 }
108 
109 void
110 MSStageMoving::replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset) {
111  assert(routeOffset >= 0);
112  assert(routeOffset < (int)edges.size());
113  getEdge()->removeTransportable(transportable);
114  myRoute = edges;
115  myRouteStep = myRoute.begin() + routeOffset;
116  getEdge()->addTransportable(transportable);
117 }
118 
119 
120 const MSLane*
121 MSStageMoving::checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id) {
122  const MSLane* lane = getSidewalk<MSEdge, MSLane>(edge, svc);
123  if (laneIndex > 0) {
124  const std::vector<MSLane*>& departLanes = edge->getLanes();
125  if ((int)departLanes.size() <= laneIndex || !departLanes[laneIndex]->allowsVehicleClass(svc)) {
126  std::string error = "Invalid departLane '" + toString(laneIndex) + "' for person '" + id + "'";
127  if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
128  WRITE_WARNING(error);
129  return nullptr;
130  } else {
131  throw ProcessError(error);
132  }
133  } else {
134  lane = departLanes[laneIndex];
135  }
136  }
137  return lane;
138 }
139 
140 
141 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
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:1133
virtual void addTransportable(MSTransportable *t) const
Definition: MSEdge.cpp:1124
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:121
virtual SUMOTime getWaitingTime() const
Definition: MSStage.cpp:150
double getAngle(SUMOTime now) const
Returns the angle of the container.
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 container.
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
virtual void setRouteIndex(MSTransportable *const transportable, int routeOffset)
place transportable on a previously passed edge
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)
std::vector< const MSEdge * >::iterator myRouteStep
current step
virtual ~MSStageMoving()
destructor
virtual double getSpeed(const MSStageMoving &stage) const =0
return the current speed of the transportable
virtual int getDirection(const MSStageMoving &stage, SUMOTime now) const =0
return the walking direction (FORWARD, BACKWARD)
virtual Position getPosition(const MSStageMoving &stage, SUMOTime now) const =0
return the network coordinate of the transportable
virtual SUMOTime getWaitingTime(const MSStageMoving &stage, SUMOTime now) const =0
return the time the transportable spent standing
virtual bool isFinished() const
whether the transportable has finished walking
Definition: MSPModel.h:213
virtual double getEdgePos(const MSStageMoving &stage, SUMOTime now) const =0
return the offset from the start of the current edge measured in its natural direction
virtual const MSLane * getLane() const
the current lane of the transportable
Definition: MSPModel.h:218
virtual double getAngle(const MSStageMoving &stage, SUMOTime now) const =0
return the direction in which the transportable faces in degrees
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
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:317