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.dev/sumo
3 // Copyright (C) 2009-2024 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 writePendingOutput(const bool includeUnfinished);
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 notifyStopEnded();
118 
123  void generateOutput(OutputDevice* tripinfoOut) const;
124 
125 
131  ConstMSRoutePtr getRoute(int index) const;
132 
133 
138  void saveState(OutputDevice& out) const;
139 
144  void loadState(const SUMOSAXAttributes& attrs);
145 
149  OutputDevice* routeOut = nullptr;
150 
152  std::map<const SUMOTime, int> departureCounts;
153 
155  std::map<const SUMOTime, std::map<const std::string, std::string> > routeXML;
156  };
157 
158  static void registerTransportableDepart(SUMOTime depart);
159  static void writeSortedOutput(SortedRouteInfo* routeInfo, SUMOTime depart, const std::string& id, const std::string& xmlOutput);
160 
161 private:
167  MSDevice_Vehroutes(SUMOVehicle& holder, const std::string& id, int maxRoutes);
168 
169 
175  void writeXMLRoute(OutputDevice& os, int index = -1) const;
176 
177 
183  void writeOutput(const bool hasArrived) const;
184 
185 
188  void addRoute(const std::string& info);
189 
190 private:
192  static bool mySaveExits;
193 
195  static bool myLastRouteOnly;
196 
198  static bool myDUAStyle;
199 
201  static bool myWriteCosts;
202 
204  static bool mySorted;
205 
207  static bool myIntendedDepart;
208 
210  static bool myRouteLength;
211 
213  static bool mySkipPTLines;
214 
216  static bool myIncludeIncomplete;
217 
220 
222  static bool myWriteInternal;
223 
228  public:
231 
236  void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
237 
239  std::map<const SUMOVehicle*, MSDevice_Vehroutes*, ComparatorNumericalIdLess> myDevices;
240 
241  };
242 
243 
246 
249 
250 
261  public:
267  RouteReplaceInfo(const MSEdge* const edge_, const SUMOTime time_, ConstMSRoutePtr const route_,
268  const std::string& info_, int lastRouteIndex_, int newRouteIndex_) :
269  edge(edge_), time(time_), route(route_), info(info_),
270  lastRouteIndex(lastRouteIndex_),
271  newRouteIndex(newRouteIndex_)
272  {}
273 
276 
278  const MSEdge* edge;
279 
282 
285 
287  std::string info;
288 
290  // (vehicle may or may not have driven to the end of it)
292 
294  // (new route may or may not include prior driven route edges)
296 
297  };
298 
301 
303  std::vector<RouteReplaceInfo> myReplacedRoutes;
304 
306  std::vector<SUMOTime> myExits;
307 
309  const int myMaxRoutes;
310 
313 
316 
319 
321  double myDepartPos;
322 
325 
328 
330  std::vector<const MSEdge*> myPriorEdges;
331 
333 
334 private:
337 
340 
341 
342 };
long long int SUMOTime
Definition: GUI.h:35
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
Information about a replaced route.
int lastRouteIndex
The last index in the replaced route.
ConstMSRoutePtr route
The prior route.
RouteReplaceInfo(const MSEdge *const edge_, const SUMOTime time_, ConstMSRoutePtr const route_, const std::string &info_, int lastRouteIndex_, int newRouteIndex_)
Constructor.
SUMOTime time
The time the route was replaced.
int newRouteIndex
The current index in the replacement route.
const MSEdge * edge
The edge the vehicle was on when the route was replaced.
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 writeSortedOutput(SortedRouteInfo *routeInfo, SUMOTime depart, const std::string &id, const std::string &xmlOutput)
static void init()
Static intialization.
std::vector< SUMOTime > myExits
The times at which the vehicle exits 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".
void addRoute(const std::string &info)
Called on route change.
int myLastRouteIndex
The route index of the last edge that the vehicle left.
static bool myIncludeIncomplete
A shortcut for the Option "vehroute-output.incomplete".
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.
ConstMSRoutePtr getRoute(int index) const
Called on route retrieval.
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.
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.
static void writePendingOutput(const bool includeUnfinished)
generate vehroute output for pending vehicles at sim end, either due to sorting or because they are s...
static bool myLastRouteOnly
A shortcut for the Option "vehroute-output.last-route".
ConstMSRoutePtr myCurrentRoute
The currently used route.
double myDepartSpeed
The speed on departure.
MSDevice_Vehroutes(const MSDevice_Vehroutes &)
Invalidated copy constructor.
int myDepartLane
The lane the vehicle departed at.
static SortedRouteInfo myRouteInfos
Information needed to sort vehicles by departure time.
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 myWriteInternal
A shortcut for the Option "vehroute-output.internal".
static bool mySkipPTLines
A shortcut for the Option "vehroute-output.skip-ptlines".
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing vehroutes output.
void notifyStopEnded()
called to update state for stopped vehicles
static bool myDUAStyle
A shortcut for the Option "vehroute-output.dua".
static bool mySaveExits
A shortcut for the Option "vehroute-output.exit-times".
static void registerTransportableDepart(SUMOTime depart)
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:84
Notification
Definition of a vehicle state.
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:635
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:602
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:61
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Information needed to sort vehicle / transportable output by departure time.
std::map< const SUMOTime, int > departureCounts
Map needed to sort vehicles by departure time.
std::map< const SUMOTime, std::map< const std::string, std::string > > routeXML
pregenerated route output sorted by time
OutputDevice * routeOut
route output device