Eclipse SUMO - Simulation of Urban MObility
MSStageWaiting.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-2022 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) :
41 MSStage(destination, toStop, SUMOVehicleParameter::interpretEdgePos(
42 pos, destination->getLength(), SUMO_ATTR_DEPARTPOS, "stopping at " + destination->getID()),
44 myWaitingDuration(duration),
45 myWaitingUntil(until),
46 myStopWaitPos(Position::INVALID),
47 myActType(actType),
48 myStopEndTime(-1) {
49}
50
51
53
57}
58
61 return myWaitingUntil;
62}
63
66 return myWaitingDuration;
67}
68
69
73 return myStopWaitPos;
74 }
77}
78
79
80double
83}
84
85
86void
87MSStageWaiting::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
88 myDeparted = now;
90 if (myDestinationStop != nullptr) {
91 myDestinationStop->addTransportable(transportable);
93 }
94
95 previous->getEdge()->addTransportable(transportable);
96 if (transportable->isPerson()) {
97 net->getPersonControl().setWaitEnd(myStopEndTime, transportable);
98 } else {
99 net->getContainerControl().setWaitEnd(myStopEndTime, transportable);
100 }
101}
102
103
104void
108 os.writeAttr("duration", time2string(myArrived - myDeparted));
109 os.writeAttr("arrival", time2string(myArrived));
110 os.writeAttr("arrivalPos", toString(myArrivalPos));
111 os.writeAttr("actType", myActType == "" ? "waiting" : myActType);
112 os.closeTag();
113 }
114}
115
116
117void
118MSStageWaiting::routeOutput(const bool /* isPerson */, OutputDevice& os, const bool, const MSStage* const /* previous */) const {
121 std::string comment = "";
122 if (myDestinationStop != nullptr) {
124 if (myDestinationStop->getMyName() != "") {
125 comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
126 }
127 } else {
128 // lane index is arbitrary
129 os.writeAttr(SUMO_ATTR_LANE, getDestination()->getID() + "_0");
131 }
132 if (myWaitingDuration >= 0) {
134 }
135 if (myWaitingUntil >= 0) {
137 }
138 if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
141 }
142 if (myActType != "") {
144 }
145 os.closeTag(comment);
146 }
147}
148
149
150void
152 MSTransportableControl& tc = (t->isPerson() ?
155 tc.abortWaiting(t);
157 tc.forceDeparture();
158 }
159}
160
161std::string
162MSStageWaiting::getStageDescription(const bool isPerson) const {
163 UNUSED_PARAMETER(isPerson);
164 if (myActType != "") {
165 return "waiting (" + myActType + ")";
166 } else {
167 return "waiting";
168 }
169}
170
171std::string
172MSStageWaiting::getStageSummary(const bool /* isPerson */) const {
173 std::string timeInfo;
174 if (myWaitingUntil >= 0) {
175 timeInfo += " until " + time2string(myWaitingUntil);
176 }
177 if (myWaitingDuration >= 0) {
178 timeInfo += " duration " + time2string(myWaitingDuration);
179 }
180 if (getDestinationStop() != nullptr) {
181 std::string nameMsg = "";
182 if (getDestinationStop()->getMyName() != "") {
183 nameMsg = "(" + getDestinationStop()->getMyName() + ") ";
184 }
185 return "stopping at stop '" + getDestinationStop()->getID() + "' " + nameMsg + timeInfo + " (" + myActType + ")";
186 }
187 return "stopping at edge '" + getDestination()->getID() + "' " + timeInfo + " (" + myActType + ")";
188}
189
190void
191MSStageWaiting::saveState(std::ostringstream& out) {
192 out << " " << myDeparted;
193}
194
195void
196MSStageWaiting::loadState(MSTransportable* transportable, std::istringstream& state) {
197 state >> myDeparted;
199 if (myDestinationStop != nullptr) {
200 myDestinationStop->addTransportable(transportable);
202 }
203 if (myDeparted >= 0) {
204 myDestination->addTransportable(transportable);
205 MSNet* net = MSNet::getInstance();
206 if (transportable->isPerson()) {
207 net->getPersonControl().setWaitEnd(until, transportable);
208 } else {
209 net->getContainerControl().setWaitEnd(until, transportable);
210 }
211 }
212}
213
long long int SUMOTime
Definition: GUI.h:36
MSStageType
Definition: MSStage.h:54
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
@ 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_UNTIL
@ SUMO_ATTR_DURATION
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MAX3(T a, T b, T c)
Definition: StdDefs.h:91
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:1085
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition: MSGlobals.h:168
The simulated network and simulation perfomer.
Definition: MSNet.h:88
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1105
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1096
const MSEdge * getDestination() const
returns the destination edge
Definition: MSStage.cpp:61
virtual double getArrivalPos() const
Definition: MSStage.h:89
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:238
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:80
SUMOTime myArrived
the time at which this stage ended
Definition: MSStage.h:247
MSStageType myType
The type of this stage.
Definition: MSStage.h:250
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
Definition: MSStage.cpp:149
virtual const MSEdge * getEdge() const
Returns the current edge.
Definition: MSStage.cpp:67
static const double ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
Definition: MSStage.h:259
double myArrivalPos
the position at which we want to arrive
Definition: MSStage.h:241
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
Definition: MSStage.cpp:138
const MSEdge * myDestination
the next edge to reach by getting transported
Definition: MSStage.h:235
SUMOTime myDeparted
the time at which this stage started
Definition: MSStage.h:244
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
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
MSStageWaiting(const MSEdge *destination, MSStoppingPlace *toStop, SUMOTime duration, SUMOTime until, double pos, const std::string &actType, const bool initial)
constructor
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
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.
Definition: OptionsCont.cpp:59
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
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:298
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 M_PI
Definition: odrSpiral.cpp:45