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-2018 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 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
long long int SUMOTime
Definition: SUMOTime.h:36
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
static void init()
Static intialization.
Definition: MSStopOut.cpp:41
std::string containerstop
(Optional) container stop if one is assigned to the stop
bool parking
whether the vehicle is removed from the net while stopping
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
SUMOTime until
The time at which the vehicle may continue its journey.
Stopped myStopped
Definition: MSStopOut.h:118
const std::string & getID() const
Returns the id.
Definition: Named.h:78
std::string parkingarea
(Optional) parking area if one is assigned to the stop
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
void loadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:89
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID)
Definition: MSStopOut.cpp:99
void unloadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:84
std::string busstop
(Optional) bus stop if one is assigned to the stop
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition: MSStopOut.cpp:64
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static void cleanup()
Definition: MSStopOut.cpp:48
std::string chargingStation
(Optional) charging station if one is assigned to the stop
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
static MSStopOut * myInstance
Definition: MSStopOut.h:122
void unloadedContainers(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:94
virtual ~MSStopOut()
Destructor.
Definition: MSStopOut.cpp:60
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
Definition of vehicle stop (position and duration)
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
OutputDevice & myDevice
Definition: MSStopOut.h:120
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void loadedPersons(const SUMOVehicle *veh, int n)
Definition: MSStopOut.cpp:76
static bool gUseMesoSim
Definition: MSGlobals.h:91
Realises dumping the complete network state.
Definition: MSStopOut.h:50
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
MSStopOut(OutputDevice &dev)
constructor.
Definition: MSStopOut.cpp:56