55 #include <mesosim/MELoop.h>
56 #include <mesosim/MESegment.h>
59 #ifdef CHECK_MEMORY_LEAKS
61 #endif // CHECK_MEMORY_LEAKS
74 const std::vector<MSEdge*>& edges,
75 SUMOReal prob,
const std::string& file,
bool off) :
79 myProbability(prob), myUserProbability(prob), myAmInUserMode(false) {
85 for (std::vector<MSEdge*>::const_iterator j = edges.begin(); j != edges.end(); ++j) {
88 MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(**j);
93 const std::vector<MSLane*>& destLanes = (*j)->getLanes();
94 for (std::vector<MSLane*>::const_iterator i = destLanes.begin(); i != destLanes.end(); ++i) {
95 (*i)->addMoveReminder(
this);
122 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": No destination edge id given.");
126 if (dest ==
"keepDestination") {
128 }
else if (dest ==
"terminateRoute") {
131 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Destination edge '" + dest +
"' is not known.");
141 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for destination '" + dest +
"' is negative (must not).");
150 if (closed_id ==
"") {
151 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": closed edge id given.");
155 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Edge '" + closed_id +
"' to close is not known.");
164 if (routeStr ==
"") {
169 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Route '" + routeStr +
"' does not exist.");
179 throw ProcessError(
"MSTriggeredRerouter " +
getID() +
": Attribute 'probability' for route '" + routeStr +
"' is negative (must not).");
209 std::vector<RerouteInterval>::const_iterator i =
myIntervals.begin();
212 if ((*i).begin <= time && (*i).end >= time) {
217 ((*i).closed.size() == 0 && (*i).edgeProbs.getOverallProb() + (*i).routeProbs.getOverallProb() > 0)) {
229 std::vector<RerouteInterval>::const_iterator i =
myIntervals.begin();
231 if ((*i).begin <= time && (*i).end >= time) {
232 if ((*i).edgeProbs.getOverallProb() != 0 || (*i).routeProbs.getOverallProb() != 0 || (*i).closed.size() != 0) {
244 std::vector<RerouteInterval>::const_iterator i =
myIntervals.begin();
247 if ((*i).begin <= time && (*i).end >= time) {
248 if ((*i).edgeProbs.getOverallProb() != 0 || (*i).routeProbs.getOverallProb() != 0 || route.
containsAnyOf((*i).closed)) {
260 std::vector<RerouteInterval>::const_iterator i =
myIntervals.begin();
262 if ((*i).edgeProbs.getOverallProb() != 0 || (*i).routeProbs.getOverallProb() != 0 || (*i).closed.size() != 0) {
299 const MSEdge* newEdge = lastEdge;
301 const bool destUnreachable = std::find(rerouteDef.
closed.begin(), rerouteDef.
closed.end(), lastEdge) != rerouteDef.
closed.end();
303 if (rerouteDef.
closed.size() == 0 || destUnreachable) {
308 if (destUnreachable) {
309 WRITE_WARNING(
"Cannot keep destination for vehicle '" + veh.
getID() +
"' due to closed edges. Terminating route.");
314 }
else if (newEdge == 0) {
320 std::vector<const MSEdge*> edges;
323 veh.replaceRouteEdges(edges);
bool hasCurrentReroute(SUMOTime time, SUMOVehicle &veh) const
Returns whether a rerouting definition is valid for the given time and vehicle.
std::vector< MSEdge * > closed
The list of closed edges.
SUMOTime myCurrentIntervalEnd
virtual const MSRoute & getRoute() const =0
Returns the current route.
RandomDistributor< MSEdge * > edgeProbs
The distributions of new destinations to use.
virtual bool replaceRoute(const MSRoute *route, bool onInit=false)=0
Replaces the current route by the given one.
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).
const RerouteInterval & getCurrentReroute(SUMOTime time, SUMOVehicle &veh) const
Returns the rerouting definition valid for the given time and vehicle.
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...
SUMOReal getUserProbability() const
Returns the rerouting probability given by the user.
void setUserMode(bool val)
Sets whether the process is currently steered by the user.
SUMOReal myUserProbability
static bool runParser(GenericSAXHandler &handler, const std::string &file)
Runs the given handler on the given file; returns if everything's ok.
SAX-handler base for SUMO-files.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step (in s)
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.
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.
bool containsAnyOf(const std::vector< MSEdge * > &edgelist) const
virtual ~MSTriggeredRerouter()
Destructor.
SUMOTime begin
The begin time these definitions are valid.
T get(MTRand *which=0) const
Draw a sample of the distribution.
std::vector< MSEdge * > myCurrentClosed
List of closed edges.
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.
Something on a lane to be noticed about vehicle movement.
static MSEdge mySpecialDest_terminateRoute
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.
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
bool myAmInUserMode
Information whether the current rerouting probability is the user-given.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
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.
MSTriggeredRerouter(const std::string &id, const std::vector< MSEdge * > &edges, SUMOReal prob, const std::string &file, bool off)
Constructor.
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.