Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2025 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 <map>
30#include <utils/common/Named.h>
35
36
37// ===========================================================================
38// class declarations
39// ===========================================================================
40class MSNet;
41class MSLane;
42class MSRoute;
43class SUMOVehicle;
44class MSBaseVehicle;
45class MSParkingArea;
46class MSRailSignal;
47
48
49// ===========================================================================
50// class definitions
51// ===========================================================================
64 public Named, public MSMoveReminder,
66
67 friend class GUIEdge; // dynamic instantiation
68
69public:
76 MSTriggeredRerouter(const std::string& id, const MSEdgeVector& edges,
77 double prob, bool off, bool optional, SUMOTime timeThreshold,
78 const std::string& vTypes, const Position& pos, const double radius);
79
80
82 virtual ~MSTriggeredRerouter();
83
84 typedef std::map<const MSEdge*, RouterProhibition> Prohibitions;
85
106
113 long long int id;
119 std::map<MSEdge*, std::pair<SVCPermissions, double> > closed;
121 std::map<MSLane*, SVCPermissions> closedLanes;
131 bool isVia = false;
134
137 std::vector<OvertakeLocation> overtakeLocations;
138 //}
139
142 std::vector<MSStoppingPlaceRerouter::StoppingPlaceVisible> stopAlternatives;
143 //}
144
146 Prohibitions v;
147 for (const auto& settings : closed) {
148 // no permissions are changed but edges are forbidden for all during routing
149 v[settings.first].permissions = settings.second.first == SVCAll ? 0 : settings.second.first;
150 if (settings.second.second != -1) {
151 // end time is known
152 v[settings.first].end = STEPS2TIME(settings.second.second);
153 }
154 }
155 return v;
156 }
157
159 MSEdgeVector v;
160 for (const auto& settings : closed) {
161 v.push_back(settings.first);
162 }
163 return v;
164 }
165 };
166
181 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
182
185
194 bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
195
204 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
205
207
209 const RerouteInterval* getCurrentReroute(SUMOTime time, SUMOTrafficObject& obj) const;
210
212 SUMOTime setPermissions(const SUMOTime currentTime);
213
215 const RerouteInterval* getCurrentReroute(SUMOTime time) const;
216
218 void setUserMode(bool val);
219
221 void setUserUsageProbability(double prob);
222
224 bool inUserMode() const;
225
227 double getProbability() const;
228
230 double getUserProbability() const;
231
232 // @brief return whether this moveReminder triggers parking reroute
233 bool isParkingRerouter() const {
234 return myHaveParkProbs;
235 }
236
238 return myPosition;
239 }
240
243
246
249
251 void rememberBlockedStoppingPlace(SUMOVehicle& veh, const MSStoppingPlace* parkingArea, bool blocked);
252
254 void rememberStoppingPlaceScore(SUMOVehicle& veh, MSStoppingPlace* parkingArea, const std::string& score);
255
258
260 SUMOTime sawBlockedStoppingPlace(SUMOVehicle& veh, MSStoppingPlace* parkingArea, bool local);
261
264
266 void setNumberStoppingPlaceReroutes(SUMOVehicle& veh, int value);
267
270 SUMOVehicle& veh, bool& newDestination, ConstMSEdgeVector& newRoute);
271
273 std::pair<const SUMOVehicle*, MSRailSignal*> overtakingTrain(
274 const SUMOVehicle& veh,
275 ConstMSEdgeVector::const_iterator mainStart,
276 const OvertakeLocation& oloc,
277 double& netSaving);
278
281
283 static MSRailSignal* findSignal(ConstMSEdgeVector::const_iterator begin, ConstMSEdgeVector::const_iterator end);
284
286 static MSRailSignal* getRailSignal(const MSEdge* edge);
287
289 static const std::map<std::string, MSTriggeredRerouter*>& getInstances() {
290 return myInstances;
291 }
292
294 static void checkParkingRerouteConsistency();
295
297 static double getEvalDefaultWeight(std::string& paramName) {
298 if (paramName == "") {
299 return 1.;
300 }
301 return 0.;
302 }
303
304 static const double DEFAULT_MAXDELAY;
305
306protected:
308
309
317 virtual void myStartElement(int element,
318 const SUMOSAXAttributes& attrs);
319
320
327 virtual void myEndElement(int element);
329
335 bool applies(const SUMOTrafficObject& obj) const;
336
338 void resetClosedEdges(bool hasReroutingDevice, const SUMOTrafficObject& o);
339
340 static bool affected(const std::set<SUMOTrafficObject::NumericalID>& edgeIndices, const MSEdgeVector& closed);
341
342protected:
345
347 std::vector<RerouteInterval> myIntervals;
348
351
354
357
360
362 double myRadius;
363
364 // @brief waiting time threshold for activation
366
368 std::set<std::string> myVehicleTypes;
369
372
375
376 std::set<const MSStoppingPlace*> myBlockedStoppingPlaces;
377
381
382 static std::map<std::string, MSTriggeredRerouter*> myInstances;
383
384private:
387
390
391
392};
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
#define STEPS2TIME(x)
Definition SUMOTime.h:55
const SVCPermissions SVCAll
all VClasses are allowed
A road/street connecting two junctions (gui-version)
Definition GUIEdge.h:51
The base class for microscopic and mesoscopic vehicles.
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.
A signal for rails.
A lane area vehicles can halt at.
Reroutes traffic objects 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.
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.
static MSRailSignal * findSignal(ConstMSEdgeVector::const_iterator begin, ConstMSEdgeVector::const_iterator end)
find the last downstream signal on the given route
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes the reminder.
double getUserProbability() const
Returns the rerouting probability given by the user.
static const double DEFAULT_MAXDELAY
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.
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.
std::pair< const SUMOVehicle *, MSRailSignal * > overtakingTrain(const SUMOVehicle &veh, ConstMSEdgeVector::const_iterator mainStart, const OvertakeLocation &oloc, double &netSaving)
determine whether veh should switch from main to siding to be overtaken and return the overtaking veh...
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
double getStoppingPlaceOccupancy(MSStoppingPlace *sp)
Return the number of occupied places of the stopping place.
static MSEdge mySpecialDest_terminateRoute
virtual void myEndElement(int element)
Called when a closing tag occurs.
void checkStopSwitch(MSBaseVehicle &veh, const MSTriggeredRerouter::RerouteInterval *def)
consider switching the location of the upcoming stop
void resetClosedEdges(bool hasReroutingDevice, const SUMOTrafficObject &o)
reset router after closing edges
bool triggerRouting(SUMOTrafficObject &veh, MSMoveReminder::Notification reason)
double myRadius
At which distance are we activated.
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< const MSStoppingPlace * > myBlockedStoppingPlaces
double getStoppingPlaceCapacity(MSStoppingPlace *sp)
Return the number of places the stopping place provides.
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
double getLastStepStoppingPlaceOccupancy(MSStoppingPlace *sp)
Return the number of occupied places of the stopping place from the previous time step.
static std::map< std::string, MSTriggeredRerouter * > myInstances
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
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.
static MSRailSignal * getRailSignal(const MSEdge *edge)
return railsignal at that edge or nullptr
const MSEdgeVector myEdges
edges where vehicles are notified
std::map< const MSEdge *, RouterProhibition > Prohibitions
MSTriggeredRerouter & operator=(const MSTriggeredRerouter &)
Invalidated assignment operator.
static MSEdge mySpecialDest_keepDestination
special destination values
RerouteInterval myParsedRerouteInterval
used during loading
double getProbability() const
Returns the rerouting probability.
const Position & getPosition()
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
Represents a generic random distribution.
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition SUMOVehicle.h:62
double sidingLength
The usable length of the siding.
MSEdgeVector main
The list of main edges (const and non-const for different usage)
bool defer
whether the decision to use this siding should be deferred
double minSaving
The threshold in savings for triggering reroute.
MSEdgeVector siding
The list of siding edges.
MSRailSignal * sidingExit
The rail signal at the end of the siding.
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.
std::vector< MSStoppingPlaceRerouter::StoppingPlaceVisible > stopAlternatives
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.
std::map< MSLane *, SVCPermissions > closedLanes
The list of closed lanes to their permissions.
bool isVia
The edge probs are vias and not destinations.
MSEdgeVector closedLanesAffected
The list of edges that are affected by closed lanes.
bool permissionsAllowAll
The permissions are all SVCAll.
std::map< MSEdge *, std::pair< SVCPermissions, double > > closed
The map of closed edges to their permissions and expected end of closing.
std::vector< OvertakeLocation > overtakeLocations