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 /****************************************************************************/
16 // A device which collects info on the vehicle trip
17 /****************************************************************************/
18 #ifndef MSDevice_Vehroutes_h
19 #define MSDevice_Vehroutes_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include "MSVehicleDevice.h"
28 #include <microsim/MSNet.h>
29 #include <microsim/MSVehicle.h>
30 #include <utils/common/SUMOTime.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class MSEdge;
38 class MSRoute;
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
53 public:
56  static void init();
57 
58 
69  static MSDevice_Vehroutes* buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, int maxRoutes = std::numeric_limits<int>::max());
70 
71 
73  static void generateOutputForUnfinished();
74 
75 
76 public:
79 
80 
81 
84 
93  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
94 
95 
107  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
109 
111  const std::string deviceName() const {
112  return "vehroute";
113  }
114 
115  void stopEnded(const SUMOVehicleParameter::Stop& stop);
116 
121  void generateOutput() const;
122 
123 
129  const MSRoute* getRoute(int index) const;
130 
131 
136  void saveState(OutputDevice& out) const;
137 
142  void loadState(const SUMOSAXAttributes& attrs);
143 
144 
145 private:
151  MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes);
152 
153 
159  void writeXMLRoute(OutputDevice& os, int index = -1) const;
160 
161 
167  void writeOutput(const bool hasArrived) const;
168 
169 
172  void addRoute(const std::string& info);
173 
174 
175 
176 private:
178  static bool mySaveExits;
179 
181  static bool myLastRouteOnly;
182 
184  static bool myDUAStyle;
185 
187  static bool myWriteCosts;
188 
190  static bool mySorted;
191 
193  static bool myIntendedDepart;
194 
196  static bool myRouteLength;
197 
199  static bool mySkipPTLines;
200 
202  static bool myIncludeIncomplete;
203 
204 
209  public:
212 
217  void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
218 
220  std::map<const SUMOVehicle*, MSDevice_Vehroutes*, ComparatorNumericalIdLess> myDevices;
221 
222  };
223 
224 
227 
229  static std::map<const SUMOTime, int> myDepartureCounts;
230 
232  static std::map<const SUMOTime, std::map<const std::string, std::string> > myRouteInfos;
233 
234 
245  public:
251  RouteReplaceInfo(const MSEdge* const edge_, const SUMOTime time_, const MSRoute* const route_, const std::string& info_)
252  : edge(edge_), time(time_), route(route_), info(info_) {}
253 
256 
258  const MSEdge* edge;
259 
262 
264  const MSRoute* route;
265 
267  std::string info;
268 
269  };
270 
273 
275  std::vector<RouteReplaceInfo> myReplacedRoutes;
276 
278  std::vector<SUMOTime> myExits;
279 
281  const int myMaxRoutes;
282 
285 
288 
290  double myDepartPos;
291 
294 
297 
299 
300 private:
303 
306 
307 
308 };
309 
310 
311 #endif
312 
313 /****************************************************************************/
314 
MSDevice_Vehroutes::myDUAStyle
static bool myDUAStyle
A shortcut for the Option "vehroute-output.dua".
Definition: MSDevice_Vehroutes.h:184
MSDevice_Vehroutes::getRoute
const MSRoute * getRoute(int index) const
Called on route retrieval.
Definition: MSDevice_Vehroutes.cpp:367
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
MSDevice_Vehroutes::RouteReplaceInfo::route
const MSRoute * route
The prior route.
Definition: MSDevice_Vehroutes.h:264
MSDevice_Vehroutes::myRouteInfos
static std::map< const SUMOTime, std::map< const std::string, std::string > > myRouteInfos
Definition: MSDevice_Vehroutes.h:232
MSDevice_Vehroutes::RouteReplaceInfo::~RouteReplaceInfo
~RouteReplaceInfo()
Destructor.
Definition: MSDevice_Vehroutes.h:255
SUMOTime.h
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
OutputDevice_String
An output device that encapsulates an ofstream.
Definition: OutputDevice_String.h:39
MSDevice_Vehroutes::myIncludeIncomplete
static bool myIncludeIncomplete
A shortcut for the Option "vehroute-output.incomplete".
Definition: MSDevice_Vehroutes.h:202
MSVehicleDevice.h
MSDevice_Vehroutes::StateListener::myDevices
std::map< const SUMOVehicle *, MSDevice_Vehroutes *, ComparatorNumericalIdLess > myDevices
A map for internal notification.
Definition: MSDevice_Vehroutes.h:220
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSDevice_Vehroutes::loadState
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition: MSDevice_Vehroutes.cpp:439
MSDevice_Vehroutes::myExits
std::vector< SUMOTime > myExits
The times the vehicle exites an edge.
Definition: MSDevice_Vehroutes.h:278
MSDevice_Vehroutes::generateOutput
void generateOutput() const
Called on writing vehroutes output.
Definition: MSDevice_Vehroutes.cpp:259
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:137
MSDevice_Vehroutes::init
static void init()
Static intialization.
Definition: MSDevice_Vehroutes.cpp:64
MSNet::VehicleStateListener
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:568
MSDevice_Vehroutes::mySaveExits
static bool mySaveExits
A shortcut for the Option "vehroute-output.exit-times".
Definition: MSDevice_Vehroutes.h:178
MSDevice_Vehroutes::myMaxRoutes
const int myMaxRoutes
The maximum number of routes to report.
Definition: MSDevice_Vehroutes.h:281
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSDevice_Vehroutes::myDepartPosLat
double myDepartPosLat
The lateral depart position.
Definition: MSDevice_Vehroutes.h:296
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:156
MSDevice_Vehroutes::myDepartureCounts
static std::map< const SUMOTime, int > myDepartureCounts
Map needed to sort vehicles by departure time.
Definition: MSDevice_Vehroutes.h:229
MSDevice_Vehroutes::RouteReplaceInfo::time
SUMOTime time
The time the route was replaced.
Definition: MSDevice_Vehroutes.h:261
MSDevice_Vehroutes::StateListener
A class that is notified about reroutings.
Definition: MSDevice_Vehroutes.h:208
MSDevice_Vehroutes::RouteReplaceInfo::edge
const MSEdge * edge
The edge the vehicle was on when the route was replaced.
Definition: MSDevice_Vehroutes.h:258
MSRoute
Definition: MSRoute.h:66
MSDevice_Vehroutes::myCurrentRoute
const MSRoute * myCurrentRoute
The currently used route.
Definition: MSDevice_Vehroutes.h:272
MSVehicle.h
MSDevice_Vehroutes::myWriteCosts
static bool myWriteCosts
A shortcut for the Option "vehroute-output.costs".
Definition: MSDevice_Vehroutes.h:187
MSDevice_Vehroutes::myStateListener
static StateListener myStateListener
A class that is notified about reroutings.
Definition: MSDevice_Vehroutes.h:226
MSDevice_Vehroutes::RouteReplaceInfo::info
std::string info
Information regarding rerouting.
Definition: MSDevice_Vehroutes.h:267
MSDevice_Vehroutes::myRouteLength
static bool myRouteLength
A shortcut for the Option "vehroute-output.route-length".
Definition: MSDevice_Vehroutes.h:196
MSDevice_Vehroutes::saveState
void saveState(OutputDevice &out) const
Saves the state of the device.
Definition: MSDevice_Vehroutes.cpp:415
MSDevice_Vehroutes::mySorted
static bool mySorted
A shortcut for the Option "vehroute-output.sorted".
Definition: MSDevice_Vehroutes.h:190
MSNet::VehicleState
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:535
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:83
MSDevice_Vehroutes::mySkipPTLines
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
Definition: MSDevice_Vehroutes.h:199
MSDevice_Vehroutes::generateOutputForUnfinished
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
Definition: MSDevice_Vehroutes.cpp:397
MSDevice_Vehroutes::RouteReplaceInfo
Information about a replaced route.
Definition: MSDevice_Vehroutes.h:244
MSDevice_Vehroutes::writeXMLRoute
void writeXMLRoute(OutputDevice &os, int index=-1) const
Called on route output.
Definition: MSDevice_Vehroutes.cpp:176
MSDevice_Vehroutes::StateListener::~StateListener
~StateListener()
Destructor.
Definition: MSDevice_Vehroutes.h:211
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
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:103
MSDevice_Vehroutes::myLastRouteOnly
static bool myLastRouteOnly
A shortcut for the Option "vehroute-output.last-route".
Definition: MSDevice_Vehroutes.h:181
MSDevice_Vehroutes::myDepartLane
int myDepartLane
The lane the vehicle departed at.
Definition: MSDevice_Vehroutes.h:287
MSDevice_Vehroutes::myIntendedDepart
static bool myIntendedDepart
A shortcut for the Option "vehroute-output.intended-depart".
Definition: MSDevice_Vehroutes.h:193
MSDevice_Vehroutes::MSDevice_Vehroutes
MSDevice_Vehroutes(SUMOVehicle &holder, const std::string &id, int maxRoutes)
Constructor.
Definition: MSDevice_Vehroutes.cpp:113
MSDevice_Vehroutes::stopEnded
void stopEnded(const SUMOVehicleParameter::Stop &stop)
Definition: MSDevice_Vehroutes.cpp:170
MSDevice_Vehroutes::addRoute
void addRoute(const std::string &info)
Called on route change.
Definition: MSDevice_Vehroutes.cpp:377
MSDevice_Vehroutes::myDepartPos
double myDepartPos
The lane the vehicle departed at.
Definition: MSDevice_Vehroutes.h:290
MSDevice_Vehroutes
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Vehroutes.h:52
MSDevice_Vehroutes::deviceName
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_Vehroutes.h:111
MSDevice_Vehroutes::myLastSavedAt
const MSEdge * myLastSavedAt
The last edge the exit time was saved for.
Definition: MSDevice_Vehroutes.h:284
OutputDevice_String.h
MSDevice_Vehroutes::myReplacedRoutes
std::vector< RouteReplaceInfo > myReplacedRoutes
Prior routes.
Definition: MSDevice_Vehroutes.h:275
MSDevice_Vehroutes::writeOutput
void writeOutput(const bool hasArrived) const
Called on writing vehroutes output.
Definition: MSDevice_Vehroutes.cpp:265
config.h
MSDevice_Vehroutes::~MSDevice_Vehroutes
~MSDevice_Vehroutes()
Destructor.
Definition: MSDevice_Vehroutes.cpp:127
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
MSDevice_Vehroutes::myStopOut
OutputDevice_String myStopOut
Definition: MSDevice_Vehroutes.h:298
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:251
SUMOVehicleParameter::Stop
Definition of vehicle stop (position and duration)
Definition: SUMOVehicleParameter.h:572
MSDevice_Vehroutes::myDepartSpeed
double myDepartSpeed
The speed on departure.
Definition: MSDevice_Vehroutes.h:293
MSVehicleDevice
Abstract in-vehicle device.
Definition: MSVehicleDevice.h:54