Eclipse SUMO - Simulation of Urban MObility
MSStage.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 /****************************************************************************/
20 // The common superclass for modelling transportable objects like persons and containers
21 /****************************************************************************/
22 #include <config.h>
23 
25 #include <microsim/MSEdge.h>
26 #include <microsim/MSLane.h>
27 #include <microsim/MSNet.h>
33 
34 
35 /* -------------------------------------------------------------------------
36 * static member definitions
37 * ----------------------------------------------------------------------- */
38 const double MSStage::ROADSIDE_OFFSET(3);
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 /* -------------------------------------------------------------------------
45  * MSStage - methods
46  * ----------------------------------------------------------------------- */
47 MSStage::MSStage(MSStageType type, const MSEdge* destination, MSStoppingPlace* toStop, const double arrivalPos,
48  const double arrivalPosLat, const std::string& group) :
49  myDestination(destination),
50  myDestinationStop(toStop),
51  myArrivalPos(arrivalPos),
52  myArrivalPosLat(arrivalPosLat),
53  myDeparted(-1),
54  myArrived(-1),
55  myType(type),
56  myGroup(group),
57  myCosts(-1),
58  myParametersSet(0)
59 {}
60 
62 
63 
64 const MSEdge*
66  return myDestination;
67 }
68 
69 
70 const MSEdge*
72  return myDestination;
73 }
74 
75 
76 const MSEdge*
78  return myDestination;
79 }
80 
81 
82 double
83 MSStage::getEdgePos(SUMOTime /* now */) const {
84  return myArrivalPos;
85 }
86 
87 
88 double
89 MSStage::getEdgePosLat(SUMOTime /* now */) const {
90  return myArrivalPosLat;
91 }
92 
93 
94 int
97 }
98 
99 
100 SUMOTime
102  return 0;
103 }
104 
105 
106 double
108  return 0.;
109 }
110 
111 
114  ConstMSEdgeVector result;
115  result.push_back(getDestination());
116  return result;
117 }
118 
119 
120 void
122  if (myDeparted < 0) {
123  myDeparted = now;
124  }
125 }
126 
127 SUMOTime
129  return myDeparted;
130 }
131 
132 SUMOTime
134  return myArrived;
135 }
136 
137 
138 SUMOTime
140  return myArrived >= 0 ? myArrived - myDeparted : SUMOTime_MAX;
141 }
142 
143 
144 SUMOTime
146  return getDuration();
147 }
148 
149 SUMOTime
151  return 0;
152 }
153 
154 SUMOTime
155 MSStage::getTimeLoss(const MSTransportable* /*transportable*/) const {
156  return 0;
157 }
158 
159 
160 const std::string
161 MSStage::setArrived(MSNet* /* net */, MSTransportable* /* transportable */, SUMOTime now, const bool /* vehicleArrived */) {
162  myArrived = now;
163  return "";
164 }
165 
166 bool
167 MSStage::isWaitingFor(const SUMOVehicle* /*vehicle*/) const {
168  return false;
169 }
170 
171 Position
172 MSStage::getEdgePosition(const MSEdge* e, double at, double offset) const {
173  return getLanePosition(e->getLanes()[0], at, offset);
174 }
175 
176 Position
177 MSStage::getLanePosition(const MSLane* lane, double at, double offset) const {
178  return lane->getShape().positionAtOffset(lane->interpolateLanePosToGeometryPos(at), offset);
179 }
180 
181 
182 double
183 MSStage::getEdgeAngle(const MSEdge* e, double at) const {
184  return e->getLanes()[0]->getShape().rotationAtOffset(at);
185 }
186 
187 
188 void
189 MSStage::setDestination(const MSEdge* newDestination, MSStoppingPlace* newDestStop) {
190  myDestination = newDestination;
191  myDestinationStop = newDestStop;
192  if (newDestStop != nullptr) {
193  myArrivalPos = (newDestStop->getBeginLanePosition() + newDestStop->getEndLanePosition()) / 2;
194  }
195 }
196 
197 
198 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
MSStageType
Definition: MSStage.h:54
#define SUMOTime_MAX
Definition: SUMOTime.h:34
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
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:546
virtual const PositionVector & getShape(bool) const
Definition: MSLane.h:294
The simulated network and simulation perfomer.
Definition: MSNet.h:89
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:121
virtual ~MSStage()
destructor
Definition: MSStage.cpp:61
const MSEdge * getDestination() const
returns the destination edge
Definition: MSStage.cpp:65
double myArrivalPosLat
the lateral position at which we want to arrive
Definition: MSStage.h:278
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition: MSStage.cpp:113
virtual double getEdgePos(SUMOTime now) const
Definition: MSStage.cpp:83
virtual int getDirection() const
Return the movement directon on the edge.
Definition: MSStage.cpp:95
virtual const MSEdge * getFromEdge() const
Definition: MSStage.cpp:77
virtual double getEdgePosLat(SUMOTime now) const
Definition: MSStage.cpp:89
virtual SUMOTime getTimeLoss(const MSTransportable *transportable) const
Definition: MSStage.cpp:155
virtual SUMOTime getTravelTime() const
Definition: MSStage.cpp:145
SUMOTime getDeparted() const
get departure time of stage
Definition: MSStage.cpp:128
void setDeparted(SUMOTime now)
logs end of the step
Definition: MSStage.cpp:121
virtual bool isWaitingFor(const SUMOVehicle *vehicle) const
Whether the transportable waits for the given vehicle.
Definition: MSStage.cpp:167
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:272
virtual const std::string setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now, const bool vehicleArrived)
logs end of the step
Definition: MSStage.cpp:161
SUMOTime getArrived() const
get arrival time of stage
Definition: MSStage.cpp:133
MSStage(const MSStageType type, const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double arrivalPosLat=0.0, const std::string &group="")
constructor
Definition: MSStage.cpp:47
virtual double getSpeed() const
the speed of the transportable
Definition: MSStage.cpp:107
virtual SUMOTime getWaitingTime() const
Definition: MSStage.cpp:150
virtual SUMOTime getDuration() const
Definition: MSStage.cpp:139
SUMOTime myArrived
the time at which this stage ended
Definition: MSStage.h:284
void setDestination(const MSEdge *newDestination, MSStoppingPlace *newDestStop)
Definition: MSStage.cpp:189
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
Definition: MSStage.cpp:177
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
Definition: MSStage.cpp:183
virtual const MSEdge * getEdge() const
Returns the current edge.
Definition: MSStage.cpp:71
static const double ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
Definition: MSStage.h:299
double myArrivalPos
the longitudinal position at which we want to arrive
Definition: MSStage.h:275
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
Definition: MSStage.cpp:172
const MSEdge * myDestination
the next edge to reach by getting transported
Definition: MSStage.h:269
SUMOTime myDeparted
the time at which this stage started
Definition: MSStage.h:281
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
double getEndLanePosition() const
Returns the end position of this stop.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Representation of a vehicle.
Definition: SUMOVehicle.h:60