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.dev/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
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>
29 #include <utils/common/Named.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSNet;
40 class MSLane;
41 class MSRoute;
42 class SUMOVehicle;
43 class MSParkingArea;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
61  public Named, public MSMoveReminder,
63 
64  friend class GUIEdge; // dynamic instantiation
65 
66 public:
73  MSTriggeredRerouter(const std::string& id, const MSEdgeVector& edges,
74  double prob, bool off, bool optional, SUMOTime timeThreshold,
75  const std::string& vTypes, const Position& pos);
76 
77 
79  virtual ~MSTriggeredRerouter();
80 
81  //typedef std::pair<MSParkingArea*, bool> ParkingAreaVisible;
82 
87  struct RerouteInterval {
89  long long int id;
97  std::vector<MSLane*> closedLanes;
107  //RandomDistributor<ParkingAreaVisible> parkProbs;
110  bool isVia = false;
111  };
112 
127  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
128 
131 
140  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
141 
150  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
151 
153 
156 
158  SUMOTime setPermissions(const SUMOTime currentTime);
159 
161  const RerouteInterval* getCurrentReroute(SUMOTime time) const;
162 
164  void setUserMode(bool val);
165 
167  void setUserUsageProbability(double prob);
168 
170  bool inUserMode() const;
171 
173  double getProbability() const;
174 
176  double getUserProbability() const;
177 
178  // @brief return whether this moveReminder triggers parking reroute
179  bool isParkingRerouter() const {
180  return myHaveParkProbs;
181  }
182 
184  return myPosition;
185  }
186 
188  double getStoppingPlaceOccupancy(MSStoppingPlace* parkingArea);
189 
192 
194  double getStoppingPlaceCapacity(MSStoppingPlace* parkingArea);
195 
197  void rememberBlockedStoppingPlace(SUMOVehicle& veh, const MSStoppingPlace* parkingArea, bool blocked);
198 
200  void rememberStoppingPlaceScore(SUMOVehicle& veh, MSStoppingPlace* parkingArea, const std::string& score);
201 
204 
206  SUMOTime sawBlockedStoppingPlace(SUMOVehicle& veh, MSStoppingPlace* parkingArea, bool local);
207 
210 
212  void setNumberStoppingPlaceReroutes(SUMOVehicle& veh, int value);
213 
216  SUMOVehicle& veh, bool& newDestination, ConstMSEdgeVector& newRoute);
217 
219  static const std::map<std::string, MSTriggeredRerouter*>& getInstances() {
220  return myInstances;
221  }
222 
224  static void checkParkingRerouteConsistency();
225 
227  static double getEvalDefaultWeight(std::string& paramName) {
228  if (paramName == "") {
229  return 1.;
230  }
231  return 0.;
232  }
233 
234 protected:
236 
237 
245  virtual void myStartElement(int element,
246  const SUMOSAXAttributes& attrs);
247 
248 
255  virtual void myEndElement(int element);
257 
263  bool applies(const SUMOTrafficObject& obj) const;
264 
265  static bool affected(const std::set<SUMOTrafficObject::NumericalID>& edgeIndices, const MSEdgeVector& closed);
266 
267 protected:
270 
272  std::vector<RerouteInterval> myIntervals;
273 
276 
279 
282 
285 
286  // @brief waiting time threshold for activation
288 
290  std::set<std::string> myVehicleTypes;
291 
294 
297 
301 
302  static std::map<std::string, MSTriggeredRerouter*> myInstances;
303 
304 private:
307 
310 
311 
312 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
long long 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:51
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
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:89
A lane area vehicles can halt at.
Definition: MSParkingArea.h:60
A lane area vehicles can halt at.
Reroutes traffic objects passing an edge.
bool isParkingRerouter() const
SUMOTime setPermissions(const SUMOTime currentTime)
Sets the edge permission if there are any defined in the closingEdge.
double getStoppingPlaceCapacity(MSStoppingPlace *parkingArea)
Return the number of places the ParkingArea provides.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Tries to reroute the vehicle.
int getNumberStoppingPlaceReroutes(SUMOVehicle &veh)
ask how many times already the vehicle has been rerouted to another stopping place
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.
const Position & getPosition()
double getUserProbability() const
Returns the rerouting probability given by the user.
MSParkingArea * rerouteParkingArea(const MSTriggeredRerouter::RerouteInterval *rerouteDef, SUMOVehicle &veh, bool &newDestination, ConstMSEdgeVector &newRoute)
search for an alternative ParkingArea
bool myHaveParkProbs
whether this rerouter has loaded parkingReroute definitions
static double getEvalDefaultWeight(std::string &paramName)
provide default values for evaluation components
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool myAmOptional
Information whether the rerouting will only take place on request.
MSTriggeredRerouter & operator=(const MSTriggeredRerouter &)
Invalidated assignment operator.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
static bool affected(const std::set< SUMOTrafficObject::NumericalID > &edgeIndices, const MSEdgeVector &closed)
void setUserUsageProbability(double prob)
Sets the probability with which a vehicle is rerouted given by the user.
Position myPosition
Where are we located in the network.
void rememberStoppingPlaceScore(SUMOVehicle &veh, MSStoppingPlace *parkingArea, const std::string &score)
store the score of the ParkingArea in the vehicle
void rememberBlockedStoppingPlace(SUMOVehicle &veh, const MSStoppingPlace *parkingArea, bool blocked)
store the blocked ParkingArea in the vehicle
static MSEdge mySpecialDest_terminateRoute
virtual void myEndElement(int element)
Called when a closing tag occurs.
MSTriggeredRerouter(const std::string &id, const MSEdgeVector &edges, double prob, bool off, bool optional, SUMOTime timeThreshold, const std::string &vTypes, const Position &pos)
Constructor.
bool triggerRouting(SUMOTrafficObject &veh, MSMoveReminder::Notification reason)
void resetStoppingPlaceScores(SUMOVehicle &veh)
reset all stored ParkingArea scores for this vehicle
double myProbability
The probability and the user-given probability.
SUMOTime sawBlockedStoppingPlace(SUMOVehicle &veh, MSStoppingPlace *parkingArea, bool local)
get the time the ParkingArea was considered full from this vehicle
virtual ~MSTriggeredRerouter()
Destructor.
MSTriggeredRerouter(const MSTriggeredRerouter &)
Invalidated copy constructor.
bool inUserMode() const
Returns whether the user is setting the rerouting probability.
void setNumberStoppingPlaceReroutes(SUMOVehicle &veh, int value)
update the number of reroutes for the vehicle
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
const RerouteInterval * getCurrentReroute(SUMOTime time, SUMOTrafficObject &obj) const
Returns the rerouting definition valid for the given time and object, nullptr if none.
static void checkParkingRerouteConsistency()
issues warning for incomplete parkingReroute relationships
static std::map< std::string, MSTriggeredRerouter * > myInstances
bool applies(const SUMOTrafficObject &obj) const
Checks whether the detector measures objects of the given type.
bool myAmInUserMode
Information whether the current rerouting probability is the user-given.
const MSEdgeVector myEdges
edges where vehicles are notified
double getLastStepStoppingPlaceOccupancy(MSStoppingPlace *parkingArea)
Return the number of occupied places of the StoppingPlace from the previous time step.
static MSEdge mySpecialDest_keepDestination
special destination values
RerouteInterval myParsedRerouteInterval
used during loading
double getStoppingPlaceOccupancy(MSStoppingPlace *parkingArea)
Return the number of occupied places of the ParkingArea.
double getProbability() const
Returns the rerouting probability.
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
void setUserMode(bool val)
Sets whether the process is currently steered by the user.
Base class for objects which have an id.
Definition: Named.h:54
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:62
SUMOTime begin
The begin time these definitions are valid.
long long int id
unique ID for this interval
RandomDistributor< MSStoppingPlaceRerouter::StoppingPlaceVisible > parkProbs
The distributions of new parking areas to use as destinations.
RandomDistributor< ConstMSRoutePtr > routeProbs
The distributions of new routes to use.
SUMOTime end
The end time these definitions are valid.
RandomDistributor< MSEdge * > edgeProbs
The distributions of new destinations or vias to use.
bool isVia
The edge probs are vias and not destinations.
MSEdgeVector closedLanesAffected
The list of edges that are affect by closed lanes.
SVCPermissions permissions
The permissions to use.
MSEdgeVector closed
The list of closed edges.
std::vector< MSLane * > closedLanes
The list of closed lanes.