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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A device which collects info on the vehicle trip
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include "MSVehicleDevice.h"
26 #include <microsim/MSNet.h>
27 #include <microsim/MSVehicle.h>
28 #include <utils/common/SUMOTime.h>
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
35 class MSEdge;
36 class MSRoute;
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
51 public:
54  static void init();
55 
59  static void insertOptions(OptionsCont& oc);
60 
71  static MSDevice_Vehroutes* buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, int maxRoutes = std::numeric_limits<int>::max());
72 
73 
75  static void generateOutputForUnfinished();
76 
77 
78 public:
81 
82 
83 
86 
95  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
96 
97 
109  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
111 
113  const std::string deviceName() const {
114  return "vehroute";
115  }
116 
117  void stopEnded(const SUMOVehicleParameter::Stop& stop);
118 
123  void generateOutput(OutputDevice* tripinfoOut) const;
124 
125 
131  const MSRoute* getRoute(int index) const;
132 
133 
138  void saveState(OutputDevice& out) const;
139 
144  void loadState(const SUMOSAXAttributes& attrs);
145 
146 
147 private:
153  MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes);
154 
155 
161  void writeXMLRoute(OutputDevice& os, int index = -1) const;
162 
163 
169  void writeOutput(const bool hasArrived) const;
170 
171 
174  void addRoute(const std::string& info);
175 
176 
177 
178 private:
180  static bool mySaveExits;
181 
183  static bool myLastRouteOnly;
184 
186  static bool myDUAStyle;
187 
189  static bool myWriteCosts;
190 
192  static bool mySorted;
193 
195  static bool myIntendedDepart;
196 
198  static bool myRouteLength;
199 
201  static bool mySkipPTLines;
202 
204  static bool myIncludeIncomplete;
205 
208 
213  public:
216 
221  void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
222 
224  std::map<const SUMOVehicle*, MSDevice_Vehroutes*, ComparatorNumericalIdLess> myDevices;
225 
226  };
227 
228 
231 
233  static std::map<const SUMOTime, int> myDepartureCounts;
234 
236  static std::map<const SUMOTime, std::map<const std::string, std::string> > myRouteInfos;
237 
238 
249  public:
255  RouteReplaceInfo(const MSEdge* const edge_, const SUMOTime time_, const MSRoute* const route_, const std::string& info_)
256  : edge(edge_), time(time_), route(route_), info(info_) {}
257 
260 
262  const MSEdge* edge;
263 
266 
268  const MSRoute* route;
269 
271  std::string info;
272 
273  };
274 
277 
279  std::vector<RouteReplaceInfo> myReplacedRoutes;
280 
282  std::vector<SUMOTime> myExits;
283 
285  const int myMaxRoutes;
286 
289 
292 
294  double myDepartPos;
295 
298 
301 
303  std::vector<const MSEdge*> myPriorEdges;
304 
306 
307 private:
310 
313 
314 
315 };
long long int SUMOTime
Definition: SUMOTime.h:31
Information about a replaced route.
RouteReplaceInfo(const MSEdge *const edge_, const SUMOTime time_, const MSRoute *const route_, const std::string &info_)
Constructor.
SUMOTime time
The time the route was replaced.
const MSEdge * edge
The edge the vehicle was on when the route was replaced.
const MSRoute * route
The prior route.
std::string info
Information regarding rerouting.
A class that is notified about reroutings.
std::map< const SUMOVehicle *, MSDevice_Vehroutes *, ComparatorNumericalIdLess > myDevices
A map for internal notification.
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
A device which collects info on the vehicle trip (mainly on departure and arrival)
static bool myWriteCosts
A shortcut for the Option "vehroute-output.costs".
static void init()
Static intialization.
std::vector< SUMOTime > myExits
The times the vehicle exites an edge.
static bool mySorted
A shortcut for the Option "vehroute-output.sorted".
static bool myIntendedDepart
A shortcut for the Option "vehroute-output.intended-depart".
static std::map< const SUMOTime, std::map< const std::string, std::string > > myRouteInfos
void addRoute(const std::string &info)
Called on route change.
static bool myIncludeIncomplete
A shortcut for the Option "vehroute-output.incomplete".
void stopEnded(const SUMOVehicleParameter::Stop &stop)
MSDevice_Vehroutes(SUMOVehicle &holder, const std::string &id, int maxRoutes)
Constructor.
static bool myRouteLength
A shortcut for the Option "vehroute-output.route-length".
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
void writeXMLRoute(OutputDevice &os, int index=-1) const
Called on route output.
static std::map< const SUMOTime, int > myDepartureCounts
Map needed to sort vehicles by departure time.
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.
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
std::vector< RouteReplaceInfo > myReplacedRoutes
Prior routes.
std::vector< const MSEdge * > myPriorEdges
the edges that were passed before the current stop
const int myMaxRoutes
The maximum number of routes to report.
MSDevice_Vehroutes & operator=(const MSDevice_Vehroutes &)
Invalidated assignment operator.
static bool myWriteStopPriorEdges
A shortcut for the Option "vehroute-output.stop-edges".
double myDepartPosLat
The lateral depart position.
const MSEdge * myLastSavedAt
The last edge the exit time was saved for.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
OutputDevice_String myStopOut
const std::string deviceName() const
return the name for this type of device
double myDepartPos
The lane the vehicle departed at.
const MSRoute * getRoute(int index) const
Called on route retrieval.
static bool myLastRouteOnly
A shortcut for the Option "vehroute-output.last-route".
double myDepartSpeed
The speed on departure.
MSDevice_Vehroutes(const MSDevice_Vehroutes &)
Invalidated copy constructor.
int myDepartLane
The lane the vehicle departed at.
void writeOutput(const bool hasArrived) const
Called on writing vehroutes output.
~MSDevice_Vehroutes()
Destructor.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Saves exit times if needed.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Does nothing, returns true only if exit times should be collected.
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing vehroutes output.
const MSRoute * myCurrentRoute
The currently used route.
static bool myDUAStyle
A shortcut for the Option "vehroute-output.dua".
static bool mySaveExits
A shortcut for the Option "vehroute-output.exit-times".
void saveState(OutputDevice &out) const
Saves the state of the device.
static StateListener myStateListener
A class that is notified about reroutings.
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Notification
Definition of a vehicle state.
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:620
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:587
Abstract in-vehicle device.
A storage for options typed value containers)
Definition: OptionsCont.h:89
An output device that encapsulates an ofstream.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:58
Definition of vehicle stop (position and duration)