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 /****************************************************************************/
15 // Ouput information about planned vehicle stop
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
27 #include <microsim/MSNet.h>
28 #include <microsim/MSEdge.h>
29 #include <microsim/MSParkingArea.h>
32 #include "MSStopOut.h"
33 
34 
35 // ---------------------------------------------------------------------------
36 // static initialisation methods
37 // ---------------------------------------------------------------------------
39 
40 void
42  if (OptionsCont::getOptions().isSet("stop-output")) {
44  }
45 }
46 
47 void
49  delete myInstance;
50  myInstance = nullptr;
51 }
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57  myDevice(dev) {
58 }
59 
61 
62 
63 void
64 MSStopOut::stopStarted(const SUMOVehicle* veh, int numPersons, int numContainers, SUMOTime time) {
65  assert(veh != 0);
66  if (myStopped.count(veh) != 0) {
67  WRITE_WARNING("Vehicle '" + veh->getID() + "' stops on edge '" + veh->getEdge()->getID()
68  + "', time " + time2string(time)
69  + " without ending the previous stop entered at time " + time2string(myStopped[veh].started));
70  }
71  StopInfo stopInfo(MSNet::getInstance()->getCurrentTimeStep(), numPersons, numContainers);
72  myStopped[veh] = stopInfo;
73 }
74 
75 void
77  // ignore triggered vehicles
78  if (veh->hasDeparted()) {
79  myStopped[veh].loadedPersons += n;
80  }
81 }
82 
83 void
85  myStopped[veh].unloadedPersons += n;
86 }
87 
88 void
90  myStopped[veh].loadedContainers += n;
91 }
92 
93 void
95  myStopped[veh].unloadedContainers += n;
96 }
97 
98 void
99 MSStopOut::stopEnded(const SUMOVehicle* veh, const SUMOVehicleParameter::Stop& stop, const std::string& laneOrEdgeID) {
100  assert(veh != 0);
101  if (myStopped.count(veh) == 0) {
102  WRITE_WARNING("Vehicle '" + veh->getID() + "' ends stop on edge '" + veh->getEdge()->getID()
103  + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + " without entering the stop");
104  return;
105  }
106  double delay = -1;
107  if (stop.until >= 0) {
108  delay = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - stop.until);
109  }
110  StopInfo& si = myStopped[veh];
111  myDevice.openTag("stopinfo");
115  myDevice.writeAttr(SUMO_ATTR_EDGE, laneOrEdgeID);
116  } else {
117  myDevice.writeAttr(SUMO_ATTR_LANE, laneOrEdgeID);
118  }
121  myDevice.writeAttr("started", time2string(si.started));
122  myDevice.writeAttr("ended", time2string(MSNet::getInstance()->getCurrentTimeStep()));
123  myDevice.writeAttr("delay", delay);
124  myDevice.writeAttr("initialPersons", si.initialNumPersons);
125  myDevice.writeAttr("loadedPersons", si.loadedPersons);
126  myDevice.writeAttr("unloadedPersons", si.unloadedPersons);
127  myDevice.writeAttr("initialContainers", si.initialNumContainers);
128  myDevice.writeAttr("loadedContainers", si.loadedContainers);
129  myDevice.writeAttr("unloadedContainers", si.unloadedContainers);
130  if (stop.busstop != "") {
132  }
133  if (stop.containerstop != "") {
135  }
136  if (stop.parkingarea != "") {
138  }
139  if (stop.chargingStation != "") {
141  }
142  myDevice.closeTag();
143  myStopped.erase(veh);
144 }
145 
146 /****************************************************************************/
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:382
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
MSStopOut::unloadedContainers
void unloadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:94
MSStopOut.h
MSStopOut::MSStopOut
MSStopOut(OutputDevice &dev)
constructor.
Definition: MSStopOut.cpp:56
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
MSNet.h
SUMO_ATTR_PARKING_AREA
Definition: SUMOXMLDefinitions.h:768
SUMO_ATTR_CONTAINER_STOP
Definition: SUMOXMLDefinitions.h:767
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
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.
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
MsgHandler.h
MSStopOut::StopInfo::unloadedPersons
int unloadedPersons
Definition: MSStopOut.h:111
SUMOVehicleParameter::Stop::busstop
std::string busstop
(Optional) bus stop if one is assigned to the stop
Definition: SUMOVehicleParameter.h:583
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:424
MSStopOut::loadedPersons
void loadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:76
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:91
MSChargingStation.h
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
SUMOVehicleParameter::Stop::parkingarea
std::string parkingarea
(Optional) parking area if one is assigned to the stop
Definition: SUMOVehicleParameter.h:589
MSEdge.h
SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:635
SUMO_ATTR_CHARGING_STATION
Definition: SUMOXMLDefinitions.h:771
MSStopOut::loadedContainers
void loadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:89
MSStopOut
Realises dumping the complete network state.
Definition: MSStopOut.h:50
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:254
MSStopOut::init
static void init()
Static intialization.
Definition: MSStopOut.cpp:41
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
SUMOVehicle.h
MSStopOut::StopInfo::unloadedContainers
int unloadedContainers
Definition: MSStopOut.h:114
MSStopOut::cleanup
static void cleanup()
Definition: MSStopOut.cpp:48
SUMOVehicleParameter::Stop::until
SUMOTime until
The time at which the vehicle may continue its journey.
Definition: SUMOVehicleParameter.h:604
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
MSStopOut::myDevice
OutputDevice & myDevice
Definition: MSStopOut.h:120
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
MSParkingArea.h
MSStopOut::StopInfo::loadedContainers
int loadedContainers
Definition: MSStopOut.h:113
MSStopOut::StopInfo::started
SUMOTime started
Definition: MSStopOut.h:108
MSStopOut::~MSStopOut
virtual ~MSStopOut()
Destructor.
Definition: MSStopOut.cpp:60
MSStopOut::myStopped
Stopped myStopped
Definition: MSStopOut.h:118
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:658
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
MSStopOut::myInstance
static MSStopOut * myInstance
Definition: MSStopOut.h:122
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
SUMOVehicle::hasDeparted
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
MSStopOut::StopInfo::initialNumContainers
int initialNumContainers
Definition: MSStopOut.h:112
MSStopOut::unloadedPersons
void unloadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:84
MSStopOut::stopStarted
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition: MSStopOut.cpp:64
SUMO_ATTR_PARKING
Definition: SUMOXMLDefinitions.h:798
config.h
MSStopOut::StopInfo::initialNumPersons
int initialNumPersons
Definition: MSStopOut.h:109
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
SUMO_ATTR_BUS_STOP
Definition: SUMOXMLDefinitions.h:766
MSStopOut::stopEnded
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID)
Definition: MSStopOut.cpp:99
MSStopOut::StopInfo::loadedPersons
int loadedPersons
Definition: MSStopOut.h:110
MSStoppingPlace.h
SUMOVehicleParameter::Stop::parking
bool parking
whether the vehicle is removed from the net while stopping
Definition: SUMOVehicleParameter.h:613
SUMOVehicleParameter::Stop::chargingStation
std::string chargingStation
(Optional) charging station if one is assigned to the stop
Definition: SUMOVehicleParameter.h:592
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
SUMOVehicleParameter::Stop::containerstop
std::string containerstop
(Optional) container stop if one is assigned to the stop
Definition: SUMOVehicleParameter.h:586
OutputDevice::getDeviceByOption
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
Definition: OutputDevice.cpp:117
MSStopOut::StopInfo
Definition: MSStopOut.h:85
SUMOVehicleParameter::Stop
Definition of vehicle stop (position and duration)
Definition: SUMOVehicleParameter.h:566