62#define DEBUGCOND (veh.isSelected())
78 const MSEdgeVector& edges,
double prob,
bool off,
bool optional,
79 SUMOTime timeThreshold,
const std::string& vTypes,
const Position& pos,
const double radius) :
85 myUserProbability(prob),
86 myAmInUserMode(false),
87 myAmOptional(optional),
90 myTimeThreshold(timeThreshold),
91 myHaveParkProbs(false) {
94 for (
const MSEdge*
const e : edges) {
98 for (
MSLane*
const lane : e->getLanes()) {
99 lane->addMoveReminder(
this);
140 if (dest ==
"keepDestination") {
142 }
else if (dest ==
"terminateRoute") {
155 throw ProcessError(
TLF(
"rerouter '%': Attribute 'probability' for destination '%' is negative (must not).",
getID(), dest));
165 if (closed ==
nullptr) {
179 if (closed ==
nullptr) {
198 if (routeStr ==
"") {
199 throw ProcessError(
TLF(
"rerouter '%': routeProbReroute has no alternative route id.",
getID()));
202 if (route ==
nullptr) {
203 throw ProcessError(
TLF(
"rerouter '%': Alternative route '%' does not exist.",
getID(), routeStr));
213 throw ProcessError(
TLF(
"rerouter '%': Attribute 'probability' for alternative route '%' is negative (must not).",
getID(), routeStr));
221 if (parkingarea ==
"") {
222 throw ProcessError(
TLF(
"rerouter '%': parkingAreaReroute requires a parkingArea id.",
getID()));
235 throw ProcessError(
TLF(
"rerouter '%': Attribute 'probability' for parkingArea '%' is negative (must not).",
getID(), parkingarea));
250 if (via ==
nullptr) {
260 throw ProcessError(
TLF(
"rerouter '%': Attribute 'probability' for via '%' is negative (must not).",
getID(), viaID));
285 if (closingBegin < simBegin && myParsedRerouteInterval.end > simBegin) {
305 bool updateVehicles =
false;
307 if (i.begin == currentTime && !(i.closed.empty() && i.closedLanes.empty()) && i.permissions !=
SVCAll) {
308 for (
MSEdge*
const e : i.closed) {
309 for (
MSLane* lane : e->getLanes()) {
311 lane->setPermissions(i.permissions, i.id);
313 e->rebuildAllowedLanes();
314 updateVehicles =
true;
316 for (
MSLane*
const lane : i.closedLanes) {
317 lane->setPermissions(i.permissions, i.id);
318 lane->getEdge().rebuildAllowedLanes();
319 updateVehicles =
true;
324 if (i.end == currentTime && !(i.closed.empty() && i.closedLanes.empty()) && i.permissions !=
SVCAll) {
325 for (
MSEdge*
const e : i.closed) {
326 for (
MSLane* lane : e->getLanes()) {
327 lane->resetPermissions(i.id);
330 e->rebuildAllowedLanes();
331 updateVehicles =
true;
333 for (
MSLane* lane : i.closedLanes) {
334 lane->resetPermissions(i.id);
335 lane->getEdge().rebuildAllowedLanes();
336 updateVehicles =
true;
340 if (updateVehicles) {
344 e->rebuildAllowedTargets();
354 if (ri.begin <= time && ri.end > time) {
357 ri.edgeProbs.getOverallProb() > 0 ||
359 ri.routeProbs.getOverallProb() > 0 ||
361 ri.parkProbs.getOverallProb() > 0) {
364 if (!ri.closed.empty() || !ri.closedLanesAffected.empty()) {
365 const std::set<SUMOTrafficObject::NumericalID>& edgeIndices = obj.
getUpcomingEdgeIDs();
366 if (
affected(edgeIndices, ri.closed) ||
affected(edgeIndices, ri.closedLanesAffected)) {
379 if (ri.begin <= time && ri.end > time) {
380 if (ri.edgeProbs.getOverallProb() != 0 || ri.routeProbs.getOverallProb() != 0 || ri.parkProbs.getOverallProb() != 0
381 || !ri.closed.empty() || !ri.closedLanesAffected.empty()) {
421 if (rerouteDef ==
nullptr) {
436 if (rerouteDef->
closedLanes.size() > 0 && !hasReroutingDevice) {
442 std::cout <<
SIMTIME <<
" veh=" << veh.
getID() <<
" check rerouter " <<
getID() <<
" lane=" <<
Named::getIDSecure(veh.getLane()) <<
" edge=" << veh.getEdge()->getID() <<
" finalEdge=" << lastEdge->
getID() <<
" arrivalPos=" << veh.getArrivalPos() <<
"\n";
454 bool newDestination =
false;
457 if (newParkingArea !=
nullptr) {
463 if (newDestination) {
478 const double savings = previousCost - routeCost;
487 std::string errorMsg;
492 +
"' could not reroute to new parkingArea '" + newParkingArea->
getID()
502 if (newRoute !=
nullptr) {
505 std::cout <<
" replacedRoute from routeDist " << newRoute->getID() <<
"\n";
511 const MSEdge* newEdge = lastEdge;
513 double newArrivalPos = -1;
514 const bool destUnreachable = std::find(rerouteDef->
closed.begin(), rerouteDef->
closed.end(), lastEdge) != rerouteDef->
closed.end();
515 bool keepDestination =
false;
518 if (rerouteDef->
closed.empty() || destUnreachable || rerouteDef->
isVia) {
520 assert(newEdge !=
nullptr);
522 keepDestination =
true;
530 WRITE_WARNINGF(
TL(
"Cannot keep destination edge '%' for vehicle '%' due to closed edges. Terminating route."), lastEdge->
getID(), tObject.
getID());
538 std::vector<MSTransportableRouter::TripItem> items;
547 bool ok = veh.
reroute(now,
getID(), router,
false,
false, canChangeDest, newEdge);
548 if (!ok && !keepDestination && canChangeDest) {
552 while (!ok && edgeProbs2.
getVals().size() > 0) {
553 newEdge = edgeProbs2.
get();
563 ok = veh.
reroute(now,
getID(), router,
false,
false,
true, newEdge);
567 if (!rerouteDef->
isVia) {
569 if (
DEBUGCOND) std::cout <<
" rerouting: newDest=" << newEdge->
getID()
571 <<
" useNewRoute=" << useNewRoute <<
" newArrivalPos=" << newArrivalPos <<
" numClosed=" << rerouteDef->
closed.size()
574 if (ok && newArrivalPos != -1) {
588 if (!rerouteDef->
isVia) {
591 if (!it.edges.empty() && !edges.empty() && edges.back() == it.edges.front()) {
594 edges.insert(edges.end(), std::make_move_iterator(it.edges.begin()), std::make_move_iterator(it.edges.end()));
595 if (!edges.empty()) {
607 if (rerouteDef->
isVia) {
610 if (!edges.empty()) {
616 router.
compute(newEdge, lastEdge, &veh, now, edges);
623 if (
DEBUGCOND) std::cout <<
" rerouting: newDest=" << newEdge->
getID()
625 <<
" useNewRoute=" << useNewRoute <<
" newArrivalPos=" << newArrivalPos <<
" numClosed=" << rerouteDef->
closed.size()
628 if (useNewRoute && newArrivalPos != -1) {
634 bool success = !items.empty();
645 if (!it.edges.empty() && !edges.empty() && edges.back() == it.edges.front()) {
648 edges.insert(edges.end(), std::make_move_iterator(it.edges.begin()), std::make_move_iterator(it.edges.end()));
650 if (!edges.empty()) {
695 return dynamic_cast<MSParkingArea*
>(parkingArea)->getOccupancy();
701 return dynamic_cast<MSParkingArea*
>(parkingArea)->getLastStepOccupancy();
763 for (
auto vTypeDist : vTypeDists) {
775 for (
const MSEdge*
const e : closed) {
776 if (edgeIndices.count(e->getNumericalID()) > 0) {
789 std::set<MSEdge*> parkingRerouterEdges;
790 std::map<MSParkingArea*, std::string, ComparatorIdLess> targetedParkingArea;
792 bool hasParkingReroute =
false;
794 if (interval.parkProbs.getOverallProb() > 0) {
795 hasParkingReroute =
true;
797 targetedParkingArea[
dynamic_cast<MSParkingArea*
>(pav.first)] = rr.first;
801 if (hasParkingReroute) {
802 parkingRerouterEdges.insert(rr.second->myEdges.begin(), rr.second->myEdges.end());
805 for (
const auto& item : targetedParkingArea) {
806 if (parkingRerouterEdges.count(&item.first->getLane().getEdge()) == 0) {
807 WRITE_WARNINGF(
TL(
"ParkingArea '%' is targeted by rerouter '%' but doesn't have its own rerouter. This may cause parking search to abort."),
808 item.first->getID(), item.second);
std::vector< const MSEdge * > ConstMSEdgeVector
std::vector< MSEdge * > MSEdgeVector
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::shared_ptr< const MSRoute > ConstMSRoutePtr
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
const SVCPermissions SVCAll
all VClasses are allowed
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
@ SVC_AUTHORITY
authorities vehicles
@ GIVEN
The arrival position is given.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_CLOSING_REROUTE
reroute of type closing
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ SUMO_TAG_VIA_PROB_REROUTE
probability of a via fora reroute
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destination of a reroute
@ SUMO_TAG_CLOSING_LANE_REROUTE
lane of a reroute of type closing
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool compute(const E *from, const E *to, const double departPos, const std::string &originStopID, const double arrivalPos, const std::string &stopID, const double speed, const V *const vehicle, const SVCPermissions modeSet, const SUMOTime msTime, std::vector< TripItem > &into, const double externalFactor=0.)
Builds the route between the given edges using the minimum effort at the given time The definition of...
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
void addDetector(MSMoveReminder *data, int queueIndex=-1)
Adds a data collector for a detector to this segment.
A device that performs vehicle rerouting based on current edge speeds.
A road/street connecting two junctions.
double getLength() const
return the length of the edge
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
static int gNumSimThreads
how many threads to use for simulation
Representation of a lane in the micro simulation.
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
MSTransportableRouter & getIntermodalRouter(const int rngIndex, const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
MSVehicleRouter & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
A lane area vehicles can halt at.
int getCapacity() const
Returns the area capacity.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
bool containsAnyOf(const MSEdgeVector &edgelist) const
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the vehicle router instance
static MSTransportableRouter & getIntermodalRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector())
return the person router instance
A lane area vehicles can halt at.
double getEndLanePosition() const
Returns the end position of this stop.
std::map< std::string, double > StoppingPlaceParamMap_t
MSStoppingPlace * reroute(std::vector< StoppingPlaceVisible > &stoppingPlaceCandidates, const std::vector< double > &probs, SUMOVehicle &veh, bool &newDestination, ConstMSEdgeVector &newRoute, StoppingPlaceParamMap_t &scores, const MSEdgeVector &closedEdges={}, const int insertStopIndex=0, const bool keepCurrentStop=true)
main method to trigger the rerouting to the "best" StoppingPlace according to the custom evaluation f...
std::pair< MSStoppingPlace *, bool > StoppingPlaceVisible
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.
MSTriggeredRerouter(const std::string &id, const MSEdgeVector &edges, double prob, bool off, bool optional, SUMOTime timeThreshold, const std::string &vTypes, const Position &pos, const double radius)
Constructor.
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
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.
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.
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.
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.
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
const std::string & getOriginalID() const
Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise.
Base class for objects which have an id.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const std::string & getID() const
Returns the id.
static OptionsCont & getOptions()
Retrieves the options.
A point in 2D or 3D with translation and scaling methods.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Represents a generic random distribution.
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
T get(SumoRNG *which=nullptr) const
Draw a sample of the distribution.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.
bool remove(T val)
Removes a value with an assigned probability from the distribution.
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
Representation of a vehicle, person, or container.
virtual bool isVehicle() const
Whether it is a vehicle.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual int getRNGIndex() const =0
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true, std::string *msgReturn=nullptr)=0
Replaces the current route by the given one.
virtual SUMOTime getWaitingTime(const bool accumulated=false) const =0
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual double getMaxSpeed() const =0
Returns the object's maximum speed (minimum of technical and desired maximum speed)
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual SumoRNG * getRNG() const =0
Returns the associated RNG for this object.
virtual const std::set< NumericalID > getUpcomingEdgeIDs() const =0
returns the numerical IDs of edges to be used (possibly of future stages)
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual const MSEdge * getRerouteDestination() const =0
Returns the end point for reroutes (usually the last edge of the route)
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
virtual bool reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false, const MSEdge *sink=nullptr)=0
Performs a rerouting using the given router.
virtual SUMOTime sawBlockedParkingArea(const MSStoppingPlace *pa, bool local) const =0
virtual bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)=0
Replaces the current route by the given edges.
virtual bool replaceParkingArea(MSParkingArea *parkingArea, std::string &errorMsg)=0
Replaces a stop.
virtual MSParkingArea * getNextParkingArea()=0
virtual void rememberParkingAreaScore(const MSStoppingPlace *pa, const std::string &score)=0
virtual void rememberBlockedParkingArea(const MSStoppingPlace *pa, bool local)=0
virtual int getNumberParkingReroutes() const =0
virtual const std::vector< MSTransportable * > & getPersons() const =0
retrieve riding persons
virtual void replaceParameter(const SUMOVehicleParameter *newParameter)=0
Replaces the vehicle's parameter.
virtual void resetParkingAreaScores()=0
virtual void setArrivalPos(double arrivalPos)=0
Sets this vehicle's desired arrivalPos for its current route.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual void setNumberParkingReroutes(int value)=0
virtual const MSRoute & getRoute() const =0
Returns the current route.
Structure representing possible vehicle parameter.
double arrivalPos
(optional) The position the vehicle shall arrive on
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
A scoped lock which only triggers on condition.
std::vector< std::string > getVector()
return vector of strings
A wrapper for a Command function.
SUMOTime begin
The begin time these definitions are valid.
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.