55 #include <mesosim/MELoop.h>
56 #include <mesosim/MESegment.h>
59 #ifdef CHECK_MEMORY_LEAKS
61 #endif // CHECK_MEMORY_LEAKS
75 SUMOReal prob,
const std::string& file,
bool off) :
79 myProbability(prob), myUserProbability(prob), myAmInUserMode(false) {
81 for (MSEdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
84 MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(**j);
89 const std::vector<MSLane*>& destLanes = (*j)->getLanes();
90 for (std::vector<MSLane*>::const_iterator i = destLanes.begin(); i != destLanes.end(); ++i) {
91 (*i)->addMoveReminder(
this);
118 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": No destination edge id given.");
122 if (dest ==
"keepDestination") {
124 }
else if (dest ==
"terminateRoute") {
127 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Destination edge '" + dest +
"' is not known.");
137 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for destination '" + dest +
"' is negative (must not).");
148 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Edge '" + closed_id +
"' to close is not known.");
161 if (routeStr ==
"") {
166 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Route '" + routeStr +
"' does not exist.");
176 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for route '" + routeStr +
"' is negative (must not).");
213 if (i->begin == currentTime && !i->closed.empty() && i->permissions !=
SVCAll) {
214 for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
215 for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l) {
216 i->prevPermissions.push_back((*l)->getPermissions());
217 (*l)->setPermissions(i->permissions);
219 (*e)->rebuildAllowedLanes();
225 if (i->end == currentTime && !i->closed.empty() && i->permissions !=
SVCAll) {
226 for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
227 std::vector<SVCPermissions>::const_iterator p = i->prevPermissions.begin();
228 for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l, ++p) {
229 (*l)->setPermissions(*p);
231 (*e)->rebuildAllowedLanes();
242 if (i->begin <= time && i->end > time) {
247 i->edgeProbs.getOverallProb() > 0 || i->routeProbs.getOverallProb() > 0) {
259 if (i->begin <= time && i->end > time) {
260 if (i->edgeProbs.getOverallProb() != 0 || i->routeProbs.getOverallProb() != 0 || !i->closed.empty()) {
278 if (rerouteDef == 0) {
297 const MSEdge* newEdge = lastEdge;
299 const bool destUnreachable = std::find(rerouteDef->
closed.begin(), rerouteDef->
closed.end(), lastEdge) != rerouteDef->
closed.end();
301 if (rerouteDef->
closed.size() == 0 || destUnreachable) {
306 if (destUnreachable) {
307 WRITE_WARNING(
"Cannot keep destination for vehicle '" + veh.
getID() +
"' due to closed edges. Terminating route.");
312 }
else if (newEdge == 0) {
321 veh.replaceRouteEdges(edges);
MSEdgeVector closed
The list of closed edges.
SUMOTime myCurrentIntervalEnd
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.
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.
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
Notification
Definition of a vehicle state.
static SUMOReal rand()
Returns a random real number in [0, 1)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
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.
SUMOReal myUserProbability
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)
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.
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)
An abstract device that changes the state of the micro simulation.
Representation of a vehicle.
Encapsulated SAX-Attributes.
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< const MSRoute * > myCurrentRouteProb
new routes with probabilities
static MSEdge mySpecialDest_keepDestination
special destination values
SUMOReal getProbability() const
Returns the rerouting probability.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Tries to reroute the vehicle.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
Something on a lane to be noticed about vehicle movement.
static MSEdge mySpecialDest_terminateRoute
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.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
RandomDistributor< MSEdge * > myCurrentEdgeProb
new destinations with probabilities
void clear()
Clears the distribution.
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
bool inUserMode() const
Returns whether the user is setting the rerouting probability.
SUMOTime end
The end time these definitions are valid.
RandomDistributor< const MSRoute * > routeProbs
The distributions of new routes to use.
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 replaceRoute(const MSRoute *route, bool onInit=false, int offset=0)=0
Replaces the current route by the given one.
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
MSEdgeVector myCurrentClosed
List of closed edges.
bool myAmInUserMode
Information whether the current rerouting probability is the user-given.
MSTriggeredRerouter(const std::string &id, const MSEdgeVector &edges, SUMOReal prob, const std::string &file, bool off)
Constructor.
Patch the time in a way that it is at least as high as the simulation begin time. ...
static const bool gUseMesoSim
virtual void 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 void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
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.
std::vector< MSEdge * > MSEdgeVector
SVCPermissions permissions
The permissions to use.
virtual const std::string & getID() const =0
Get the vehicle's ID.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
bool containsAnyOf(const MSEdgeVector &edgelist) const