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.org/sumo
3// Copyright (C) 2001-2023 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 delete myState;
40}
41
42const MSEdge*
44 if (myCurrentInternalEdge != nullptr) {
46 } else {
47 return myRouteStep == myRoute.end() ? nullptr : *myRouteStep;
48 }
49}
50
51const MSEdge*
53 return myRoute.front();
54}
55
58 return myRoute;
59}
60
61
62double
64 return myState == nullptr ? 0. : myState->getEdgePos(*this, now);
65}
66
67int
69 return myState == nullptr ? MSPModel::UNDEFINED_DIRECTION : myState->getDirection(*this, MSNet::getInstance()->getCurrentTimeStep());
70}
71
72
75 return myState == nullptr ? Position::INVALID : myState->getPosition(*this, now);
76}
77
78double
80 return myState == nullptr ? 0. : myState->getAngle(*this, now);
81}
82
85 return myState == nullptr ? 0 : myState->getWaitingTime(*this, now);
86}
87
88double
90 return myState == nullptr ? 0. : myState->getSpeed(*this);
91}
92
93const MSLane*
95 return myState == nullptr ? nullptr : myState->getLane();
96}
97
98void
99MSStageMoving::setRouteIndex(MSTransportable* const transportable, int routeOffset) {
100 assert(routeOffset >= 0);
101 assert(routeOffset < (int)myRoute.size());
102 getEdge()->removeTransportable(transportable);
103 myRouteStep = myRoute.begin() + routeOffset;
104 getEdge()->addTransportable(transportable);
105}
106
107void
108MSStageMoving::replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset) {
109 assert(routeOffset >= 0);
110 assert(routeOffset < (int)edges.size());
111 getEdge()->removeTransportable(transportable);
112 myRoute = edges;
113 myRouteStep = myRoute.begin() + routeOffset;
114 getEdge()->addTransportable(transportable);
115}
116
117
118const MSLane*
119MSStageMoving::checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id) {
120 const MSLane* lane = getSidewalk<MSEdge, MSLane>(edge, svc);
121 if (laneIndex > 0) {
122 const std::vector<MSLane*>& departLanes = edge->getLanes();
123 if ((int)departLanes.size() <= laneIndex || !departLanes[laneIndex]->allowsVehicleClass(svc)) {
124 std::string error = "Invalid departLane '" + toString(laneIndex) + "' for person '" + id + "'";
125 if (OptionsCont::getOptions().getBool("ignore-route-errors")) {
126 WRITE_WARNING(error);
127 return nullptr;
128 } else {
129 throw ProcessError(error);
130 }
131 } else {
132 lane = departLanes[laneIndex];
133 }
134 }
135 return lane;
136}
137
138
139/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:267
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:1095
virtual void addTransportable(MSTransportable *t) const
Definition: MSEdge.cpp:1086
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:183
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:121
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.
MSTransportableStateAdapter * myState
state that is to be manipulated by MSPModel
ConstMSEdgeVector getEdges() const
the edges of the current stage
SUMOTime getWaitingTime(SUMOTime now) const
Returns the time the container spent waiting.
double getSpeed() const
Returns the speed of the container.
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.
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.
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 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 const MSLane * getLane() const
whether the transportable is jammed
Definition: MSPModel.h:207
virtual SUMOTime getWaitingTime(const MSStageMoving &stage, SUMOTime now) const =0
return the time the transportable spent standing
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 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:59
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:300