Eclipse SUMO - Simulation of Urban MObility
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-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 /****************************************************************************/
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>
29 #include <microsim/MSParkingArea.h>
31 #include <microsim/MSVehicleType.h>
34 #include "MSStopOut.h"
35 
36 
37 // ---------------------------------------------------------------------------
38 // static initialisation methods
39 // ---------------------------------------------------------------------------
41 
42 void
44  if (OptionsCont::getOptions().isSet("stop-output")) {
46  }
47 }
48 
49 void
51  delete myInstance;
52  myInstance = nullptr;
53 }
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
59  myDevice(dev) {
60 }
61 
63 
64 
65 void
66 MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
67  assert(veh != nullptr);
68  if (myStopped.count(veh) != 0) {
69  WRITE_WARNINGF(TL("Vehicle '%' stops on edge '%', time=% without ending the previous stop."),
70  veh->getID(), veh->getEdge()->getID(), time2string(time));
71  }
72  myStopped.emplace(veh, StopInfo(numPersons, numContainers));
73 }
74 
75 void
77  // ignore triggered vehicles
78  if (veh->hasDeparted()) {
79  if (myStopped.count(veh) == 0) {
80  WRITE_WARNINGF(TL("Vehicle '%' loads persons on edge '%', time=% without starting the stop."),
81  veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
82  } else {
83  myStopped.find(veh)->second.loadedPersons += n;
84  }
85  }
86 }
87 
88 void
90  if (myStopped.count(veh) == 0) {
91  WRITE_WARNINGF(TL("Vehicle '%' unloads persons on edge '%', time=% without starting the stop."),
92  veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
93  } else {
94  myStopped.find(veh)->second.unloadedPersons += n;
95  }
96 }
97 
98 void
100  // ignore triggered vehicles
101  if (veh->hasDeparted()) {
102  if (myStopped.count(veh) == 0) {
103  WRITE_WARNINGF(TL("Vehicle '%' loads container on edge '%', time=% without starting the stop."),
104  veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
105  } else {
106  myStopped.find(veh)->second.loadedContainers += n;
107  }
108  }
109 }
110 
111 void
113  if (myStopped.count(veh) == 0) {
114  WRITE_WARNINGF(TL("Vehicle '%' unloads container on edge '%', time=% without starting the stop."),
115  veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
116  } else {
117  myStopped.find(veh)->second.unloadedContainers += n;
118  }
119 }
120 
121 void
122 MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID, bool simEnd) {
123  assert(veh != nullptr);
124  if (myStopped.count(veh) == 0) {
125  WRITE_WARNINGF(TL("Vehicle '%' ends stop on edge '%', time=% without entering the stop."),
126  veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
127  return;
128  }
129  const StopInfo& si = myStopped.find(veh)->second;
130  double delay = -1;
131  double arrivalDelay = -1;
132  if (stop.until >= 0 && !simEnd) {
133  delay = STEPS2TIME(SIMSTEP - stop.until);
134  }
135  if (stop.arrival >= 0) {
136  arrivalDelay = STEPS2TIME(stop.started - stop.arrival);
137  }
138  myDevice.openTag("stopinfo");
142  myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
143  } else {
144  myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
145  }
150  if (stop.until >= 0) {
151  myDevice.writeAttr("delay", delay);
152  }
153  if (stop.arrival >= 0) {
155  }
156  if (stop.busstop != "") {
158  }
159  if (stop.containerstop != "") {
161  }
162  if (stop.parkingarea != "") {
164  }
165  if (stop.chargingStation != "") {
167  }
168  if (stop.overheadWireSegment != "") {
170  }
171  if (stop.tripId != "") {
173  }
174  if (stop.line != "") {
176  }
177  if (stop.split != "") {
179  }
182  }
183  myDevice.writeAttr("initialPersons", si.initialNumPersons);
184  myDevice.writeAttr("loadedPersons", si.loadedPersons);
185  myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
186  myDevice.writeAttr("initialContainers", si.initialNumContainers);
187  myDevice.writeAttr("loadedContainers", si.loadedContainers);
188  myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
189  myDevice.closeTag();
190  myStopped.erase(veh);
191 }
192 
193 void
195  while (!myStopped.empty()) {
196  const auto& item = *myStopped.begin();
197  const SUMOVehicle* veh = item.first;
199  assert(stop != nullptr);
200  const std::string laneOrEdgeID = MSGlobals::gUseMesoSim ? veh->getEdge()->getID() : Named::getIDSecure(veh->getLane());
201  // erases item from myStopped
202  stopEnded(veh, *stop, laneOrEdgeID, true);
203  }
204 }
205 
206 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#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:103
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition: MSGlobals.h:130
Realises dumping the complete network state.
Definition: MSStopOut.h:47
virtual ~MSStopOut()
Destructor.
Definition: MSStopOut.cpp:62
void loadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:99
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:103
void unloadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:89
static void cleanup()
Definition: MSStopOut.cpp:50
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition: MSStopOut.cpp:66
void generateOutputForUnfinished()
generate output for vehicles which are still stopped at simulation end
Definition: MSStopOut.cpp:194
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID, bool simEnd=false)
Definition: MSStopOut.cpp:122
void unloadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:112
static MSStopOut * myInstance
Definition: MSStopOut.h:107
OutputDevice & myDevice
Definition: MSStopOut.h:105
void loadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:76
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
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.
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
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.