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.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 /****************************************************************************/
21 // An stage for planned waiting (stopping)
22 /****************************************************************************/
23 #include <config.h>
24 
26 #include <utils/geom/GeomHelper.h>
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) :
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  myStopEndTime(-1) {
50 }
51 
52 
54 
55 MSStage*
59  clon->setParameters(*this);
60  return clon;
61 }
62 
65  return myWaitingUntil;
66 }
67 
70  return myWaitingDuration;
71 }
72 
76 }
77 
81  return myStopWaitPos;
82  }
85 }
86 
87 
88 double
91 }
92 
93 
94 void
95 MSStageWaiting::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
96  myDeparted = now;
98  if (myDestinationStop != nullptr) {
99  myDestinationStop->addTransportable(transportable);
101  }
102 
103  previous->getEdge()->addTransportable(transportable);
104  if (transportable->isPerson()) {
105  net->getPersonControl().setWaitEnd(myStopEndTime, transportable);
106  } else {
107  net->getContainerControl().setWaitEnd(myStopEndTime, transportable);
108  }
109 }
110 
111 
112 void
116  os.writeAttr("duration", getDuration() != SUMOTime_MAX ? time2string(getDuration()) : "-1");
117  os.writeAttr("arrival", time2string(myArrived));
118  os.writeAttr("arrivalPos", toString(myArrivalPos));
119  os.writeAttr("actType", myActType == "" ? "waiting" : myActType);
120  os.closeTag();
121  }
122 }
123 
124 
125 void
126 MSStageWaiting::routeOutput(const bool /* isPerson */, OutputDevice& os, const bool, const MSStage* const /* previous */) const {
129  std::string comment = "";
130  if (myDestinationStop != nullptr) {
132  if (myDestinationStop->getMyName() != "") {
133  comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
134  }
135  } else {
136  // lane index is arbitrary
137  os.writeAttr(SUMO_ATTR_LANE, getDestination()->getID() + "_0");
139  }
140  if (myWaitingDuration >= 0) {
142  }
143  if (myWaitingUntil >= 0) {
145  }
146  if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
149  }
150  if (myActType != "") {
152  }
153  // Write rest of parameters
154  writeParams(os);
155  os.closeTag(comment);
156  }
157 }
158 
159 
160 void
162  MSTransportableControl& tc = (t->isPerson() ?
165  tc.abortWaiting(t);
167  tc.forceDeparture();
168  }
169 }
170 
171 std::string
172 MSStageWaiting::getStageDescription(const bool isPerson) const {
173  UNUSED_PARAMETER(isPerson);
174  if (myActType != "") {
175  return "waiting (" + myActType + ")";
176  } else {
177  return "waiting";
178  }
179 }
180 
181 std::string
182 MSStageWaiting::getStageSummary(const bool /* isPerson */) const {
183  std::string timeInfo;
184  if (myWaitingUntil >= 0) {
185  timeInfo += " until " + time2string(myWaitingUntil);
186  }
187  if (myWaitingDuration >= 0) {
188  timeInfo += " duration " + time2string(myWaitingDuration);
189  }
190  if (getDestinationStop() != nullptr) {
191  std::string nameMsg = "";
192  if (getDestinationStop()->getMyName() != "") {
193  nameMsg = "(" + getDestinationStop()->getMyName() + ") ";
194  }
195  return "stopping at stop '" + getDestinationStop()->getID() + "' " + nameMsg + timeInfo + " (" + myActType + ")";
196  }
197  return "stopping at edge '" + getDestination()->getID() + "' " + timeInfo + " (" + myActType + ")";
198 }
199 
200 void
201 MSStageWaiting::saveState(std::ostringstream& out) {
202  out << " " << myDeparted;
203 }
204 
205 void
206 MSStageWaiting::loadState(MSTransportable* transportable, std::istringstream& state) {
207  state >> myDeparted;
209  if (myDestinationStop != nullptr) {
210  myDestinationStop->addTransportable(transportable);
212  }
213  if (myDeparted >= 0) {
214  myDestination->addTransportable(transportable);
215  MSNet* net = MSNet::getInstance();
216  if (transportable->isPerson()) {
217  net->getPersonControl().setWaitEnd(until, transportable);
218  } else {
219  net->getContainerControl().setWaitEnd(until, transportable);
220  }
221  }
222 }
long long int SUMOTime
Definition: GUI.h:35
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
#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_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:1124
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition: MSGlobals.h:169
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:182
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1182
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1173
const MSEdge * getDestination() const
returns the destination edge
Definition: MSStage.cpp:65
virtual double getArrivalPos() const
Definition: MSStage.h:93
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:272
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:84
virtual SUMOTime getDuration() const
Definition: MSStage.cpp:139
SUMOTime myArrived
the time at which this stage ended
Definition: MSStage.h:284
MSStageType myType
The type of this stage.
Definition: MSStage.h:287
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
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
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:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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:317
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