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),
47 myStopWaitPos(Position::INVALID),
48 myActType(actType),
49 myJumpDuration(jumpDuration),
50 myStopEndTime(-1) {
51}
52
53
55
63
68
73
78
87
88
89double
93
94
95void
96MSStageWaiting::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
97 myDeparted = now;
100 myArrivalPos = previous->getArrivalPos();
101 }
102 if (myDestinationStop != nullptr) {
103 myDestinationStop->addTransportable(transportable);
105 }
106
107 previous->getEdge()->addTransportable(transportable);
108 if (transportable->isPerson()) {
109 net->getPersonControl().setWaitEnd(myStopEndTime, transportable);
110 } else {
111 net->getContainerControl().setWaitEnd(myStopEndTime, transportable);
112 }
113}
114
115
116void
120 os.writeAttr("duration", getDuration() != SUMOTime_MAX ? time2string(getDuration()) : "-1");
121 os.writeAttr("arrival", time2string(myArrived));
122 os.writeAttr("arrivalPos", toString(myArrivalPos));
123 os.writeAttr("actType", myActType == "" ? "waiting" : myActType);
124 os.closeTag();
125 }
126}
127
128
129void
130MSStageWaiting::routeOutput(const bool /* isPerson */, OutputDevice& os, const bool, const MSStage* const /* previous */) const {
133 std::string comment = "";
134 if (myDestinationStop != nullptr) {
136 if (myDestinationStop->getMyName() != "") {
137 comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
138 }
139 } else {
140 // lane index is arbitrary
141 os.writeAttr(SUMO_ATTR_LANE, getDestination()->getID() + "_0");
143 }
144 if (myWaitingDuration >= 0) {
146 }
147 if (myWaitingUntil >= 0) {
149 }
150 if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
153 }
154 if (myJumpDuration >= 0) {
156 }
157 if (myActType != "") {
159 }
160 // Write rest of parameters
161 writeParams(os);
162 os.closeTag(comment);
163 }
164}
165
166
167void
177
178std::string
179MSStageWaiting::getStageDescription(const bool isPerson) const {
180 UNUSED_PARAMETER(isPerson);
181 if (myActType != "") {
182 return "waiting (" + myActType + ")";
183 } else {
184 return "waiting";
185 }
186}
187
188std::string
189MSStageWaiting::getStageSummary(const bool /* isPerson */) const {
190 std::string timeInfo;
191 if (myWaitingUntil >= 0) {
192 timeInfo += " until " + time2string(myWaitingUntil);
193 }
194 if (myWaitingDuration >= 0) {
195 timeInfo += " duration " + time2string(myWaitingDuration);
196 }
197 if (getDestinationStop() != nullptr) {
198 std::string nameMsg = "";
199 if (getDestinationStop()->getMyName() != "") {
200 nameMsg = "(" + getDestinationStop()->getMyName() + ") ";
201 }
202 return "stopping at stop '" + getDestinationStop()->getID() + "' " + nameMsg + timeInfo + " (" + myActType + ")";
203 }
204 return "stopping at edge '" + getDestination()->getID() + "' " + timeInfo + " (" + myActType + ")";
205}
206
207void
208MSStageWaiting::saveState(std::ostringstream& out) {
209 out << " " << myDeparted;
210}
211
212void
213MSStageWaiting::loadState(MSTransportable* transportable, std::istringstream& state) {
214 state >> myDeparted;
216 if (myDestinationStop != nullptr) {
217 myDestinationStop->addTransportable(transportable);
219 }
220 if (myDeparted >= 0) {
221 myDestination->addTransportable(transportable);
222 MSNet* net = MSNet::getInstance();
223 if (transportable->isPerson()) {
224 net->getPersonControl().setWaitEnd(until, transportable);
225 } else {
226 net->getContainerControl().setWaitEnd(until, transportable);
227 }
228 }
229}
long long int SUMOTime
Definition GUI.h:36
MSStageType
Definition MSStage.h:55
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:96
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:1194
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:1209
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1200
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
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.
SumoXMLTag getElement() const
return the type of this stopping place
const std::string & getMyName() const
Position getWaitPosition(MSTransportable *person) const
Returns the next free waiting place for pedestrians / containers.
bool addTransportable(const MSTransportable *p)
adds a transportable to this stop
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
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 inner 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:319
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