60 #define DEBUGCOND (veh.isSelected()) 73 double prob,
const std::string& file,
bool off,
75 const std::string& vTypes) :
80 myUserProbability(prob),
81 myAmInUserMode(false),
82 myTimeThreshold(timeThreshold) {
84 for (MSEdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
90 const std::vector<MSLane*>& destLanes = (*j)->getLanes();
91 for (std::vector<MSLane*>::const_iterator i = destLanes.begin(); i != destLanes.end(); ++i) {
92 (*i)->addMoveReminder(
this);
121 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": No destination edge id given.");
125 if (dest ==
"keepDestination") {
127 }
else if (dest ==
"terminateRoute") {
130 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Destination edge '" + dest +
"' is not known.");
140 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for destination '" + dest +
"' is negative (must not).");
151 if (closed ==
nullptr) {
152 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Edge '" + closed_id +
"' to close is not known.");
165 if (closed ==
nullptr) {
166 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Lane '" + closed_id +
"' to close is not known.");
185 if (routeStr ==
"") {
189 if (route ==
nullptr) {
190 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Route '" + routeStr +
"' does not exist.");
200 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for route '" + routeStr +
"' is negative (must not).");
210 if (parkingarea ==
"") {
211 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": No parking area id given.");
215 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Parking area '" + parkingarea +
"' is not known.");
224 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for destination '" + parkingarea +
"' is negative (must not).");
249 std::set<MSEdge*> affected;
251 affected.insert(&((*l)->getEdge()));
276 if (i->begin == currentTime && !(i->closed.empty() && i->closedLanes.empty()) && i->permissions !=
SVCAll) {
277 for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
278 for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l) {
280 (*l)->setPermissions(i->permissions, i->id);
282 (*e)->rebuildAllowedLanes();
284 for (std::vector<MSLane*>::iterator l = i->closedLanes.begin(); l != i->closedLanes.end(); ++l) {
285 (*l)->setPermissions(i->permissions, i->id);
286 (*l)->getEdge().rebuildAllowedLanes();
291 if (i->end == currentTime && !(i->closed.empty() && i->closedLanes.empty()) && i->permissions !=
SVCAll) {
292 for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
293 for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l) {
294 (*l)->resetPermissions(i->id);
297 (*e)->rebuildAllowedLanes();
299 for (std::vector<MSLane*>::iterator l = i->closedLanes.begin(); l != i->closedLanes.end(); ++l) {
300 (*l)->resetPermissions(i->id);
301 (*l)->getEdge().rebuildAllowedLanes();
312 if (i->begin <= time && i->end > time) {
315 i->edgeProbs.getOverallProb() > 0 ||
317 i->routeProbs.getOverallProb() > 0 ||
319 i->parkProbs.getOverallProb() > 0 ||
335 if (i->begin <= time && i->end > time) {
336 if (i->parkProbs.getOverallProb() != 0 || i->edgeProbs.getOverallProb() != 0 || i->routeProbs.getOverallProb() != 0 || !i->closed.empty()) {
367 if (rerouteDef ==
nullptr) {
379 if (rerouteDef->
closedLanes.size() > 0 && !hasReroutingDevice) {
385 #ifdef DEBUG_REROUTER 392 bool newDestination =
false;
394 if (newParkingArea !=
nullptr) {
407 if (!newDestination) {
412 p->rerouteParkingArea(veh.getNextParkingArea(), newParkingArea);
418 if (edgesFromPark.size() > 0) {
419 edges.insert(edges.end(), edgesFromPark.begin() + 1, edgesFromPark.end());
422 if (newDestination) {
427 veh.replaceParameter(newParameter);
432 const double savings = previousCost - routeCost;
437 veh.replaceRouteEdges(edges, routeCost, savings,
getID(),
false,
false,
false);
438 std::string errorMsg;
439 if (!veh.replaceParkingArea(newParkingArea, errorMsg)) {
441 +
"' could not reroute to new parkingArea '" + newParkingArea->
getID()
451 if (newRoute !=
nullptr) {
452 #ifdef DEBUG_REROUTER 454 std::cout <<
" replacedRoute from routeDist " << newRoute->
getID() <<
"\n";
460 const MSEdge* newEdge = lastEdge;
462 double newArrivalPos = -1;
463 const bool destUnreachable = std::find(rerouteDef->
closed.begin(), rerouteDef->
closed.end(), lastEdge) != rerouteDef->
closed.end();
466 if (rerouteDef->
closed.size() == 0 || destUnreachable) {
476 WRITE_WARNING(
"Cannot keep destination edge '" + lastEdge->
getID() +
"' for vehicle '" + veh.
getID() +
"' due to closed edges. Terminating route.");
481 }
else if (newEdge ==
nullptr) {
482 #ifdef DEBUG_REROUTER 484 std::cout <<
" could not find new edge!\n";
500 const bool useNewRoute = veh.replaceRouteEdges(edges, routeCost, 0,
getID());
501 #ifdef DEBUG_REROUTER 502 if (
DEBUGCOND) std::cout <<
" rerouting: newEdge=" << newEdge->
getID() <<
" useNewRoute=" << useNewRoute <<
" newArrivalPos=" << newArrivalPos <<
" numClosed=" << rerouteDef->
closed.size()
503 <<
" destUnreachable=" << destUnreachable <<
" containsClosed=" << veh.getRoute().containsAnyOf(rerouteDef->
closed) <<
"\n";
505 if (useNewRoute && newArrivalPos != -1) {
507 veh.setArrivalPos(newArrivalPos);
564 return defaultWeight;
582 if (destParkArea ==
nullptr) {
587 bool destVisible =
false;
588 for (
auto paVis : parks) {
589 if (paVis.first == destParkArea
611 <<
" rerouteParkingArea dest=" << destParkArea->
getID()
613 <<
" newDest=" << newDestination
618 typedef std::map<std::string, double> ParkingParamMap_t;
619 typedef std::map<MSParkingArea*, ParkingParamMap_t> MSParkingAreaMap_t;
621 ParkingParamMap_t weights;
624 weights[
"probability"] =
getWeight(veh,
"parking.probability.weight", 0.0);
627 weights[
"capacity"] =
getWeight(veh,
"parking.capacity.weight", 0.0);
630 weights[
"absfreespace"] =
getWeight(veh,
"parking.absfreespace.weight", 0.0);
633 weights[
"relfreespace"] =
getWeight(veh,
"parking.relfreespace.weight", 0.0);
636 weights[
"distanceto"] =
getWeight(veh,
"parking.distanceto.weight",
getWeight(veh,
"parking.distance.weight", 1.0));
639 weights[
"timeto"] =
getWeight(veh,
"parking.timeto.weight", 0.0);
642 weights[
"distancefrom"] =
getWeight(veh,
"parking.distancefrom.weight", 0.0);
645 weights[
"timefrom"] =
getWeight(veh,
"parking.timefrom.weight", 0.0);
648 ParkingParamMap_t maxValues;
650 maxValues[
"probability"] = 0.0;
651 maxValues[
"capacity"] = 0.0;
652 maxValues[
"absfreespace"] = 0.0;
653 maxValues[
"relfreespace"] = 0.0;
654 maxValues[
"distanceto"] = 0.0;
655 maxValues[
"timeto"] = 0.0;
656 maxValues[
"distancefrom"] = 0.0;
657 maxValues[
"timefrom"] = 0.0;
660 MSParkingAreaMap_t parkAreas;
668 for (
int i = 0; i < (int)parks.size(); ++i) {
670 const double prob = probs[i];
674 if (paOccupancy < pa->getCapacity()) {
677 ParkingParamMap_t parkValues;
688 if (edgesToPark.size() > 0) {
692 if (!newDestination) {
696 if (edgesFromPark.size() > 0 || newDestination) {
698 parkValues[
"probability"] = prob;
700 if (parkValues[
"probability"] > maxValues[
"probability"]) {
701 maxValues[
"probability"] = parkValues[
"probability"];
704 parkValues[
"capacity"] = (double)(pa->
getCapacity());
705 parkValues[
"absfreespace"] = (double)(pa->
getCapacity() - paOccupancy);
706 parkValues[
"relfreespace"] = parkValues[
"absfreespace"] / parkValues[
"capacity"];
708 if (parkValues[
"capacity"] > maxValues[
"capacity"]) {
709 maxValues[
"capacity"] = parkValues[
"capacity"];
712 if (parkValues[
"absfreespace"] > maxValues[
"absfreespace"]) {
713 maxValues[
"absfreespace"] = parkValues[
"absfreespace"];
716 if (parkValues[
"relfreespace"] > maxValues[
"relfreespace"]) {
717 maxValues[
"relfreespace"] = parkValues[
"relfreespace"];
724 routeToPark.begin(), routeToPark.end() - 1, includeInternalLengths);
733 if (parkValues[
"distanceto"] < brakeGap) {
742 if (parkValues[
"distanceto"] > maxValues[
"distanceto"]) {
743 maxValues[
"distanceto"] = parkValues[
"distanceto"];
746 if (parkValues[
"timeto"] > maxValues[
"timeto"]) {
747 maxValues[
"timeto"] = parkValues[
"timeto"];
750 if (newDestination) {
751 parkValues[
"distancefrom"] = 0;
752 parkValues[
"timefrom"] = 0;
754 MSRoute routeFromPark(route.
getID() +
"!frompark#1", edgesFromPark,
false,
758 routeFromPark.begin(), routeFromPark.end() - 1, includeInternalLengths);
763 if (parkValues[
"distancefrom"] > maxValues[
"distancefrom"]) {
764 maxValues[
"distancefrom"] = parkValues[
"distancefrom"];
767 if (parkValues[
"timefrom"] > maxValues[
"timefrom"]) {
768 maxValues[
"timefrom"] = parkValues[
"timefrom"];
771 parkAreas[pa] = parkValues;
775 std::cout <<
" altPA=" << pa->
getID()
787 std::cout <<
" maxValues=" <<
joinToString(maxValues,
" ",
":") <<
"\n";
792 double minParkingCost = 0.0;
794 for (MSParkingAreaMap_t::iterator it = parkAreas.begin(); it != parkAreas.end(); ++it) {
796 ParkingParamMap_t parkValues = it->second;
799 parkValues[
"probability"] = maxValues[
"probability"] > 0.0 ? 1.0 - parkValues[
"probability"] / maxValues[
"probability"] : 0.0;
800 parkValues[
"capacity"] = maxValues[
"capacity"] > 0.0 ? 1.0 - parkValues[
"capacity"] / maxValues[
"capacity"] : 0.0;
801 parkValues[
"absfreespace"] = maxValues[
"absfreespace"] > 0.0 ? 1.0 - parkValues[
"absfreespace"] / maxValues[
"absfreespace"] : 0.0;
802 parkValues[
"relfreespace"] = maxValues[
"relfreespace"] > 0.0 ? 1.0 - parkValues[
"relfreespace"] / maxValues[
"relfreespace"] : 0.0;
804 parkValues[
"distanceto"] = maxValues[
"distanceto"] > 0.0 ? parkValues[
"distanceto"] / maxValues[
"distanceto"] : 0.0;
805 parkValues[
"timeto"] = maxValues[
"timeto"] > 0.0 ? parkValues[
"timeto"] / maxValues[
"timeto"] : 0.0;
807 parkValues[
"distancefrom"] = maxValues[
"distancefrom"] > 0.0 ? parkValues[
"distancefrom"] / maxValues[
"distancefrom"] : 0.0;
808 parkValues[
"timefrom"] = maxValues[
"timefrom"] > 0.0 ? parkValues[
"timefrom"] / maxValues[
"timefrom"] : 0.0;
811 double parkingCost = 0.0;
814 for (ParkingParamMap_t::iterator pc = parkValues.begin(); pc != parkValues.end(); ++pc) {
815 parkingCost += weights[pc->first] * pc->second;
819 if (nearParkArea ==
nullptr || parkingCost < minParkingCost) {
820 minParkingCost = parkingCost;
821 nearParkArea = it->first;
826 std::cout <<
" altPA=" << it->first->
getID() <<
" score=" << parkingCost <<
"\n";
848 for (
auto vTypeDist : vTypeDists) {
A lane area vehicles can halt at.
double getProbability() const
Returns the rerouting probability.
MSEdgeVector closed
The list of closed edges.
const RerouteInterval * getCurrentReroute(SUMOTime time, SUMOVehicle &veh) const
Returns the rerouting definition valid for the given time and vehicle, 0 if none. ...
MSEdge & getEdge() const
Returns the lane's edge.
virtual double getArrivalPos() const =0
Returns this vehicle's desired arrivalPos for its current route (may change on reroute) ...
double getBeginLanePosition() const
Returns the begin position of this stop.
double getUserProbability() const
Returns the rerouting probability given by the user.
virtual MSParkingArea * getNextParkingArea()=0
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
SUMOTime myCurrentIntervalEnd
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
virtual const MSRoute & getRoute() const =0
Returns the current route.
SUMOTime setPermissions(const SUMOTime currentTime)
Sets the edge permission if there are any defined in the closingEdge.
SVCPermissions myCurrentPermissions
List of permissions for closed edges.
RandomDistributor< MSEdge * > edgeProbs
The distributions of new destinations to use.
The vehicle arrived at a junction.
lane of a reroute of type closing
SUMOTime myCurrentIntervalBegin
The first and the last time steps of the interval.
std::vector< MSLane * > myCurrentClosedLanes
List of closed lanes.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
A device that performs vehicle rerouting based on current edge speeds.
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
const RGBColor & getColor() const
Returns the color.
weights: time range begin
virtual double getBrakeGap() const =0
get distance for coming to a stop (used for rerouting checks)
virtual bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)=0
Replaces the current route by the given one.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSTriggeredRerouter(const std::string &id, const MSEdgeVector &edges, double prob, const std::string &file, bool off, SUMOTime timeThreshold, const std::string &vTypes)
Constructor.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
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...
const std::vector< T > & getVals() const
Returns the members of the distribution.
const MSEdge * getLastEdge() const
returns the destination edge
void setUserUsageProbability(double prob)
Sets the probability with which a vehicle is rerouted given by the user.
std::vector< const MSEdge * > ConstMSEdgeVector
const std::string & getID() const
Returns the id.
The arrival position is given.
const SVCPermissions SVCAll
all VClasses are allowed
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
void setUserMode(bool val)
Sets whether the process is currently steered by the user.
SAX-handler base for SUMO-files.
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
double myProbability
The probability and the user-given probability.
#define WRITE_WARNING(msg)
RandomDistributor< ParkingAreaVisible > myCurrentParkProb
new destinations with probabilities
A road/street connecting two junctions.
virtual void myEndElement(int element)
Called when a closing tag occurs.
double getEndLanePosition() const
Returns the end position of this stop.
The vehicle changes lanes (micro only)
std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
An abstract device that changes the state of the micro simulation.
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
double getWeight(SUMOVehicle &veh, const std::string param, const double defaultWeight) const
Representation of a vehicle.
Encapsulated SAX-Attributes.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
T get(std::mt19937 *which=0) const
Draw a sample of the distribution.
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
virtual ~MSTriggeredRerouter()
Destructor.
SUMOTime begin
The begin time these definitions are valid.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
A wrapper for a Command function.
int getCapacity() const
Returns the area capacity.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
virtual SUMOTime getAccumulatedWaitingTime() const =0
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
RandomDistributor< const MSRoute * > myCurrentRouteProb
new routes with probabilities
static MSEdge mySpecialDest_keepDestination
special destination values
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
bool hasInternalLinks() const
return whether the network contains internal links
MSParkingArea * rerouteParkingArea(const MSTriggeredRerouter::RerouteInterval *rerouteDef, SUMOVehicle &veh, bool &newDestination) const
probability of route of a reroute
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
probability of destiny of a reroute
Something on a lane to be noticed about vehicle movement.
static MSEdge mySpecialDest_terminateRoute
const SUMOVTypeParameter & getParameter() const
int getOccupancy() const
Returns the area occupancy.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Tries to reroute the vehicle.
bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes the reminder.
double arrivalPos
(optional) The position the vehicle shall arrive on
RandomDistributor< MSEdge * > myCurrentEdgeProb
new destinations with probabilities
std::vector< std::string > getVector()
void clear()
Clears the distribution.
entry for an alternative parking zone
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
Structure representing possible vehicle parameter.
SUMOTime end
The end time these definitions are valid.
bool containsAnyOf(const MSEdgeVector &edgelist) const
std::vector< MSLane * > closedLanes
The list of closed lanes.
RandomDistributor< const MSRoute * > routeProbs
The distributions of new routes to use.
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
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.
A single mesoscopic segment (cell)
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
const std::string & getID() const
Returns the name of the vehicle type.
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
bool inUserMode() const
Returns whether the user is setting the rerouting probability.
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
MSEdgeVector myCurrentClosed
List of closed edges.
bool myAmInUserMode
Information whether the current rerouting probability is the user-given.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
virtual SUMOTime getWaitingTime() const =0
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
an aggreagated-output interval
double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime) const
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
std::vector< MSEdge * > MSEdgeVector
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Triggers rerouting (once) for vehicles that are already on the edge when the rerouter activates...
const MSLane & getLane() const
Returns the lane this stop is located at.
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
SVCPermissions permissions
The permissions to use.
RandomDistributor< ParkingAreaVisible > parkProbs
The distributions of new parking areas to use as destinations.
Representation of a lane in the micro simulation.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
virtual const std::string & getID() const =0
Get the vehicle's ID.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
MSEdgeVector closedLanesAffected
The list of edges that are affect by closed lanes.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...