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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // Ouput information about planned vehicle stop
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
26 #include <microsim/MSNet.h>
27 #include <microsim/MSEdge.h>
28 #include <microsim/MSParkingArea.h>
31 #include "MSStopOut.h"
32 
33 
34 // ---------------------------------------------------------------------------
35 // static initialisation methods
36 // ---------------------------------------------------------------------------
38 
39 void
41  if (OptionsCont::getOptions().isSet("stop-output")) {
43  }
44 }
45 
46 void
48  delete myInstance;
49  myInstance = nullptr;
50 }
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
56  myDevice(dev) {
57 }
58 
60 
61 
62 void
63 MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
64  assert(veh != 0);
65  if (myStopped.count(veh) != 0) {
66  WRITE_WARNING("Vehicle '" + veh->getID() + "' stops on edge '" + veh->getEdge()->getID()
67  + "', time " + time2string(time)
68  + " without ending the previous stop entered at time " + time2string(myStopped[veh].started));
69  }
70  StopInfo stopInfo(MSNet::getInstance()->getCurrentTimeStep(), numPersons, numContainers);
71  myStopped[veh] = stopInfo;
72 }
73 
74 void
76  // ignore triggered vehicles
77  if (veh->hasDeparted()) {
78  myStopped[veh].loadedPersons += n;
79  }
80 }
81 
82 void
84  myStopped[veh].unloadedPersons += n;
85 }
86 
87 void
89  myStopped[veh].loadedContainers += n;
90 }
91 
92 void
94  myStopped[veh].unloadedContainers += n;
95 }
96 
97 void
98 MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID) {
99  assert(veh != 0);
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  double delay = -1;
106  if (stop.until >= 0) {
107  delay = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - stop.until);
108  }
109  StopInfo& si = myStopped[veh];
110  myDevice.openTag("stopinfo");
114  myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
115  } else {
116  myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
117  }
120  myDevice.writeAttr("started", time2string(si.started));
121  myDevice.writeAttr("ended", time2string(MSNet::getInstance()->getCurrentTimeStep()));
122  myDevice.writeAttr("delay", delay);
123  myDevice.writeAttr("initialPersons", si.initialNumPersons);
124  myDevice.writeAttr("loadedPersons", si.loadedPersons);
125  myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
126  myDevice.writeAttr("initialContainers", si.initialNumContainers);
127  myDevice.writeAttr("loadedContainers", si.loadedContainers);
128  myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
129  if (stop.busstop != "") {
131  }
132  if (stop.containerstop != "") {
134  }
135  if (stop.parkingarea != "") {
137  }
138  if (stop.chargingStation != "") {
140  }
141  if (stop.tripId != "") {
143  }
144  if (stop.line != "") {
146  }
147  myDevice.closeTag();
148  myStopped.erase(veh);
149 }
150 
151 /****************************************************************************/
SUMO_ATTR_TYPE
@ SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
MSStopOut::unloadedContainers
void unloadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:93
MSStopOut.h
MSStopOut::MSStopOut
MSStopOut(OutputDevice &dev)
constructor.
Definition: MSStopOut.cpp:55
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MSNet.h
SUMO_ATTR_PARKING_AREA
@ SUMO_ATTR_PARKING_AREA
Definition: SUMOXMLDefinitions.h:771
SUMO_ATTR_CONTAINER_STOP
@ SUMO_ATTR_CONTAINER_STOP
Definition: SUMOXMLDefinitions.h:770
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
OptionsCont.h
SUMOTrafficObject::getEdge
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
SUMO_ATTR_LINE
@ SUMO_ATTR_LINE
Definition: SUMOXMLDefinitions.h:775
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
MsgHandler.h
MSStopOut::StopInfo::unloadedPersons
int unloadedPersons
Definition: MSStopOut.h:110
SUMOVehicleParameter::Stop::busstop
std::string busstop
(Optional) bus stop if one is assigned to the stop
Definition: SUMOVehicleParameter.h:589
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
SUMO_ATTR_EDGE
@ SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:423
MSStopOut::loadedPersons
void loadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:75
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
SUMOVehicleParameter::Stop::line
std::string line
the new line id of the trip within a cyclical public transport route
Definition: SUMOVehicleParameter.h:640
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:90
MSChargingStation.h
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
SUMOVehicleParameter::Stop::parkingarea
std::string parkingarea
(Optional) parking area if one is assigned to the stop
Definition: SUMOVehicleParameter.h:595
MSEdge.h
SUMO_ATTR_LANE
@ SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
SUMO_ATTR_CHARGING_STATION
@ SUMO_ATTR_CHARGING_STATION
Definition: SUMOXMLDefinitions.h:774
MSStopOut::loadedContainers
void loadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:88
MSStopOut
Realises dumping the complete network state.
Definition: MSStopOut.h:49
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MSStopOut::init
static void init()
Static intialization.
Definition: MSStopOut.cpp:40
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
SUMOVehicle.h
SUMO_ATTR_TRIP_ID
@ SUMO_ATTR_TRIP_ID
Definition: SUMOXMLDefinitions.h:777
MSStopOut::StopInfo::unloadedContainers
int unloadedContainers
Definition: MSStopOut.h:113
MSStopOut::cleanup
static void cleanup()
Definition: MSStopOut.cpp:47
SUMOVehicleParameter::Stop::tripId
std::string tripId
id of the trip within a cyclical public transport route
Definition: SUMOVehicleParameter.h:637
SUMOVehicleParameter::Stop::until
SUMOTime until
The time at which the vehicle may continue its journey.
Definition: SUMOVehicleParameter.h:610
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
MSStopOut::myDevice
OutputDevice & myDevice
Definition: MSStopOut.h:119
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSParkingArea.h
MSStopOut::StopInfo::loadedContainers
int loadedContainers
Definition: MSStopOut.h:112
MSStopOut::StopInfo::started
SUMOTime started
Definition: MSStopOut.h:107
MSStopOut::~MSStopOut
virtual ~MSStopOut()
Destructor.
Definition: MSStopOut.cpp:59
MSStopOut::myStopped
Stopped myStopped
Definition: MSStopOut.h:117
SUMO_ATTR_POSITION
@ SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
MSStopOut::myInstance
static MSStopOut * myInstance
Definition: MSStopOut.h:121
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
SUMOVehicle::hasDeparted
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
MSStopOut::StopInfo::initialNumContainers
int initialNumContainers
Definition: MSStopOut.h:111
MSStopOut::unloadedPersons
void unloadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:83
MSStopOut::stopStarted
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition: MSStopOut.cpp:63
SUMO_ATTR_PARKING
@ SUMO_ATTR_PARKING
Definition: SUMOXMLDefinitions.h:801
config.h
MSStopOut::StopInfo::initialNumPersons
int initialNumPersons
Definition: MSStopOut.h:108
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
SUMO_ATTR_BUS_STOP
@ SUMO_ATTR_BUS_STOP
Definition: SUMOXMLDefinitions.h:769
MSStopOut::stopEnded
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID)
Definition: MSStopOut.cpp:98
MSStopOut::StopInfo::loadedPersons
int loadedPersons
Definition: MSStopOut.h:109
MSStoppingPlace.h
SUMOVehicleParameter::Stop::parking
bool parking
whether the vehicle is removed from the net while stopping
Definition: SUMOVehicleParameter.h:622
SUMOVehicleParameter::Stop::chargingStation
std::string chargingStation
(Optional) charging station if one is assigned to the stop
Definition: SUMOVehicleParameter.h:598
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
SUMOVehicleParameter::Stop::containerstop
std::string containerstop
(Optional) container stop if one is assigned to the stop
Definition: SUMOVehicleParameter.h:592
OutputDevice::getDeviceByOption
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
Definition: OutputDevice.cpp:116
MSStopOut::StopInfo
Definition: MSStopOut.h:84
SUMOVehicleParameter::Stop
Definition of vehicle stop (position and duration)
Definition: SUMOVehicleParameter.h:572