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-2023 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
66MSStopOut::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
75void
77 // ignore triggered vehicles
78 if (veh->hasDeparted()) {
79 myStopped.find(veh)->second.loadedPersons += n;
80 }
81}
82
83void
85 myStopped.find(veh)->second.unloadedPersons += n;
86}
87
88void
90 // ignore triggered vehicles
91 if (veh->hasDeparted()) {
92 myStopped.find(veh)->second.loadedContainers += n;
93 }
94}
95
96void
98 myStopped.find(veh)->second.unloadedContainers += n;
99}
100
101void
102MSStopOut::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(TL("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 }
130 if (stop.until >= 0) {
131 myDevice.writeAttr("delay", delay);
132 }
133 if (stop.arrival >= 0) {
134 myDevice.writeAttr("arrivalDelay", arrivalDelay);
135 }
136 myDevice.writeAttr("initialPersons", si.initialNumPersons);
137 myDevice.writeAttr("loadedPersons", si.loadedPersons);
138 myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
139 myDevice.writeAttr("initialContainers", si.initialNumContainers);
140 myDevice.writeAttr("loadedContainers", si.loadedContainers);
141 myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
142 if (stop.busstop != "") {
144 }
145 if (stop.containerstop != "") {
147 }
148 if (stop.parkingarea != "") {
150 }
151 if (stop.chargingStation != "") {
153 }
154 if (stop.overheadWireSegment != "") {
156 }
157 if (stop.tripId != "") {
159 }
160 if (stop.line != "") {
162 }
163 if (stop.split != "") {
165 }
168 }
170 myStopped.erase(veh);
171}
172
173void
175 while (!myStopped.empty()) {
176 const auto& item = *myStopped.begin();
177 const SUMOVehicle* veh = item.first;
179 assert(stop != nullptr);
180 const std::string laneOrEdgeID = MSGlobals::gUseMesoSim ? veh->getEdge()->getID() : Named::getIDSecure(veh->getLane());
181 // erases item from myStopped
182 stopEnded(veh, *stop, laneOrEdgeID, true);
183 }
184}
185
186/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:271
#define TL(string)
Definition MsgHandler.h:287
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_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: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
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID, bool simEnd=false)
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.
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.