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-2020 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/MSGlobals.h>
28 #include <microsim/MSParkingArea.h>
30 #include <microsim/MSVehicleType.h>
33 #include "MSStopOut.h"
34 
35 
36 // ---------------------------------------------------------------------------
37 // static initialisation methods
38 // ---------------------------------------------------------------------------
40 
41 void
43  if (OptionsCont::getOptions().isSet("stop-output")) {
45  }
46 }
47 
48 void
50  delete myInstance;
51  myInstance = nullptr;
52 }
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  myDevice(dev) {
59 }
60 
62 
63 
64 void
65 MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
66  assert(veh != nullptr);
67  if (myStopped.count(veh) != 0) {
68  WRITE_WARNING("Vehicle '" + veh->getID() + "' stops on edge '" + veh->getEdge()->getID()
69  + "', time " + time2string(time) + " without ending the previous stop.");
70  }
71  myStopped.emplace(veh, StopInfo(numPersons, numContainers));
72 }
73 
74 void
76  // ignore triggered vehicles
77  if (veh->hasDeparted()) {
78  myStopped.find(veh)->second.loadedPersons += n;
79  }
80 }
81 
82 void
84  myStopped.find(veh)->second.unloadedPersons += n;
85 }
86 
87 void
89  myStopped.find(veh)->second.loadedContainers += n;
90 }
91 
92 void
94  myStopped.find(veh)->second.unloadedContainers += n;
95 }
96 
97 void
98 MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID) {
99  assert(veh != nullptr);
100  if (myStopped.count(veh) == 0) {
101  WRITE_WARNING("Vehicle '" + veh->getID() + "' ends stop on edge '" + veh->getEdge()->getID()
102  + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + " without entering the stop");
103  return;
104  }
105  const StopInfo& si = myStopped.find(veh)->second;
106  double delay = -1;
107  double arrivalDelay = -1;
108  if (stop.until >= 0) {
109  delay = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - stop.until);
110  }
111  if (stop.arrival >= 0) {
112  arrivalDelay = STEPS2TIME(stop.actualArrival - stop.arrival);
113  }
114  myDevice.openTag("stopinfo");
118  myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
119  } else {
120  myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
121  }
124  myDevice.writeAttr("started", time2string(stop.actualArrival));
125  myDevice.writeAttr("ended", time2string(MSNet::getInstance()->getCurrentTimeStep()));
126  myDevice.writeAttr("delay", delay);
127  if (stop.arrival >= 0) {
128  myDevice.writeAttr("arrivalDelay", arrivalDelay);
129  }
130  myDevice.writeAttr("initialPersons", si.initialNumPersons);
131  myDevice.writeAttr("loadedPersons", si.loadedPersons);
132  myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
133  myDevice.writeAttr("initialContainers", si.initialNumContainers);
134  myDevice.writeAttr("loadedContainers", si.loadedContainers);
135  myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
136  if (stop.busstop != "") {
138  }
139  if (stop.containerstop != "") {
141  }
142  if (stop.parkingarea != "") {
144  }
145  if (stop.chargingStation != "") {
147  }
148  if (stop.overheadWireSegment != "") {
150  }
151  if (stop.tripId != "") {
153  }
154  if (stop.line != "") {
156  }
157  if (stop.split != "") {
159  }
160  myDevice.closeTag();
161  myStopped.erase(veh);
162 }
163 
164 
165 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:31
@ 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:88
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
Realises dumping the complete network state.
Definition: MSStopOut.h:47
virtual ~MSStopOut()
Destructor.
Definition: MSStopOut.cpp:61
void loadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:88
static void init()
Static intialization.
Definition: MSStopOut.cpp:42
MSStopOut(OutputDevice &dev)
constructor.
Definition: MSStopOut.cpp:57
std::map< const SUMOVehicle *, StopInfo > myStopped
Definition: MSStopOut.h:101
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID)
Definition: MSStopOut.cpp:98
void unloadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:83
static void cleanup()
Definition: MSStopOut.cpp:49
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition: MSStopOut.cpp:65
void unloadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:93
static MSStopOut * myInstance
Definition: MSStopOut.h:105
OutputDevice & myDevice
Definition: MSStopOut.h:103
void loadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:75
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
const std::string & getID() const
Returns the id.
Definition: Named.h:73
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
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:239
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:58
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
Definition of vehicle stop (position and duration)
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 actualArrival
the time at which this stop was reached
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.