60 #ifdef CHECK_MEMORY_LEAKS 62 #endif // CHECK_MEMORY_LEAKS 65 #define DEBUGCOND (veh.getID() == "disabled") 78 SUMOReal prob,
const std::string& file,
bool off) :
82 myProbability(prob), myUserProbability(prob), myAmInUserMode(false) {
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);
119 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": No destination edge id given.");
123 if (dest ==
"keepDestination") {
125 }
else if (dest ==
"terminateRoute") {
128 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Destination edge '" + dest +
"' is not known.");
138 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for destination '" + dest +
"' is negative (must not).");
150 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Edge '" + closed_id +
"' to close is not known.");
164 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Lane '" + closed_id +
"' to close is not known.");
183 if (routeStr ==
"") {
188 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Route '" + routeStr +
"' does not exist.");
198 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for route '" + routeStr +
"' is negative (must not).");
208 if (parkingarea ==
"") {
209 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": No parking area id given.");
213 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Parking area '" + parkingarea +
"' is not known.");
222 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for destination '" + parkingarea +
"' is negative (must not).");
246 std::set<MSEdge*> affected;
248 affected.insert(&((*l)->getEdge()));
274 if (i->begin == currentTime && !(i->closed.empty() && i->closedLanes.empty()) && i->permissions !=
SVCAll) {
275 for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
276 for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l) {
278 (*l)->setPermissions(i->permissions, i->id);
280 (*e)->rebuildAllowedLanes();
282 for (std::vector<MSLane*>::iterator l = i->closedLanes.begin(); l != i->closedLanes.end(); ++l) {
283 (*l)->setPermissions(i->permissions, i->id);
284 (*l)->getEdge().rebuildAllowedLanes();
290 if (i->end == currentTime && !(i->closed.empty() && i->closedLanes.empty()) && i->permissions !=
SVCAll) {
291 for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
292 for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l) {
293 (*l)->resetPermissions(i->id);
296 (*e)->rebuildAllowedLanes();
298 for (std::vector<MSLane*>::iterator l = i->closedLanes.begin(); l != i->closedLanes.end(); ++l) {
299 (*l)->resetPermissions(i->id);
300 (*l)->getEdge().rebuildAllowedLanes();
311 if (i->begin <= time && i->end > time) {
314 i->edgeProbs.getOverallProb() > 0 ||
316 i->routeProbs.getOverallProb() > 0 ||
318 i->parkProbs.getOverallProb() > 0 ||
334 if (i->begin <= time && i->end > time) {
335 if (i->parkProbs.getOverallProb() != 0 || i->edgeProbs.getOverallProb() != 0 || i->routeProbs.getOverallProb() != 0 || !i->closed.empty()) {
363 if (rerouteDef == 0) {
372 if (rerouteDef->
closedLanes.size() > 0 && !hasReroutingDevice) {
378 #ifdef DEBUG_REROUTER 386 if (newParkingArea != 0) {
403 if (edgesFromPark.size() > 0) {
404 edges.insert(edges.end(), edgesFromPark.begin() + 1, edgesFromPark.end());
407 veh.replaceRouteEdges(edges,
false,
false,
false);
408 std::string errorMsg;
409 if (!veh.replaceParkingArea(newParkingArea, errorMsg)) {
411 +
"' could not reroute to new parkingArea '" + newParkingArea->
getID()
422 #ifdef DEBUG_REROUTER 424 std::cout <<
" replacedRoute from routeDist " << newRoute->
getID() <<
"\n";
430 const MSEdge* newEdge = lastEdge;
433 const bool destUnreachable = std::find(rerouteDef->
closed.begin(), rerouteDef->
closed.end(), lastEdge) != rerouteDef->
closed.end();
436 if (rerouteDef->
closed.size() == 0 || destUnreachable) {
446 WRITE_WARNING(
"Cannot keep destination edge '" + lastEdge->
getID() +
"' for vehicle '" + veh.
getID() +
"' due to closed edges. Terminating route.");
451 }
else if (newEdge == 0) {
452 #ifdef DEBUG_REROUTER 454 std::cout <<
" could not find new edge!\n";
469 const bool useNewRoute = veh.replaceRouteEdges(edges);
470 #ifdef DEBUG_REROUTER 471 if (
DEBUGCOND) std::cout <<
" rerouting: newEdge=" << newEdge->
getID() <<
" useNewRoute=" << useNewRoute <<
" newArrivalPos=" << newArrivalPos <<
" numClosed=" << rerouteDef->
closed.size()
472 <<
" destUnreachable=" << destUnreachable <<
" containsClosed=" << veh.getRoute().containsAnyOf(rerouteDef->
closed) <<
"\n";
474 if (useNewRoute && newArrivalPos != -1) {
476 veh.setArrivalPos(newArrivalPos);
533 return defaultWeight;
548 if (destParkArea != 0 &&
551 typedef std::map<std::string, SUMOReal> ParkingParamMap_t;
552 typedef std::map<MSParkingArea*, ParkingParamMap_t> MSParkingAreaMap_t;
554 ParkingParamMap_t weights;
557 weights[
"probability"] =
getWeight(veh,
"parking.probability.weight", 0.0);
560 weights[
"capacity"] =
getWeight(veh,
"parking.capacity.weight", 0.0);
563 weights[
"absfreespace"] =
getWeight(veh,
"parking.absfreespace.weight", 0.0);
566 weights[
"relfreespace"] =
getWeight(veh,
"parking.relfreespace.weight", 0.0);
569 weights[
"distanceto"] =
getWeight(veh,
"parking.distanceto.weight",
getWeight(veh,
"parking.distance.weight", 1.0));
572 weights[
"timeto"] =
getWeight(veh,
"parking.timeto.weight", 0.0);
575 weights[
"distancefrom"] =
getWeight(veh,
"parking.distancefrom.weight", 0.0);
578 weights[
"timefrom"] =
getWeight(veh,
"parking.timefrom.weight", 0.0);
581 ParkingParamMap_t maxValues;
583 maxValues[
"probability"] = 0.0;
584 maxValues[
"capacity"] = 0.0;
585 maxValues[
"absfreespace"] = 0.0;
586 maxValues[
"relfreespace"] = 0.0;
587 maxValues[
"distanceto"] = 0.0;
588 maxValues[
"timeto"] = 0.0;
589 maxValues[
"distancefrom"] = 0.0;
590 maxValues[
"timefrom"] = 0.0;
593 MSParkingAreaMap_t parkAreas;
600 for (
int i = 0; i < (int)parks.size(); ++i) {
606 ParkingParamMap_t parkValues;
617 if (edgesToPark.size() > 0) {
622 if (edgesFromPark.size() > 0) {
624 parkValues[
"probability"] = prob;
626 if (parkValues[
"probability"] > maxValues[
"probability"]) {
627 maxValues[
"probability"] = parkValues[
"probability"];
630 parkValues[
"capacity"] = (double)(pa->
getCapacity());
632 parkValues[
"relfreespace"] = parkValues[
"absfreespace"] / parkValues[
"capacity"];
634 if (parkValues[
"capacity"] > maxValues[
"capacity"]) {
635 maxValues[
"capacity"] = parkValues[
"capacity"];
638 if (parkValues[
"absfreespace"] > maxValues[
"absfreespace"]) {
639 maxValues[
"absfreespace"] = parkValues[
"absfreespace"];
642 if (parkValues[
"relfreespace"] > maxValues[
"relfreespace"]) {
643 maxValues[
"relfreespace"] = parkValues[
"relfreespace"];
650 routeToPark.begin(), routeToPark.end(), includeInternalLengths);
655 if (parkValues[
"distanceto"] > maxValues[
"distanceto"]) {
656 maxValues[
"distanceto"] = parkValues[
"distanceto"];
659 if (parkValues[
"timeto"] > maxValues[
"timeto"]) {
660 maxValues[
"timeto"] = parkValues[
"timeto"];
667 routeFromPark.begin(), routeFromPark.end(), includeInternalLengths);
672 if (parkValues[
"distancefrom"] > maxValues[
"distancefrom"]) {
673 maxValues[
"distancefrom"] = parkValues[
"distancefrom"];
676 if (parkValues[
"timefrom"] > maxValues[
"timefrom"]) {
677 maxValues[
"timefrom"] = parkValues[
"timefrom"];
680 parkAreas[pa] = parkValues;
689 for (MSParkingAreaMap_t::iterator it = parkAreas.begin(); it != parkAreas.end(); ++it) {
691 ParkingParamMap_t parkValues = it->second;
694 parkValues[
"probability"] = maxValues[
"probability"] > 0.0 ? 1.0 - parkValues[
"probability"] / maxValues[
"probability"] : 0.0;
695 parkValues[
"capacity"] = maxValues[
"capacity"] > 0.0 ? 1.0 - parkValues[
"capacity"] / maxValues[
"capacity"] : 0.0;
696 parkValues[
"absfreespace"] = maxValues[
"absfreespace"] > 0.0 ? 1.0 - parkValues[
"absfreespace"] / maxValues[
"absfreespace"] : 0.0;
697 parkValues[
"relfreespace"] = maxValues[
"relfreespace"] > 0.0 ? 1.0 - parkValues[
"relfreespace"] / maxValues[
"relfreespace"] : 0.0;
699 parkValues[
"distanceto"] = maxValues[
"distanceto"] > 0.0 ? parkValues[
"distanceto"] / maxValues[
"distanceto"] : 0.0;
700 parkValues[
"timeto"] = maxValues[
"timeto"] > 0.0 ? parkValues[
"timeto"] / maxValues[
"timeto"] : 0.0;
702 parkValues[
"distancefrom"] = maxValues[
"distancefrom"] > 0.0 ? parkValues[
"distancefrom"] / maxValues[
"distancefrom"] : 0.0;
703 parkValues[
"timefrom"] = maxValues[
"timefrom"] > 0.0 ? parkValues[
"timefrom"] / maxValues[
"timefrom"] : 0.0;
709 for (ParkingParamMap_t::iterator pc = parkValues.begin(); pc != parkValues.end(); ++pc) {
710 parkingCost += weights[pc->first] * pc->second;
714 if (nearParkArea == 0 || parkingCost < minParkingCost) {
715 minParkingCost = parkingCost;
716 nearParkArea = it->first;
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
A lane area vehicles can halt at.
int getCapacity() const
Returns the area capacity.
int getOccupancy() const
Returns the area occupancy.
MSEdge & getEdge() const
Returns the lane's edge.
MSEdgeVector closed
The list of closed edges.
virtual bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true)=0
Replaces the current route by the given one.
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Triggers rerouting (once) for vehicles that are already on the edge when the rerouter activates...
virtual MSParkingArea * getNextParkingArea()=0
const std::vector< SUMOReal > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
MSParkingArea * getParkingArea(const std::string &id) const
Returns the named parking area.
SUMOTime myCurrentIntervalEnd
SUMOTime setPermissions(const SUMOTime currentTime)
Sets the edge permission if there are any defined in the closingEdge.
static SUMOReal _2SUMOReal(const E *const data)
converts a char-type array into the SUMOReal value described by it
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
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
const MSEdge * getLastEdge() const
returns the destination edge
SUMOTime myCurrentIntervalBegin
The first and the last time steps of the interval.
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Removes the reminder.
std::vector< MSLane * > myCurrentClosedLanes
List of closed lanes.
bool hasInternalLinks() const
return whether the network contains internal links
Notification
Definition of a vehicle state.
static SUMOReal rand()
Returns a random real number in [0, 1)
std::string time2string(SUMOTime t)
A device that performs vehicle rerouting based on current edge speeds.
virtual SUMOReal recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime) const =0
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
weights: time range begin
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
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...
void setUserUsageProbability(SUMOReal prob)
Sets the probability with which a vehicle is rerouted given by the user.
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...
std::vector< const MSEdge * > ConstMSEdgeVector
SUMOReal getUserProbability() const
Returns the rerouting probability given by the user.
const SVCPermissions SVCAll
void setUserMode(bool val)
Sets whether the process is currently steered by the user.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
SUMOReal myUserProbability
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
SAX-handler base for SUMO-files.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The purpose of the edge is not known.
#define WRITE_WARNING(msg)
const std::vector< T > & getVals() const
Returns the members of the distribution.
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.
SUMOReal myProbability
The probability and the user-given probability.
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
virtual void myEndElement(int element)
Called when a closing tag occurs.
The vehicle changes lanes (micro only) XXX: What if a vehicle changes lanes and passes a junction sim...
const MSLane & getLane() const
Returns the lane this stop is located at.
const SUMOVTypeParameter & getParameter() const
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle's position along the lane.
An abstract device that changes the state of the micro simulation.
Representation of a vehicle.
Encapsulated SAX-Attributes.
SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
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.
T get(MTRand *which=0) const
Draw a sample of the distribution.
A wrapper for a Command function.
RandomDistributor< MSParkingArea * > myCurrentParkProb
new destinations with probabilities
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.
SUMOReal getProbability() const
Returns the rerouting probability.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Tries to reroute the vehicle.
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
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
const RerouteInterval * getCurrentReroute(SUMOTime time, SUMOVehicle &veh) const
Returns the rerouting definition valid for the given time and vehicle, 0 if none. ...
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
RandomDistributor< MSEdge * > myCurrentEdgeProb
new destinations with probabilities
void clear()
Clears the distribution.
entry for an alternative parking zone
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
SUMOReal getWeight(SUMOVehicle &veh, const std::string param, const SUMOReal defaultWeight) const
RandomDistributor< MSParkingArea * > parkProbs
The distributions of new parking areas to use as destinations.
virtual const MSRoute & getRoute() const =0
Returns the current route.
bool inUserMode() const
Returns whether the user is setting the rerouting probability.
SUMOTime end
The end time these definitions are valid.
std::vector< MSLane * > closedLanes
The list of closed lanes.
RandomDistributor< const MSRoute * > routeProbs
The distributions of new routes to use.
A single mesoscopic segment (cell)
SUMOReal getBeginLanePosition() const
Returns the begin position of this stop.
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
MESegment * getSegmentForEdge(const MSEdge &e, SUMOReal pos=0)
Get the segment for a given edge at a given position.
MSEdgeVector myCurrentClosed
List of closed edges.
virtual const std::string & getID() const =0
Get the vehicle's ID.
bool myAmInUserMode
Information whether the current rerouting probability is the user-given.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
MSTriggeredRerouter(const std::string &id, const MSEdgeVector &edges, SUMOReal prob, const std::string &file, bool off)
Constructor.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
an aggreagated-output interval
Patch the time in a way that it is at least as high as the simulation begin time. ...
const RGBColor & getColor() const
Returns the color.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
MSParkingArea * rerouteParkingZone(const MSTriggeredRerouter::RerouteInterval *rerouteDef, SUMOVehicle &veh) const
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.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
std::vector< MSEdge * > MSEdgeVector
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
virtual SUMOReal getArrivalPos() const =0
Returns this vehicle's desired arrivalPos for its current route (may change on reroute) ...
SVCPermissions permissions
The permissions to use.
Representation of a lane in the micro simulation.
MSEdgeVector closedLanesAffected
The list of edges that are affect by closed lanes.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
bool containsAnyOf(const MSEdgeVector &edgelist) const
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.