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-2026 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/MSStop.h>
29#include <microsim/MSGlobals.h>
35#include "MSStopOut.h"
36
37
38// ---------------------------------------------------------------------------
39// static initialisation methods
40// ---------------------------------------------------------------------------
42
43void
45 if (OptionsCont::getOptions().isSet("stop-output")) {
47 }
48}
49
50void
52 delete myInstance;
53 myInstance = nullptr;
54}
55
56// ===========================================================================
57// method definitions
58// ===========================================================================
60 myDevice(dev) {
61}
62
64
65
66void
68 assert(veh != nullptr);
69 if (myStopped.count(veh) == 0) {
70 myStopped.emplace(veh, StopInfo(-time, -1, -1));
71 }
72}
73
74
75void
77 assert(veh != nullptr);
78 myStopped.erase(veh);
79}
80
81
82void
83MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
84 assert(veh != nullptr);
85 if (myStopped.count(veh) == 0) {
86 myStopped.emplace(veh, StopInfo(0, numPersons, numContainers));
87 } else {
88 MSStopOut::StopInfo& info = myStopped.find(veh)->second;
89 info.blockTime += time;
90 info.initialNumPersons = numPersons;
91 info.initialNumContainers = numContainers;
92 }
93}
94
95
96void
98 // ignore triggered vehicles
99 if (veh->hasDeparted()) {
100 if (myStopped.count(veh) == 0) {
101 WRITE_WARNINGF(TL("Vehicle '%' loads persons on edge '%', time=% without starting the stop."),
102 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
103 } else {
104 myStopped.find(veh)->second.loadedPersons += n;
105 }
106 }
107}
108
109
110void
112 if (myStopped.count(veh) == 0) {
113 WRITE_WARNINGF(TL("Vehicle '%' unloads persons on edge '%', time=% without starting the stop."),
114 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
115 } else {
116 myStopped.find(veh)->second.unloadedPersons += n;
117 }
118}
119
120
121void
123 // ignore triggered vehicles
124 if (veh->hasDeparted()) {
125 if (myStopped.count(veh) == 0) {
126 WRITE_WARNINGF(TL("Vehicle '%' loads container on edge '%', time=% without starting the stop."),
127 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
128 } else {
129 myStopped.find(veh)->second.loadedContainers += n;
130 }
131 }
132}
133
134
135void
137 if (myStopped.count(veh) == 0) {
138 WRITE_WARNINGF(TL("Vehicle '%' unloads container on edge '%', time=% without starting the stop."),
139 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
140 } else {
141 myStopped.find(veh)->second.unloadedContainers += n;
142 }
143}
144
145
146void
147MSStopOut::stopEnded(const SUMOVehicle* veh, const MSStop& stop, bool simEnd) {
148 assert(veh != nullptr);
149 if (myStopped.count(veh) == 0) {
150 WRITE_WARNINGF(TL("Vehicle '%' ends stop on edge '%', time=% without entering the stop."),
151 veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
152 return;
153 }
154 const SUMOVehicleParameter::Stop& pars = stop.pars;
155 const StopInfo& si = myStopped.find(veh)->second;
156 double delay = -1;
157 double arrivalDelay = -1;
158 if (pars.until >= 0 && !simEnd) {
159 delay = STEPS2TIME(SIMSTEP - pars.until);
160 }
161 if (pars.arrival >= 0) {
162 arrivalDelay = STEPS2TIME(pars.started - pars.arrival);
163 }
164 myDevice.openTag("stopinfo");
169 } else {
171 }
176 if (pars.until >= 0) {
177 myDevice.writeAttr("delay", delay);
178 }
179 if (pars.arrival >= 0) {
181 }
182 if (pars.busstop != "") {
184 }
185 if (pars.containerstop != "") {
187 }
188 if (pars.parkingarea != "") {
190 }
191 if (pars.chargingStation != "") {
193 }
194 if (pars.overheadWireSegment != "") {
196 }
197 if (pars.tripId != "") {
199 }
200 if (pars.line != "") {
202 }
203 if (pars.split != "") {
205 }
208 }
209 myDevice.writeAttr("initialPersons", si.initialNumPersons);
210 myDevice.writeAttr("loadedPersons", si.loadedPersons);
211 myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
212 myDevice.writeAttr("initialContainers", si.initialNumContainers);
213 myDevice.writeAttr("loadedContainers", si.loadedContainers);
214 myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
215 myDevice.writeAttr("blockedDuration", time2string(si.blockTime));
216
217 if (stop.pars.speed > 0) {
218 if (stop.waypointWithStop) {
219 myDevice.writeAttr(SUMO_ATTR_STATE, "waypointStopped");
220 } else {
222 }
223 } else if (stop.skipOnDemand) {
224 myDevice.writeAttr(SUMO_ATTR_STATE, "skippedOnDemand");
225 }
226
228 myStopped.erase(veh);
229}
230
231
232void
234 while (!myStopped.empty()) {
235 const auto& item = *myStopped.begin();
236 const SUMOVehicle* veh = item.first;
237 assert(veh->isStopped());
238 const MSStop& stop = veh->getNextStop();
239 // erases item from myStopped
240 stopEnded(veh, stop, true);
241 }
242}
243
244
245/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:304
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:58
#define SIMSTEP
Definition SUMOTime.h:64
@ 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
@ SUMO_ATTR_STATE
The state of a link.
static bool gUseMesoSim
Definition MSGlobals.h:106
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition MSGlobals.h:133
const MSLane * lane
The lane to stop at (microsim only)
Definition MSStop.h:50
bool skipOnDemand
whether the decision to skip this stop has been made
Definition MSStop.h:89
bool waypointWithStop
whehther the vehicle stopped despite having a waypoing
Definition MSStop.h:93
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
Realises dumping the complete network state.
Definition MSStopOut.h:48
virtual ~MSStopOut()
Destructor.
Definition MSStopOut.cpp:63
void stopBlocked(const SUMOVehicle *veh, SUMOTime time)
Definition MSStopOut.cpp:67
void loadedContainers(const SUMOVehicle *veh, int n)
static void init()
Static intialization.
Definition MSStopOut.cpp:44
MSStopOut(OutputDevice &dev)
constructor.
Definition MSStopOut.cpp:59
std::map< const SUMOVehicle *, StopInfo, ComparatorNumericalIdLess > myStopped
Definition MSStopOut.h:108
void stopNotStarted(const SUMOVehicle *veh)
Definition MSStopOut.cpp:76
void unloadedPersons(const SUMOVehicle *veh, int n)
static void cleanup()
Definition MSStopOut.cpp:51
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition MSStopOut.cpp:83
void generateOutputForUnfinished()
generate output for vehicles which are still stopped at simulation end
void unloadedContainers(const SUMOVehicle *veh, int n)
void stopEnded(const SUMOVehicle *veh, const MSStop &stop, bool simEnd=false)
static MSStopOut * myInstance
Definition MSStopOut.h:112
OutputDevice & myDevice
Definition MSStopOut.h:110
void loadedPersons(const SUMOVehicle *veh, int n)
Definition MSStopOut.cpp:97
const std::string & getID() const
Returns the name of the vehicle type.
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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 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:63
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop and waiting for a person or container to continue.
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual const MSStop & getNextStop() const =0
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
double speed
the speed at which this stop counts as reached (waypoint mode)
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.