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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A device which collects info on the vehicle trip
20 /****************************************************************************/
21 #ifndef MSDevice_Vehroutes_h
22 #define MSDevice_Vehroutes_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "MSDevice.h"
35 #include <microsim/MSNet.h>
36 #include <microsim/MSVehicle.h>
37 #include <utils/common/SUMOTime.h>
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class MSEdge;
45 class MSRoute;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
59 class MSDevice_Vehroutes : public MSDevice {
60 public:
63  static void init();
64 
65 
76  static MSDevice_Vehroutes* buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into, int maxRoutes = std::numeric_limits<int>::max());
77 
78 
80  static void generateOutputForUnfinished();
81 
82 
83 public:
86 
87 
88 
91 
100  bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
101 
102 
114  bool notifyLeave(SUMOVehicle& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
116 
118  const std::string deviceName() const {
119  return "vehroute";
120  }
121 
122  void stopEnded(const MSVehicle::Stop& stop);
123 
128  void generateOutput() const;
129 
130 
136  const MSRoute* getRoute(int index) const;
137 
138 
143  void saveState(OutputDevice& out) const;
144 
149  void loadState(const SUMOSAXAttributes& attrs);
150 
151 
152 private:
158  MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes);
159 
160 
166  void writeXMLRoute(OutputDevice& os, int index = -1) const;
167 
168 
174  void writeOutput(const bool hasArrived) const;
175 
176 
179  void addRoute();
180 
181 
182 
183 private:
185  static bool mySaveExits;
186 
188  static bool myLastRouteOnly;
189 
191  static bool myDUAStyle;
192 
194  static bool mySorted;
195 
197  static bool myIntendedDepart;
198 
200  static bool myRouteLength;
201 
203  static bool mySkipPTLines;
204 
205 
210  public:
213 
218  void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to);
219 
221  std::map<const SUMOVehicle*, MSDevice_Vehroutes*, SUMOVehicle::ComparatorIdLess> 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_)
253  : edge(edge_), time(time_), route(route_) {}
254 
257 
259  const MSEdge* edge;
260 
263 
265  const MSRoute* route;
266 
267  };
268 
271 
273  std::vector<RouteReplaceInfo> myReplacedRoutes;
274 
276  std::vector<SUMOTime> myExits;
277 
279  const int myMaxRoutes;
280 
283 
286 
288  double myDepartPos;
289 
292 
295 
297 
298 private:
301 
304 
305 
306 };
307 
308 
309 #endif
310 
311 /****************************************************************************/
312 
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:509
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:66
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
A class that is notified about reroutings.
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
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:482
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:70
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.
OutputDevice_String myStopOut
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
static MSDevice_Vehroutes * buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into, int maxRoutes=std::numeric_limits< int >::max())
Build devices for the given vehicle, if needed.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
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:51
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:77
An output device that encapsulates an ofstream.
void stopEnded(const MSVehicle::Stop &stop)
Definition of vehicle stop (position and duration)
Definition: MSVehicle.h:901
const MSEdge * myLastSavedAt
The last edge the exit time was saved for.
~MSDevice_Vehroutes()
Destructor.
Information about a replaced route.