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.org/sumo
3 // Copyright (C) 2001-2022 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("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  myStopped.find(veh)->second.loadedPersons += n;
80  }
81 }
82 
83 void
85  myStopped.find(veh)->second.unloadedPersons += n;
86 }
87 
88 void
90  // ignore triggered vehicles
91  if (veh->hasDeparted()) {
92  myStopped.find(veh)->second.loadedContainers += n;
93  }
94 }
95 
96 void
98  myStopped.find(veh)->second.unloadedContainers += n;
99 }
100 
101 void
102 MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID, bool simEnd) {
103  assert(veh != nullptr);
104  if (myStopped.count(veh) == 0) {
105  WRITE_WARNINGF("Vehicle '%' ends stop on edge '%', time=% without entering the stop.",
106  veh->getID(), veh->getEdge()->getID(), time2string(SIMSTEP));
107  return;
108  }
109  const StopInfo& si = myStopped.find(veh)->second;
110  double delay = -1;
111  double arrivalDelay = -1;
112  if (stop.until >= 0 && !simEnd) {
113  delay = STEPS2TIME(SIMSTEP - stop.until);
114  }
115  if (stop.arrival >= 0) {
116  arrivalDelay = STEPS2TIME(stop.started - stop.arrival);
117  }
118  myDevice.openTag("stopinfo");
122  myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
123  } else {
124  myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
125  }
128  myDevice.writeAttr("started", time2string(stop.started));
129  myDevice.writeAttr("ended", simEnd ? "-1" : time2string(SIMSTEP));
130  myDevice.writeAttr("delay", delay);
131  if (stop.arrival >= 0) {
132  myDevice.writeAttr("arrivalDelay", arrivalDelay);
133  }
134  myDevice.writeAttr("initialPersons", si.initialNumPersons);
135  myDevice.writeAttr("loadedPersons", si.loadedPersons);
136  myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
137  myDevice.writeAttr("initialContainers", si.initialNumContainers);
138  myDevice.writeAttr("loadedContainers", si.loadedContainers);
139  myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
140  if (stop.busstop != "") {
142  }
143  if (stop.containerstop != "") {
145  }
146  if (stop.parkingarea != "") {
148  }
149  if (stop.chargingStation != "") {
151  }
152  if (stop.overheadWireSegment != "") {
154  }
155  if (stop.tripId != "") {
157  }
158  if (stop.line != "") {
160  }
161  if (stop.split != "") {
163  }
164  myDevice.closeTag();
165  myStopped.erase(veh);
166 }
167 
168 void
170  while (!myStopped.empty()) {
171  const auto& item = *myStopped.begin();
172  const SUMOVehicle* veh = item.first;
174  assert(stop != nullptr);
175  const std::string laneOrEdgeID = MSGlobals::gUseMesoSim ? veh->getEdge()->getID() : Named::getIDSecure(veh->getLane());
176  // erases item from myStopped
177  stopEnded(veh, *stop, laneOrEdgeID, true);
178  }
179 }
180 
181 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:281
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define SIMSTEP
Definition: SUMOTime.h:59
long long int SUMOTime
Definition: SUMOTime.h:32
@ SUMO_ATTR_PARKING
@ SUMO_ATTR_LANE
@ 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_OVERHEAD_WIRE_SEGMENT
@ SUMO_ATTR_TRIP_ID
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
static bool gUseMesoSim
Definition: MSGlobals.h:94
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:89
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:84
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:169
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID, bool simEnd=false)
Definition: MSStopOut.cpp:102
void unloadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:97
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:90
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:58
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:248
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:60
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
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.
bool parking
whether the vehicle is removed from the net while stopping
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.