Eclipse SUMO - Simulation of Urban MObility
MSDevice_Vehroutes.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2009-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 /****************************************************************************/
17 // A device which collects info on the vehicle trip
18 /****************************************************************************/
19 #ifndef MSDevice_Vehroutes_h
20 #define MSDevice_Vehroutes_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include "MSVehicleDevice.h"
29 #include <microsim/MSNet.h>
30 #include <microsim/MSVehicle.h>
31 #include <utils/common/SUMOTime.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSEdge;
39 class MSRoute;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
54 public:
57  static void init();
58 
59 
70  static MSDevice_Vehroutes* buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, int maxRoutes = std::numeric_limits<int>::max());
71 
72 
74  static void generateOutputForUnfinished();
75 
76 
77 public:
80 
81 
82 
85 
94  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
95 
96 
108  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
110 
112  const std::string deviceName() const {
113  return "vehroute";
114  }
115 
116  void stopEnded(const SUMOVehicleParameter::Stop& stop);
117 
122  void generateOutput() const;
123 
124 
130  const MSRoute* getRoute(int index) const;
131 
132 
137  void saveState(OutputDevice& out) const;
138 
143  void loadState(const SUMOSAXAttributes& attrs);
144 
145 
146 private:
152  MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes);
153 
154 
160  void writeXMLRoute(OutputDevice& os, int index = -1) const;
161 
162 
168  void writeOutput(const bool hasArrived) const;
169 
170 
173  void addRoute(const std::string& info);
174 
175 
176 
177 private:
179  static bool mySaveExits;
180 
182  static bool myLastRouteOnly;
183 
185  static bool myDUAStyle;
186 
188  static bool myWriteCosts;
189 
191  static bool mySorted;
192 
194  static bool myIntendedDepart;
195 
197  static bool myRouteLength;
198 
200  static bool mySkipPTLines;
201 
203  static bool myIncludeIncomplete;
204 
205 
210  public:
213 
218  void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
219 
221  std::map<const SUMOVehicle*, MSDevice_Vehroutes*, ComparatorNumericalIdLess> myDevices;
222 
223  };
224 
225 
228 
230  static std::map<const SUMOTime, int> myDepartureCounts;
231 
233  static std::map<const SUMOTime, std::map<const std::string, std::string> > myRouteInfos;
234 
235 
246  public:
252  RouteReplaceInfo(const MSEdge* const edge_, const SUMOTime time_, const MSRoute* const route_, const std::string& info_)
253  : edge(edge_), time(time_), route(route_), info(info_) {}
254 
257 
259  const MSEdge* edge;
260 
263 
265  const MSRoute* route;
266 
268  std::string info;
269 
270  };
271 
274 
276  std::vector<RouteReplaceInfo> myReplacedRoutes;
277 
279  std::vector<SUMOTime> myExits;
280 
282  const int myMaxRoutes;
283 
286 
289 
291  double myDepartPos;
292 
295 
298 
300 
301 private:
304 
307 
308 
309 };
310 
311 
312 #endif
313 
314 /****************************************************************************/
315 
MSDevice_Vehroutes::myDUAStyle
static bool myDUAStyle
A shortcut for the Option "vehroute-output.dua".
Definition: MSDevice_Vehroutes.h:185
MSDevice_Vehroutes::getRoute
const MSRoute * getRoute(int index) const
Called on route retrieval.
Definition: MSDevice_Vehroutes.cpp:368
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:48
MSDevice_Vehroutes::RouteReplaceInfo::route
const MSRoute * route
The prior route.
Definition: MSDevice_Vehroutes.h:265
MSDevice_Vehroutes::myRouteInfos
static std::map< const SUMOTime, std::map< const std::string, std::string > > myRouteInfos
Definition: MSDevice_Vehroutes.h:233
MSDevice_Vehroutes::RouteReplaceInfo::~RouteReplaceInfo
~RouteReplaceInfo()
Destructor.
Definition: MSDevice_Vehroutes.h:256
SUMOTime.h
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
OutputDevice_String
An output device that encapsulates an ofstream.
Definition: OutputDevice_String.h:40
MSDevice_Vehroutes::myIncludeIncomplete
static bool myIncludeIncomplete
A shortcut for the Option "vehroute-output.incomplete".
Definition: MSDevice_Vehroutes.h:203
MSVehicleDevice.h
MSDevice_Vehroutes::StateListener::myDevices
std::map< const SUMOVehicle *, MSDevice_Vehroutes *, ComparatorNumericalIdLess > myDevices
A map for internal notification.
Definition: MSDevice_Vehroutes.h:221
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSDevice_Vehroutes::loadState
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition: MSDevice_Vehroutes.cpp:440
MSDevice_Vehroutes::myExits
std::vector< SUMOTime > myExits
The times the vehicle exites an edge.
Definition: MSDevice_Vehroutes.h:279
MSDevice_Vehroutes::generateOutput
void generateOutput() const
Called on writing vehroutes output.
Definition: MSDevice_Vehroutes.cpp:260
MSDevice_Vehroutes::notifyEnter
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Does nothing, returns true only if exit times should be collected.
Definition: MSDevice_Vehroutes.cpp:138
MSDevice_Vehroutes::init
static void init()
Static intialization.
Definition: MSDevice_Vehroutes.cpp:65
MSNet::VehicleStateListener
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:567
MSDevice_Vehroutes::mySaveExits
static bool mySaveExits
A shortcut for the Option "vehroute-output.exit-times".
Definition: MSDevice_Vehroutes.h:179
MSDevice_Vehroutes::myMaxRoutes
const int myMaxRoutes
The maximum number of routes to report.
Definition: MSDevice_Vehroutes.h:282
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
MSDevice_Vehroutes::myDepartPosLat
double myDepartPosLat
The lateral depart position.
Definition: MSDevice_Vehroutes.h:297
MSDevice_Vehroutes::operator=
MSDevice_Vehroutes & operator=(const MSDevice_Vehroutes &)
Invalidated assignment operator.
MSDevice_Vehroutes::notifyLeave
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Saves exit times if needed.
Definition: MSDevice_Vehroutes.cpp:157
MSDevice_Vehroutes::myDepartureCounts
static std::map< const SUMOTime, int > myDepartureCounts
Map needed to sort vehicles by departure time.
Definition: MSDevice_Vehroutes.h:230
MSDevice_Vehroutes::RouteReplaceInfo::time
SUMOTime time
The time the route was replaced.
Definition: MSDevice_Vehroutes.h:262
MSDevice_Vehroutes::StateListener
A class that is notified about reroutings.
Definition: MSDevice_Vehroutes.h:209
MSDevice_Vehroutes::RouteReplaceInfo::edge
const MSEdge * edge
The edge the vehicle was on when the route was replaced.
Definition: MSDevice_Vehroutes.h:259
MSRoute
Definition: MSRoute.h:67
MSDevice_Vehroutes::myCurrentRoute
const MSRoute * myCurrentRoute
The currently used route.
Definition: MSDevice_Vehroutes.h:273
MSVehicle.h
MSDevice_Vehroutes::myWriteCosts
static bool myWriteCosts
A shortcut for the Option "vehroute-output.costs".
Definition: MSDevice_Vehroutes.h:188
MSDevice_Vehroutes::myStateListener
static StateListener myStateListener
A class that is notified about reroutings.
Definition: MSDevice_Vehroutes.h:227
MSDevice_Vehroutes::RouteReplaceInfo::info
std::string info
Information regarding rerouting.
Definition: MSDevice_Vehroutes.h:268
MSDevice_Vehroutes::myRouteLength
static bool myRouteLength
A shortcut for the Option "vehroute-output.route-length".
Definition: MSDevice_Vehroutes.h:197
MSDevice_Vehroutes::saveState
void saveState(OutputDevice &out) const
Saves the state of the device.
Definition: MSDevice_Vehroutes.cpp:416
MSDevice_Vehroutes::mySorted
static bool mySorted
A shortcut for the Option "vehroute-output.sorted".
Definition: MSDevice_Vehroutes.h:191
MSNet::VehicleState
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:536
MSDevice_Vehroutes::buildVehicleDevices
static MSDevice_Vehroutes * buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into, int maxRoutes=std::numeric_limits< int >::max())
Build devices for the given vehicle, if needed.
Definition: MSDevice_Vehroutes.cpp:84
MSDevice_Vehroutes::mySkipPTLines
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
Definition: MSDevice_Vehroutes.h:200
MSDevice_Vehroutes::generateOutputForUnfinished
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
Definition: MSDevice_Vehroutes.cpp:398
MSDevice_Vehroutes::RouteReplaceInfo
Information about a replaced route.
Definition: MSDevice_Vehroutes.h:245
MSDevice_Vehroutes::writeXMLRoute
void writeXMLRoute(OutputDevice &os, int index=-1) const
Called on route output.
Definition: MSDevice_Vehroutes.cpp:177
MSDevice_Vehroutes::StateListener::~StateListener
~StateListener()
Destructor.
Definition: MSDevice_Vehroutes.h:212
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
MSDevice_Vehroutes::StateListener::vehicleStateChanged
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
Definition: MSDevice_Vehroutes.cpp:104
MSDevice_Vehroutes::myLastRouteOnly
static bool myLastRouteOnly
A shortcut for the Option "vehroute-output.last-route".
Definition: MSDevice_Vehroutes.h:182
MSDevice_Vehroutes::myDepartLane
int myDepartLane
The lane the vehicle departed at.
Definition: MSDevice_Vehroutes.h:288
MSDevice_Vehroutes::myIntendedDepart
static bool myIntendedDepart
A shortcut for the Option "vehroute-output.intended-depart".
Definition: MSDevice_Vehroutes.h:194
MSDevice_Vehroutes::MSDevice_Vehroutes
MSDevice_Vehroutes(SUMOVehicle &holder, const std::string &id, int maxRoutes)
Constructor.
Definition: MSDevice_Vehroutes.cpp:114
MSDevice_Vehroutes::stopEnded
void stopEnded(const SUMOVehicleParameter::Stop &stop)
Definition: MSDevice_Vehroutes.cpp:171
MSDevice_Vehroutes::addRoute
void addRoute(const std::string &info)
Called on route change.
Definition: MSDevice_Vehroutes.cpp:378
MSDevice_Vehroutes::myDepartPos
double myDepartPos
The lane the vehicle departed at.
Definition: MSDevice_Vehroutes.h:291
MSDevice_Vehroutes
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Vehroutes.h:53
MSDevice_Vehroutes::deviceName
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_Vehroutes.h:112
MSDevice_Vehroutes::myLastSavedAt
const MSEdge * myLastSavedAt
The last edge the exit time was saved for.
Definition: MSDevice_Vehroutes.h:285
OutputDevice_String.h
MSDevice_Vehroutes::myReplacedRoutes
std::vector< RouteReplaceInfo > myReplacedRoutes
Prior routes.
Definition: MSDevice_Vehroutes.h:276
MSDevice_Vehroutes::writeOutput
void writeOutput(const bool hasArrived) const
Called on writing vehroutes output.
Definition: MSDevice_Vehroutes.cpp:266
config.h
MSDevice_Vehroutes::~MSDevice_Vehroutes
~MSDevice_Vehroutes()
Destructor.
Definition: MSDevice_Vehroutes.cpp:128
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:57
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:89
MSDevice_Vehroutes::myStopOut
OutputDevice_String myStopOut
Definition: MSDevice_Vehroutes.h:299
MSDevice_Vehroutes::RouteReplaceInfo::RouteReplaceInfo
RouteReplaceInfo(const MSEdge *const edge_, const SUMOTime time_, const MSRoute *const route_, const std::string &info_)
Constructor.
Definition: MSDevice_Vehroutes.h:252
SUMOVehicleParameter::Stop
Definition of vehicle stop (position and duration)
Definition: SUMOVehicleParameter.h:566
MSDevice_Vehroutes::myDepartSpeed
double myDepartSpeed
The speed on departure.
Definition: MSDevice_Vehroutes.h:294
MSVehicleDevice
Abstract in-vehicle device.
Definition: MSVehicleDevice.h:55