Eclipse SUMO - Simulation of Urban MObility
MSTriggeredRerouter.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 /****************************************************************************/
21 // Reroutes vehicles passing an edge
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <string>
27 #include <vector>
28 #include <utils/common/Command.h>
30 #include "MSTrigger.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSNet;
39 class MSLane;
40 class MSRoute;
41 class SUMOVehicle;
42 class MSParkingArea;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
60  public MSTrigger, public MSMoveReminder,
61  public SUMOSAXHandler {
62 
63  friend class GUIEdge; // dynamic instantiation
64 
65 public:
73  MSTriggeredRerouter(const std::string& id,
74  const MSEdgeVector& edges,
75  double prob, const std::string& file, bool off,
76  SUMOTime timeThreshold,
77  const std::string& vTypes);
78 
79 
81  virtual ~MSTriggeredRerouter();
82 
83  typedef std::pair<MSParkingArea*, bool> ParkingAreaVisible;
84 
89  struct RerouteInterval {
91  long long id;
99  std::vector<MSLane*> closedLanes;
110  };
111 
126  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
127 
130 
139  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
140 
149  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
150 
152  const RerouteInterval* getCurrentReroute(SUMOTime time, SUMOVehicle& veh) const;
153 
155  SUMOTime setPermissions(const SUMOTime currentTime);
156 
158  const RerouteInterval* getCurrentReroute(SUMOTime time) const;
159 
161  void setUserMode(bool val);
162 
164  void setUserUsageProbability(double prob);
165 
167  bool inUserMode() const;
168 
170  double getProbability() const;
171 
173  double getUserProbability() const;
174 
175  double getWeight(SUMOVehicle& veh, const std::string param, const double defaultWeight) const;
176 
178  SUMOVehicle& veh, bool& newDestination, ConstMSEdgeVector& newRoute) const;
179 
181  static const std::map<std::string, MSTriggeredRerouter*>& getInstances() {
182  return myInstances;
183  }
184 
186  static void checkParkingRerouteConsistency();
187 
188 protected:
190 
191 
199  virtual void myStartElement(int element,
200  const SUMOSAXAttributes& attrs);
201 
202 
209  virtual void myEndElement(int element);
211 
217  bool vehicleApplies(const SUMOVehicle& veh) const;
218 
219  typedef std::map<std::string, double> ParkingParamMap_t;
220  typedef std::map<MSParkingArea*, ParkingParamMap_t, ComparatorIdLess> MSParkingAreaMap_t;
221 
223  bool addParkValues(SUMOVehicle& veh, double brakeGap, bool newDestination,
224  MSParkingArea* pa, double paOccupancy, double prob,
226  MSParkingAreaMap_t& parkAreas,
227  std::map<MSParkingArea*, ConstMSEdgeVector>& newRoutes,
228  std::map<MSParkingArea*, ConstMSEdgeVector>& parkApproaches,
229  ParkingParamMap_t& maxValues) const;
230 
231 protected:
234 
236  std::vector<RerouteInterval> myIntervals;
237 
240 
243 
244  // @brief waiting time threshold for activation
246 
248  std::set<std::string> myVehicleTypes;
249 
251 
252 
258  std::vector<MSLane*> myCurrentClosedLanes;
268 
269 
273 
274  static std::map<std::string, MSTriggeredRerouter*> myInstances;
275 
276 private:
279 
282 
283 
284 };
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
long long int SUMOTime
Definition: SUMOTime.h:32
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:50
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
The simulated network and simulation perfomer.
Definition: MSNet.h:88
A lane area vehicles can halt at.
Definition: MSParkingArea.h:58
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:38
Reroutes vehicles passing an edge.
SUMOTime setPermissions(const SUMOTime currentTime)
Sets the edge permission if there are any defined in the closingEdge.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Tries to reroute the vehicle.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Triggers rerouting (once) for vehicles that are already on the edge when the rerouter activates.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes the reminder.
RandomDistributor< ParkingAreaVisible > myCurrentParkProb
new destinations with probabilities
double getUserProbability() const
Returns the rerouting probability given by the user.
std::vector< MSLane * > myCurrentClosedLanes
List of closed lanes.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
MSTriggeredRerouter & operator=(const MSTriggeredRerouter &)
Invalidated assignment operator.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
void setUserUsageProbability(double prob)
Sets the probability with which a vehicle is rerouted given by the user.
SVCPermissions myCurrentPermissions
List of permissions for closed edges.
MSParkingArea * rerouteParkingArea(const MSTriggeredRerouter::RerouteInterval *rerouteDef, SUMOVehicle &veh, bool &newDestination, ConstMSEdgeVector &newRoute) const
static MSEdge mySpecialDest_terminateRoute
virtual void myEndElement(int element)
Called when a closing tag occurs.
bool addParkValues(SUMOVehicle &veh, double brakeGap, bool newDestination, MSParkingArea *pa, double paOccupancy, double prob, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, MSParkingAreaMap_t &parkAreas, std::map< MSParkingArea *, ConstMSEdgeVector > &newRoutes, std::map< MSParkingArea *, ConstMSEdgeVector > &parkApproaches, ParkingParamMap_t &maxValues) const
determine attributes of candiate parking area for scoring
const RerouteInterval * getCurrentReroute(SUMOTime time, SUMOVehicle &veh) const
Returns the rerouting definition valid for the given time and vehicle, 0 if none.
std::pair< MSParkingArea *, bool > ParkingAreaVisible
double myProbability
The probability and the user-given probability.
virtual ~MSTriggeredRerouter()
Destructor.
MSTriggeredRerouter(const MSTriggeredRerouter &)
Invalidated copy constructor.
bool inUserMode() const
Returns whether the user is setting the rerouting probability.
std::map< std::string, double > ParkingParamMap_t
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
MSEdgeVector myCurrentClosed
List of closed edges.
static void checkParkingRerouteConsistency()
issues warning for incomplete parkingReroute relationships
RandomDistributor< MSEdge * > myCurrentEdgeProb
new destinations with probabilities
static std::map< std::string, MSTriggeredRerouter * > myInstances
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
double getWeight(SUMOVehicle &veh, const std::string param, const double defaultWeight) const
SUMOTime myCurrentIntervalBegin
The first and the last time steps of the interval.
MSTriggeredRerouter(const std::string &id, const MSEdgeVector &edges, double prob, const std::string &file, bool off, SUMOTime timeThreshold, const std::string &vTypes)
Constructor.
bool myAmInUserMode
Information whether the current rerouting probability is the user-given.
const MSEdgeVector myEdges
edges where vehicles are notified
RandomDistributor< const MSRoute * > myCurrentRouteProb
new routes with probabilities
static MSEdge mySpecialDest_keepDestination
special destination values
double getProbability() const
Returns the rerouting probability.
std::map< MSParkingArea *, ParkingParamMap_t, ComparatorIdLess > MSParkingAreaMap_t
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
void setUserMode(bool val)
Sets whether the process is currently steered by the user.
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
SUMOTime begin
The begin time these definitions are valid.
SUMOTime end
The end time these definitions are valid.
RandomDistributor< MSEdge * > edgeProbs
The distributions of new destinations to use.
RandomDistributor< const MSRoute * > routeProbs
The distributions of new routes to use.
MSEdgeVector closedLanesAffected
The list of edges that are affect by closed lanes.
RandomDistributor< ParkingAreaVisible > parkProbs
The distributions of new parking areas to use as destinations.
long long id
unique ID for this interval
SVCPermissions permissions
The permissions to use.
MSEdgeVector closed
The list of closed edges.
std::vector< MSLane * > closedLanes
The list of closed lanes.