Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSStageWaiting.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// An stage for planned waiting (stopping)
22/****************************************************************************/
23#include <config.h>
24
27#include <microsim/MSEdge.h>
28#include <microsim/MSLane.h>
29#include <microsim/MSNet.h>
34
35/* -------------------------------------------------------------------------
36* MSStageWaiting - methods
37* ----------------------------------------------------------------------- */
39 SUMOTime duration, SUMOTime until, double pos, const std::string& actType,
40 const bool initial, SUMOTime jumpDuration) :
42 destination,
43 toStop,
44 SUMOVehicleParameter::interpretEdgePos(pos, destination->getLength(), SUMO_ATTR_DEPARTPOS, "stopping at " + destination->getID())),
45 myWaitingDuration(duration),
46 myWaitingUntil(until),
48 myActType(actType),
49 myJumpDuration(jumpDuration),
50 myStopEndTime(-1) {
51}
52
53
55
63
68
73
78
87
88
89double
91 const double offset = myDestinationStop == nullptr ? M_PI / 2 : myDestinationStop->getAngle();
92 return getEdgeAngle(myDestination, myArrivalPos) + offset * (MSGlobals::gLefthand ? -1 : 1);
93}
94
95
96void
97MSStageWaiting::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
98 myDeparted = now;
100 if (unspecifiedArrivalPos()) {
101 myArrivalPos = previous->getArrivalPos();
102 }
103 if (myDestinationStop != nullptr) {
104 myDestinationStop->addTransportable(transportable);
105 myStopWaitPos = myDestinationStop->getWaitPosition(transportable);
106 }
107
108 previous->getEdge()->addTransportable(transportable);
109 if (transportable->isPerson()) {
110 net->getPersonControl().setWaitEnd(myStopEndTime, transportable);
111 } else {
112 net->getContainerControl().setWaitEnd(myStopEndTime, transportable);
113 }
114}
115
116
117void
121 os.writeAttr("duration", getDuration() != SUMOTime_MAX ? time2string(getDuration()) : "-1");
122 os.writeAttr("arrival", time2string(myArrived));
123 os.writeAttr("arrivalPos", toString(myArrivalPos));
124 os.writeAttr("actType", myActType == "" ? "waiting" : myActType);
125 os.closeTag();
126 }
127}
128
129
130void
131MSStageWaiting::routeOutput(const bool /* isPerson */, OutputDevice& os, const bool, const MSStage* const /* previous */) const {
134 std::string comment = "";
135 if (myDestinationStop != nullptr) {
136 os.writeAttr(toString(myDestinationStop->getElement()), myDestinationStop->getID());
137 if (myDestinationStop->getMyName() != "") {
138 comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
139 }
140 } else {
141 // lane index is arbitrary
142 os.writeAttr(SUMO_ATTR_LANE, getDestination()->getID() + "_0");
144 }
145 if (myWaitingDuration >= 0) {
147 }
148 if (myWaitingUntil >= 0) {
150 }
151 if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
154 }
155 if (myJumpDuration >= 0) {
157 }
158 if (myActType != "") {
160 }
161 // Write rest of parameters
162 writeParams(os);
163 os.closeTag(comment);
164 }
165}
166
167
168void
170 MSTransportableControl& tc = (t->isPerson() ?
171 MSNet::getInstance()->getPersonControl() :
172 MSNet::getInstance()->getContainerControl());
173 tc.abortWaiting(t);
175 tc.forceDeparture();
176 }
177}
178
179std::string
180MSStageWaiting::getStageDescription(const bool isPerson) const {
181 UNUSED_PARAMETER(isPerson);
182 if (myActType != "") {
183 return "waiting (" + myActType + ")";
184 } else {
185 return "waiting";
186 }
187}
188
189std::string
190MSStageWaiting::getStageSummary(const bool /* isPerson */) const {
191 std::string timeInfo;
192 if (myWaitingUntil >= 0) {
193 timeInfo += " until " + time2string(myWaitingUntil);
194 }
195 if (myWaitingDuration >= 0) {
196 timeInfo += " duration " + time2string(myWaitingDuration);
197 }
198 if (getDestinationStop() != nullptr) {
199 std::string nameMsg = "";
200 if (getDestinationStop()->getMyName() != "") {
201 nameMsg = "(" + getDestinationStop()->getMyName() + ") ";
202 }
203 return "stopping at stop '" + getDestinationStop()->getID() + "' " + nameMsg + timeInfo + " (" + myActType + ")";
204 }
205 return "stopping at edge '" + getDestination()->getID() + "' " + timeInfo + " (" + myActType + ")";
206}
207
208void
209MSStageWaiting::saveState(std::ostringstream& out) {
210 out << " " << myDeparted;
211}
212
213void
214MSStageWaiting::loadState(MSTransportable* transportable, std::istringstream& state) {
215 state >> myDeparted;
217 if (myDestinationStop != nullptr) {
218 myDestinationStop->addTransportable(transportable);
219 myStopWaitPos = myDestinationStop->getWaitPosition(transportable);
220 }
221 if (myDeparted >= 0) {
222 myDestination->addTransportable(transportable);
223 MSNet* net = MSNet::getInstance();
224 if (transportable->isPerson()) {
225 net->getPersonControl().setWaitEnd(until, transportable);
226 } else {
227 net->getContainerControl().setWaitEnd(until, transportable);
228 }
229 }
230}
long long int SUMOTime
Definition GUI.h:36
MSStageType
Definition MSStage.h:55
@ WAITING_FOR_DEPART
Definition MSStage.h:56
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define SUMOTime_MAX
Definition SUMOTime.h:34
@ SUMO_TAG_STOP
stop for vehicles
@ SUMO_ATTR_LANE
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_ACTTYPE
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_JUMP
@ SUMO_ATTR_UNTIL
@ SUMO_ATTR_DURATION
T MAX3(T a, T b, T c)
Definition StdDefs.h:100
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A road/street connecting two junctions.
Definition MSEdge.h:77
virtual void addTransportable(MSTransportable *t) const
Definition MSEdge.cpp:1198
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition MSGlobals.h:174
The simulated network and simulation perfomer.
Definition MSNet.h:89
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1265
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1256
const MSEdge * getDestination() const
returns the destination edge
Definition MSStage.cpp:65
virtual double getArrivalPos() const
Definition MSStage.h:97
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition MSStage.h:305
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition MSStage.h:88
bool unspecifiedArrivalPos() const
Definition MSStage.cpp:197
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 SUMOTime getDuration() const
Definition MSStage.cpp:133
SUMOTime myArrived
the time at which this stage ended
Definition MSStage.h:317
MSStageType myType
The type of this stage.
Definition MSStage.h:320
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
Definition MSStage.cpp:182
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:334
double myArrivalPos
the longitudinal position at which we want to arrive
Definition MSStage.h:308
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
Definition MSStage.cpp:171
const MSEdge * myDestination
the next edge to reach by getting transported
Definition MSStage.h:302
SUMOTime myDeparted
the time at which this stage started
Definition MSStage.h:314
void loadState(MSTransportable *transportable, std::istringstream &state)
Reconstructs the current state, standard implementation does nothing.
void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const
Called on writing vehroute output.
SUMOTime getUntil() const
SUMOTime myWaitingDuration
the time the person is waiting
SUMOTime myWaitingUntil
the time until the person is waiting
SUMOTime getDuration() const
void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, MSStage *previous)
proceeds to the next step
void saveState(std::ostringstream &out)
Saves the current state into the given stream, standard implementation does nothing.
std::string getStageDescription(const bool isPerson) const
return (brief) string representation of the current stage
double getAngle(SUMOTime now) const
returns the angle of the transportable
SUMOTime getPlannedDuration() const
Position myStopWaitPos
waiting position at stopping place
SUMOTime myStopEndTime
stores the actual end time of the stop (combination of duration and until)
MSStage * clone() const
std::string myActType
The type of activity.
virtual ~MSStageWaiting()
destructor
void abort(MSTransportable *)
abort this stage (TraCI)
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Position getPosition(SUMOTime now) const
returns the position of the transportable
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
SUMOTime myJumpDuration
the jump duration if this stop is followed by a jump
MSStageWaiting(const MSEdge *destination, MSStoppingPlace *toStop, SUMOTime duration, SUMOTime until, double pos, const std::string &actType, const bool initial, SUMOTime jumpDuration=-1)
constructor
A lane area vehicles can halt at.
const std::string & getMyName() const
void setWaitEnd(SUMOTime time, MSTransportable *transportable)
sets the arrival time for a waiting transportable
void forceDeparture()
register forced (traci) departure
void abortWaiting(MSTransportable *t)
aborts waiting stage of transportable
bool isPerson() const override
Whether it is a person.
const std::string & getID() const
Returns the id.
Definition Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setParameters(const Parameterised &params)
set the given key/value map in map<string, string> format
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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
Structure representing possible vehicle parameter.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
#define UNUSED_PARAMETER(x)
#define M_PI
Definition odrSpiral.cpp:45