SUMO - Simulation of Urban MObility
MSDevice_Vehroutes.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A device which collects info on the vehicle trip
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2009-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSDevice_Vehroutes_h
23 #define MSDevice_Vehroutes_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include "MSDevice.h"
36 #include <microsim/MSNet.h>
37 #include <utils/common/SUMOTime.h>
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class MSEdge;
44 class MSRoute;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
58 class MSDevice_Vehroutes : public MSDevice {
59 public:
62  static void init();
63 
64 
75  static MSDevice_Vehroutes* buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into, int maxRoutes = INT_MAX);
76 
77 
79  static void generateOutputForUnfinished();
80 
81 
82 public:
85 
86 
87 
90 
99  bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
100 
101 
113  bool notifyLeave(SUMOVehicle& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
115 
117  const std::string deviceName() const {
118  return "vehroute";
119  }
120 
121 
126  void generateOutput() const;
127 
128 
134  const MSRoute* getRoute(int index) const;
135 
136 
141  void saveState(OutputDevice& out) const;
142 
147  void loadState(const SUMOSAXAttributes& attrs);
148 
149 
150 private:
156  MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes);
157 
158 
164  void writeXMLRoute(OutputDevice& os, int index = -1) const;
165 
166 
172  void writeOutput(const bool hasArrived) const;
173 
174 
177  void addRoute();
178 
179 
180 
181 private:
183  static bool mySaveExits;
184 
186  static bool myLastRouteOnly;
187 
189  static bool myDUAStyle;
190 
192  static bool mySorted;
193 
195  static bool myIntendedDepart;
196 
198  static bool myRouteLength;
199 
200 
205  public:
208 
213  void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to);
214 
216  std::map<const SUMOVehicle*, MSDevice_Vehroutes*, SUMOVehicle::ComparatorIdLess> myDevices;
217 
218  };
219 
220 
223 
225  static std::map<const SUMOTime, int> myDepartureCounts;
226 
228  static std::map<const SUMOTime, std::map<const std::string, std::string> > myRouteInfos;
229 
230 
241  public:
247  RouteReplaceInfo(const MSEdge* const edge_, const SUMOTime time_, const MSRoute* const route_)
248  : edge(edge_), time(time_), route(route_) {}
249 
252 
254  const MSEdge* edge;
255 
258 
260  const MSRoute* route;
261 
262  };
263 
266 
268  std::vector<RouteReplaceInfo> myReplacedRoutes;
269 
271  std::vector<SUMOTime> myExits;
272 
274  const int myMaxRoutes;
275 
278 
281 
283  double myDepartPos;
284 
287 
290 
291 private:
294 
297 
298 
299 };
300 
301 
302 #endif
303 
304 /****************************************************************************/
305 
static std::map< const SUMOTime, int > myDepartureCounts
Map needed to sort vehicles by departure time.
const int myMaxRoutes
The maximum number of routes to report.
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:603
const MSRoute * myCurrentRoute
The currently used route.
static StateListener myStateListener
A class that is notified about reroutings.
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to)
Called if a vehicle changes its state.
static bool myDUAStyle
A shortcut for the Option "vehroute-output.dua".
Notification
Definition of a vehicle state.
RouteReplaceInfo(const MSEdge *const edge_, const SUMOTime time_, const MSRoute *const route_)
Constructor.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Does nothing, returns true only if exit times should be collected.
std::vector< SUMOTime > myExits
The times the vehicle exites an edge.
static bool mySorted
A shortcut for the Option "vehroute-output.sorted".
static bool mySaveExits
A shortcut for the Option "vehroute-output.exit-times".
void writeXMLRoute(OutputDevice &os, int index=-1) const
Called on route output.
static bool myIntendedDepart
A shortcut for the Option "vehroute-output.intended-depart".
std::map< const SUMOVehicle *, MSDevice_Vehroutes *, SUMOVehicle::ComparatorIdLess > myDevices
A map for internal notification.
void generateOutput() const
Called on writing vehroutes output.
static void init()
Static intialization.
A road/street connecting two junctions.
Definition: MSEdge.h:80
MSDevice_Vehroutes & operator=(const MSDevice_Vehroutes &)
Invalidated assignment operator.
int myDepartLane
The lane the vehicle departed at.
static bool myLastRouteOnly
A shortcut for the Option "vehroute-output.last-route".
void addRoute()
Called on route change.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
const MSRoute * route
The prior route.
Encapsulated SAX-Attributes.
double myDepartPosLat
The lateral depart position.
std::vector< RouteReplaceInfo > myReplacedRoutes
Prior routes.
const std::string deviceName() const
return the name for this type of device
static MSDevice_Vehroutes * buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into, int maxRoutes=INT_MAX)
Build devices for the given vehicle, if needed.
A class that is notified about reroutings.
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
void writeOutput(const bool hasArrived) const
Called on writing vehroutes output.
static bool myRouteLength
A shortcut for the Option "vehroute-output.route-length".
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:576
void saveState(OutputDevice &out) const
Saves the state of the device.
bool notifyLeave(SUMOVehicle &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Saves exit times if needed.
Abstract in-vehicle device.
Definition: MSDevice.h:71
double myDepartSpeed
The speed on departure.
MSDevice_Vehroutes(SUMOVehicle &holder, const std::string &id, int maxRoutes)
Constructor.
const MSEdge * edge
The edge the vehicle was on when the route was replaced.
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
SUMOTime time
The time the route was replaced.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
long long int SUMOTime
Definition: TraCIDefs.h:52
const MSRoute * getRoute(int index) const
Called on route retrieval.
static std::map< const SUMOTime, std::map< const std::string, std::string > > myRouteInfos
double myDepartPos
The lane the vehicle departed at.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
const MSEdge * myLastSavedAt
The last edge the exit time was saved for.
~MSDevice_Vehroutes()
Destructor.
Information about a replaced route.