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-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// 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
58
63
68
69
78
79
80double
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 // Write rest of parameters
146 writeParams(os);
147 os.closeTag(comment);
148 }
149}
150
151
152void
162
163std::string
164MSStageWaiting::getStageDescription(const bool isPerson) const {
165 UNUSED_PARAMETER(isPerson);
166 if (myActType != "") {
167 return "waiting (" + myActType + ")";
168 } else {
169 return "waiting";
170 }
171}
172
173std::string
174MSStageWaiting::getStageSummary(const bool /* isPerson */) const {
175 std::string timeInfo;
176 if (myWaitingUntil >= 0) {
177 timeInfo += " until " + time2string(myWaitingUntil);
178 }
179 if (myWaitingDuration >= 0) {
180 timeInfo += " duration " + time2string(myWaitingDuration);
181 }
182 if (getDestinationStop() != nullptr) {
183 std::string nameMsg = "";
184 if (getDestinationStop()->getMyName() != "") {
185 nameMsg = "(" + getDestinationStop()->getMyName() + ") ";
186 }
187 return "stopping at stop '" + getDestinationStop()->getID() + "' " + nameMsg + timeInfo + " (" + myActType + ")";
188 }
189 return "stopping at edge '" + getDestination()->getID() + "' " + timeInfo + " (" + myActType + ")";
190}
191
192void
193MSStageWaiting::saveState(std::ostringstream& out) {
194 out << " " << myDeparted;
195}
196
197void
198MSStageWaiting::loadState(MSTransportable* transportable, std::istringstream& state) {
199 state >> myDeparted;
201 if (myDestinationStop != nullptr) {
202 myDestinationStop->addTransportable(transportable);
204 }
205 if (myDeparted >= 0) {
206 myDestination->addTransportable(transportable);
207 MSNet* net = MSNet::getInstance();
208 if (transportable->isPerson()) {
209 net->getPersonControl().setWaitEnd(until, transportable);
210 } else {
211 net->getContainerControl().setWaitEnd(until, transportable);
212 }
213 }
214}
215
long long int SUMOTime
Definition GUI.h:36
MSStageType
Definition MSStage.h:54
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
@ 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: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:1086
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition MSGlobals.h:169
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:1181
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1172
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.
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 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:300
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