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 
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.
long long int SUMOTime
Definition: SUMOTime.h:35
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:567
const MSRoute * myCurrentRoute
The currently used route.
static bool myWriteCosts
A shortcut for the Option "vehroute-output.costs".
static StateListener myStateListener
A class that is notified about reroutings.
static bool myDUAStyle
A shortcut for the Option "vehroute-output.dua".
Notification
Definition of a vehicle state.
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".
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.
void generateOutput() const
Called on writing vehroutes output.
static void init()
Static intialization.
void stopEnded(const SUMOVehicleParameter::Stop &stop)
A road/street connecting two junctions.
Definition: MSEdge.h:76
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".
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Saves exit times if needed.
Representation of a vehicle.
Definition: SUMOVehicle.h:61
const MSRoute * route
The prior route.
Encapsulated SAX-Attributes.
double myDepartPosLat
The lateral depart position.
RouteReplaceInfo(const MSEdge *const edge_, const SUMOTime time_, const MSRoute *const route_, const std::string &info_)
Constructor.
void addRoute(const std::string &info)
Called on route change.
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
std::map< const SUMOVehicle *, MSDevice_Vehroutes *, ComparatorNumericalIdLess > myDevices
A map for internal notification.
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
void writeOutput(const bool hasArrived) const
Called on writing vehroutes output.
Definition of vehicle stop (position and duration)
static bool myRouteLength
A shortcut for the Option "vehroute-output.route-length".
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:536
void saveState(OutputDevice &out) const
Saves the state of the device.
Representation of a vehicle or person.
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
Abstract in-vehicle device.
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
std::string info
Information regarding rerouting.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
SUMOTime time
The time the route was replaced.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
const MSRoute * getRoute(int index) const
Called on route retrieval.
static std::map< const SUMOTime, std::map< const std::string, std::string > > myRouteInfos
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Does nothing, returns true only if exit times should be collected.
double myDepartPos
The lane the vehicle departed at.
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
static bool myIncludeIncomplete
A shortcut for the Option "vehroute-output.incomplete".
An output device that encapsulates an ofstream.
const MSEdge * myLastSavedAt
The last edge the exit time was saved for.
~MSDevice_Vehroutes()
Destructor.
Information about a replaced route.