Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSStopOut.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/****************************************************************************/
18// Ouput information about planned vehicle stop
19/****************************************************************************/
20#include <config.h>
21
25#include <microsim/MSNet.h>
26#include <microsim/MSEdge.h>
27#include <microsim/MSLane.h>
28#include <microsim/MSGlobals.h>
34#include "MSStopOut.h"
35
36
37// ---------------------------------------------------------------------------
38// static initialisation methods
39// ---------------------------------------------------------------------------
41
42void
44 if (OptionsCont::getOptions().isSet("stop-output")) {
46 }
47}
48
49void
51 delete myInstance;
52 myInstance = nullptr;
53}
54
55// ===========================================================================
56// method definitions
57// ===========================================================================
59 myDevice(dev) {
60}
61
63
64
65void
67 assert(veh != nullptr);
68 if (myStopped.count(veh) == 0) {
69 myStopped.emplace(veh, StopInfo(-time, -1, -1));
70 }
71}
72
73
74void
76 assert(veh != nullptr);
77 myStopped.erase(veh);
78}
79
80
81void
82MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
83 assert(veh != nullptr);
84 if (myStopped.count(veh) == 0) {
85 myStopped.emplace(veh, StopInfo(0, numPersons, numContainers));
86 } else {
87 MSStopOut::StopInfo& info = myStopped.find(veh)->second;
88 info.blockTime += time;
89 info.initialNumPersons = numPersons;
90 info.initialNumContainers = numContainers;
91 }
92}
93
94
95void
97 // ignore triggered vehicles
98 if (veh->hasDeparted()) {
99 if (myStopped.count(veh) == 0) {
100 WRITE_WARNINGF(TL("Vehicle '%' loads persons on edge '%', time=% without starting the stop."),
101 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
102 } else {
103 myStopped.find(veh)->second.loadedPersons += n;
104 }
105 }
106}
107
108
109void
111 if (myStopped.count(veh) == 0) {
112 WRITE_WARNINGF(TL("Vehicle '%' unloads persons on edge '%', time=% without starting the stop."),
113 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
114 } else {
115 myStopped.find(veh)->second.unloadedPersons += n;
116 }
117}
118
119
120void
122 // ignore triggered vehicles
123 if (veh->hasDeparted()) {
124 if (myStopped.count(veh) == 0) {
125 WRITE_WARNINGF(TL("Vehicle '%' loads container on edge '%', time=% without starting the stop."),
126 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
127 } else {
128 myStopped.find(veh)->second.loadedContainers += n;
129 }
130 }
131}
132
133
134void
136 if (myStopped.count(veh) == 0) {
137 WRITE_WARNINGF(TL("Vehicle '%' unloads container on edge '%', time=% without starting the stop."),
138 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
139 } else {
140 myStopped.find(veh)->second.unloadedContainers += n;
141 }
142}
143
144
145void
146MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID, bool simEnd) {
147 assert(veh != nullptr);
148 if (myStopped.count(veh) == 0) {
149 WRITE_WARNINGF(TL("Vehicle '%' ends stop on edge '%', time=% without entering the stop."),
150 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
151 return;
152 }
153 const StopInfo& si = myStopped.find(veh)->second;
154 double delay = -1;
155 double arrivalDelay = -1;
156 if (stop.until >= 0 && !simEnd) {
157 delay = STEPS2TIME(SIMSTEP - stop.until);
158 }
159 if (stop.arrival >= 0) {
160 arrivalDelay = STEPS2TIME(stop.started - stop.arrival);
161 }
162 myDevice.openTag("stopinfo");
166 myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
167 } else {
168 myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
169 }
174 if (stop.until >= 0) {
175 myDevice.writeAttr("delay", delay);
176 }
177 if (stop.arrival >= 0) {
179 }
180 if (stop.busstop != "") {
182 }
183 if (stop.containerstop != "") {
185 }
186 if (stop.parkingarea != "") {
188 }
189 if (stop.chargingStation != "") {
191 }
192 if (stop.overheadWireSegment != "") {
194 }
195 if (stop.tripId != "") {
197 }
198 if (stop.line != "") {
200 }
201 if (stop.split != "") {
203 }
206 }
207 myDevice.writeAttr("initialPersons", si.initialNumPersons);
208 myDevice.writeAttr("loadedPersons", si.loadedPersons);
209 myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
210 myDevice.writeAttr("initialContainers", si.initialNumContainers);
211 myDevice.writeAttr("loadedContainers", si.loadedContainers);
212 myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
213 myDevice.writeAttr("blockedDuration", time2string(si.blockTime));
215 myStopped.erase(veh);
216}
217
218
219void
221 while (!myStopped.empty()) {
222 const auto& item = *myStopped.begin();
223 const SUMOVehicle* veh = item.first;
225 assert(stop != nullptr);
226 const std::string laneOrEdgeID = MSGlobals::gUseMesoSim ? veh->getEdge()->getID() : Named::getIDSecure(veh->getLane());
227 // erases item from myStopped
228 stopEnded(veh, *stop, laneOrEdgeID, true);
229 }
230}
231
232
233/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:288
#define TL(string)
Definition MsgHandler.h:305
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define SIMSTEP
Definition SUMOTime.h:61
@ SUMO_ATTR_PARKING
@ SUMO_ATTR_LANE
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_CONTAINER_STOP
@ SUMO_ATTR_PARKING_AREA
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_BUS_STOP
@ SUMO_ATTR_SPLIT
@ SUMO_ATTR_LINE
@ SUMO_ATTR_CHARGING_STATION
@ SUMO_ATTR_USED_ENDED
@ SUMO_ATTR_OVERHEAD_WIRE_SEGMENT
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_ARRIVALDELAY
@ SUMO_ATTR_TRIP_ID
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
static bool gUseMesoSim
Definition MSGlobals.h:106
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition MSGlobals.h:133
Realises dumping the complete network state.
Definition MSStopOut.h:47
virtual ~MSStopOut()
Destructor.
Definition MSStopOut.cpp:62
void stopBlocked(const SUMOVehicle *veh, SUMOTime time)
Definition MSStopOut.cpp:66
void loadedContainers(const SUMOVehicle *veh, int n)
static void init()
Static intialization.
Definition MSStopOut.cpp:43
MSStopOut(OutputDevice &dev)
constructor.
Definition MSStopOut.cpp:58
std::map< const SUMOVehicle *, StopInfo, ComparatorNumericalIdLess > myStopped
Definition MSStopOut.h:107
void stopNotStarted(const SUMOVehicle *veh)
Definition MSStopOut.cpp:75
void unloadedPersons(const SUMOVehicle *veh, int n)
static void cleanup()
Definition MSStopOut.cpp:50
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition MSStopOut.cpp:82
void generateOutputForUnfinished()
generate output for vehicles which are still stopped at simulation end
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID, bool simEnd=false)
void unloadedContainers(const SUMOVehicle *veh, int n)
static MSStopOut * myInstance
Definition MSStopOut.h:111
OutputDevice & myDevice
Definition MSStopOut.h:109
void loadedPersons(const SUMOVehicle *veh, int n)
Definition MSStopOut.cpp:96
const std::string & getID() const
Returns the name of the vehicle type.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:67
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.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual const SUMOVehicleParameter::Stop * getNextStopParameter() const =0
Returns parameters of the next stop or nullptr.
Definition of vehicle stop (position and duration)
SUMOTime started
the time at which this stop was reached
ParkingType parking
whether the vehicle is removed from the net while stopping
std::string parkingarea
(Optional) parking area if one is assigned to the stop
std::string split
the id of the vehicle (train portion) that splits of upon reaching this stop
std::string line
the new line id of the trip within a cyclical public transport route
std::string chargingStation
(Optional) charging station if one is assigned to the stop
std::string overheadWireSegment
(Optional) overhead line segment if one is assigned to the stop
SUMOTime until
The time at which the vehicle may continue its journey.
SUMOTime ended
the time at which this stop was ended
std::string busstop
(Optional) bus stop if one is assigned to the stop
std::string tripId
id of the trip within a cyclical public transport route
std::string containerstop
(Optional) container stop if one is assigned to the stop
SUMOTime arrival
The (expected) time at which the vehicle reaches the stop.