Eclipse SUMO - Simulation of Urban MObility
MSTriggeredRerouter.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Reroutes vehicles passing an edge
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <algorithm>
30 #include <utils/common/Command.h>
33 #include <utils/common/ToString.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSVehicle.h>
42 #include <microsim/MSRoute.h>
43 #include <microsim/MSEdge.h>
45 #include <microsim/MSNet.h>
47 #include <microsim/MSGlobals.h>
48 #include <microsim/MSParkingArea.h>
52 #include "MSTriggeredRerouter.h"
53 
54 #include <mesosim/MELoop.h>
55 #include <mesosim/MESegment.h>
56 
57 //#define DEBUG_REROUTER
58 //#define DEBUG_PARKING
59 #define DEBUGCOND (veh.isSelected())
60 //#define DEBUGCOND (veh.getID() == "")
61 
62 // ===========================================================================
63 // static member defintion
64 // ===========================================================================
65 MSEdge MSTriggeredRerouter::mySpecialDest_keepDestination("MSTriggeredRerouter_keepDestination", -1, EDGEFUNC_UNKNOWN, "", "", -1, 0);
66 MSEdge MSTriggeredRerouter::mySpecialDest_terminateRoute("MSTriggeredRerouter_terminateRoute", -1, EDGEFUNC_UNKNOWN, "", "", -1, 0);
67 
68 // ===========================================================================
69 // method definitions
70 // ===========================================================================
72  const MSEdgeVector& edges,
73  double prob, const std::string& file, bool off,
74  SUMOTime timeThreshold,
75  const std::string& vTypes) :
76  MSTrigger(id),
77  MSMoveReminder(id),
78  SUMOSAXHandler(file),
79  myProbability(prob),
80  myUserProbability(prob),
81  myAmInUserMode(false),
82  myTimeThreshold(timeThreshold) {
83  // build actors
84  for (MSEdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
87  s->addDetector(this);
88  continue;
89  }
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);
93  }
94  }
95  if (off) {
96  setUserMode(true);
98  }
99  const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
100  myVehicleTypes.insert(vt.begin(), vt.end());
101 }
102 
103 
105 }
106 
107 // ------------ loading begin
108 void
110  const SUMOSAXAttributes& attrs) {
111  if (element == SUMO_TAG_INTERVAL) {
112  bool ok = true;
115  }
116  if (element == SUMO_TAG_DEST_PROB_REROUTE) {
117  // by giving probabilities of new destinations
118  // get the destination edge
119  std::string dest = attrs.getStringSecure(SUMO_ATTR_ID, "");
120  if (dest == "") {
121  throw ProcessError("MSTriggeredRerouter " + getID() + ": No destination edge id given.");
122  }
123  MSEdge* to = MSEdge::dictionary(dest);
124  if (to == nullptr) {
125  if (dest == "keepDestination") {
127  } else if (dest == "terminateRoute") {
129  } else {
130  throw ProcessError("MSTriggeredRerouter " + getID() + ": Destination edge '" + dest + "' is not known.");
131  }
132  }
133  // get the probability to reroute
134  bool ok = true;
135  double prob = attrs.getOpt<double>(SUMO_ATTR_PROB, getID().c_str(), ok, 1.);
136  if (!ok) {
137  throw ProcessError();
138  }
139  if (prob < 0) {
140  throw ProcessError("MSTriggeredRerouter " + getID() + ": Attribute 'probability' for destination '" + dest + "' is negative (must not).");
141  }
142  // add
143  myCurrentEdgeProb.add(to, prob);
144  }
145 
146 
147  if (element == SUMO_TAG_CLOSING_REROUTE) {
148  // by closing
149  std::string closed_id = attrs.getStringSecure(SUMO_ATTR_ID, "");
150  MSEdge* closed = MSEdge::dictionary(closed_id);
151  if (closed == nullptr) {
152  throw ProcessError("MSTriggeredRerouter " + getID() + ": Edge '" + closed_id + "' to close is not known.");
153  }
154  myCurrentClosed.push_back(closed);
155  bool ok;
156  const std::string allow = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, getID().c_str(), ok, "", false);
157  const std::string disallow = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, getID().c_str(), ok, "");
158  myCurrentPermissions = parseVehicleClasses(allow, disallow);
159  }
160 
161  if (element == SUMO_TAG_CLOSING_LANE_REROUTE) {
162  // by closing lane
163  std::string closed_id = attrs.getStringSecure(SUMO_ATTR_ID, "");
164  MSLane* closed = MSLane::dictionary(closed_id);
165  if (closed == nullptr) {
166  throw ProcessError("MSTriggeredRerouter " + getID() + ": Lane '" + closed_id + "' to close is not known.");
167  }
168  myCurrentClosedLanes.push_back(closed);
169  bool ok;
171  const std::string allow = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, getID().c_str(), ok, "", false);
172  const std::string disallow = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, getID().c_str(), ok, "");
173  myCurrentPermissions = parseVehicleClasses(allow, disallow);
174  } else {
175  // lane closing only makes sense if the lane really receives reduced
176  // permissions
178  }
179  }
180 
181  if (element == SUMO_TAG_ROUTE_PROB_REROUTE) {
182  // by explicit rerouting using routes
183  // check if route exists
184  std::string routeStr = attrs.getStringSecure(SUMO_ATTR_ID, "");
185  if (routeStr == "") {
186  throw ProcessError("MSTriggeredRerouter " + getID() + ": No route id given.");
187  }
188  const MSRoute* route = MSRoute::dictionary(routeStr);
189  if (route == nullptr) {
190  throw ProcessError("MSTriggeredRerouter " + getID() + ": Route '" + routeStr + "' does not exist.");
191  }
192 
193  // get the probability to reroute
194  bool ok = true;
195  double prob = attrs.getOpt<double>(SUMO_ATTR_PROB, getID().c_str(), ok, 1.);
196  if (!ok) {
197  throw ProcessError();
198  }
199  if (prob < 0) {
200  throw ProcessError("MSTriggeredRerouter " + getID() + ": Attribute 'probability' for route '" + routeStr + "' is negative (must not).");
201  }
202  // add
203  myCurrentRouteProb.add(route, prob);
204  }
205 
206  if (element == SUMO_TAG_PARKING_ZONE_REROUTE) {
207  // by giving probabilities of new destinations
208  // get the destination edge
209  std::string parkingarea = attrs.getStringSecure(SUMO_ATTR_ID, "");
210  if (parkingarea == "") {
211  throw ProcessError("MSTriggeredRerouter " + getID() + ": No parking area id given.");
212  }
214  if (pa == nullptr) {
215  throw ProcessError("MSTriggeredRerouter " + getID() + ": Parking area '" + parkingarea + "' is not known.");
216  }
217  // get the probability to reroute
218  bool ok = true;
219  const double prob = attrs.getOpt<double>(SUMO_ATTR_PROB, getID().c_str(), ok, 1.);
220  if (!ok) {
221  throw ProcessError();
222  }
223  if (prob < 0) {
224  throw ProcessError("MSTriggeredRerouter " + getID() + ": Attribute 'probability' for destination '" + parkingarea + "' is negative (must not).");
225  }
226  const bool visible = attrs.getOpt<bool>(SUMO_ATTR_VISIBLE, getID().c_str(), ok, false);
227  // add
228  myCurrentParkProb.add(std::make_pair(pa, visible), prob);
229  //MSEdge* to = &(pa->getLane().getEdge());
230  //myCurrentEdgeProb.add(prob, to);
231  }
232 }
233 
234 
235 void
237  if (element == SUMO_TAG_INTERVAL) {
238  RerouteInterval ri;
241  ri.closed = myCurrentClosed;
247  for (auto paVi : ri.parkProbs.getVals()) {
248  paVi.first->setNumAlternatives((int)ri.parkProbs.getVals().size() - 1);
249  }
250  if (ri.closedLanes.size() > 0) {
251  // collect edges that are affect by a closed lane
252  std::set<MSEdge*> affected;
253  for (const MSLane* const l : ri.closedLanes) {
254  affected.insert(&l->getEdge());
255  }
256  ri.closedLanesAffected.insert(ri.closedLanesAffected.begin(), affected.begin(), affected.end());
257  }
258  myCurrentClosed.clear();
259  myCurrentClosedLanes.clear();
263  myIntervals.push_back(ri);
264  myIntervals.back().id = (long long)&myIntervals.back();
265  if (!(ri.closed.empty() && ri.closedLanes.empty()) && ri.permissions != SVCAll) {
268  }
269  }
270 }
271 
272 
273 // ------------ loading end
274 
275 
276 SUMOTime
278  for (std::vector<RerouteInterval>::iterator i = myIntervals.begin(); i != myIntervals.end(); ++i) {
279  if (i->begin == currentTime && !(i->closed.empty() && i->closedLanes.empty()) && i->permissions != SVCAll) {
280  for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
281  for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l) {
282  //std::cout << SIMTIME << " closing: intervalID=" << i->id << " lane=" << (*l)->getID() << " prevPerm=" << getVehicleClassNames((*l)->getPermissions()) << " new=" << getVehicleClassNames(i->permissions) << "\n";
283  (*l)->setPermissions(i->permissions, i->id);
284  }
285  (*e)->rebuildAllowedLanes();
286  }
287  for (std::vector<MSLane*>::iterator l = i->closedLanes.begin(); l != i->closedLanes.end(); ++l) {
288  (*l)->setPermissions(i->permissions, i->id);
289  (*l)->getEdge().rebuildAllowedLanes();
290  }
293  }
294  if (i->end == currentTime && !(i->closed.empty() && i->closedLanes.empty()) && i->permissions != SVCAll) {
295  for (MSEdgeVector::iterator e = i->closed.begin(); e != i->closed.end(); ++e) {
296  for (std::vector<MSLane*>::const_iterator l = (*e)->getLanes().begin(); l != (*e)->getLanes().end(); ++l) {
297  (*l)->resetPermissions(i->id);
298  //std::cout << SIMTIME << " opening: intervalID=" << i->id << " lane=" << (*l)->getID() << " restore prevPerm=" << getVehicleClassNames((*l)->getPermissions()) << "\n";
299  }
300  (*e)->rebuildAllowedLanes();
301  }
302  for (std::vector<MSLane*>::iterator l = i->closedLanes.begin(); l != i->closedLanes.end(); ++l) {
303  (*l)->resetPermissions(i->id);
304  (*l)->getEdge().rebuildAllowedLanes();
305  }
306  }
307  }
308  return 0;
309 }
310 
311 
314  for (std::vector<RerouteInterval>::const_iterator i = myIntervals.begin(); i != myIntervals.end(); ++i) {
315  if (i->begin <= time && i->end > time) {
316  if (
317  // destProbReroute
318  i->edgeProbs.getOverallProb() > 0 ||
319  // routeProbReroute
320  i->routeProbs.getOverallProb() > 0 ||
321  // parkingZoneReroute
322  i->parkProbs.getOverallProb() > 0 ||
323  // affected by closingReroute
324  veh.getRoute().containsAnyOf(i->closed) ||
325  // affected by closingLaneReroute
326  veh.getRoute().containsAnyOf(i->closedLanesAffected)) {
327  return &*i;
328  }
329  }
330  }
331  return nullptr;
332 }
333 
334 
337  for (std::vector<RerouteInterval>::const_iterator i = myIntervals.begin(); i != myIntervals.end(); ++i) {
338  if (i->begin <= time && i->end > time) {
339  if (i->parkProbs.getOverallProb() != 0 || i->edgeProbs.getOverallProb() != 0 || i->routeProbs.getOverallProb() != 0 || !i->closed.empty()) {
340  return &*i;
341  }
342  }
343  }
344  return nullptr;
345 }
346 
347 
348 bool
350  double /*newPos*/, double /*newSpeed*/) {
351  return notifyEnter(veh, NOTIFICATION_JUNCTION);
352 }
353 
354 
355 bool
357  MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
358  return reason == NOTIFICATION_LANE_CHANGE;
359 }
360 
361 
362 bool
364  if (!tObject.isVehicle()) {
365  return false;
366  }
367  SUMOVehicle& veh = static_cast<SUMOVehicle&>(tObject);
368  if (!vehicleApplies(veh)) {
369  return false;
370  }
371  // check whether the vehicle shall be rerouted
373  const MSTriggeredRerouter::RerouteInterval* rerouteDef = getCurrentReroute(time, veh);
374  if (rerouteDef == nullptr) {
375  return true; // an active interval could appear later
376  }
377  const double prob = myAmInUserMode ? myUserProbability : myProbability;
378  if (prob < 1 && RandHelper::rand(veh.getRNG()) > prob) {
379  return false; // XXX another interval could appear later but we would have to track whether the current interval was already tried
380  }
382  return true; // waiting time may be reached later
383  }
384  // if we have a closingLaneReroute, only vehicles with a rerouting device can profit from rerouting (otherwise, edge weights will not reflect local jamming)
385  const bool hasReroutingDevice = veh.getDevice(typeid(MSDevice_Routing)) != nullptr;
386  if (rerouteDef->closedLanes.size() > 0 && !hasReroutingDevice) {
387  return true; // an active interval could appear later
388  }
389  // get vehicle params
390  const MSRoute& route = veh.getRoute();
391  const MSEdge* lastEdge = route.getLastEdge();
392 #ifdef DEBUG_REROUTER
393  if (DEBUGCOND) {
394  std::cout << SIMTIME << " veh=" << veh.getID() << " check rerouter " << getID() << " lane=" << veh.getLane()->getID() << " edge=" << veh.getEdge()->getID() << " finalEdge=" << lastEdge->getID() << " arrivalPos=" << veh.getArrivalPos() << "\n";
395  }
396 #endif
397 
398  if (rerouteDef->parkProbs.getOverallProb() > 0) {
399 #ifdef HAVE_FOX
400  FXConditionalLock lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
401 #endif
402  bool newDestination = false;
403  ConstMSEdgeVector newRoute;
404  MSParkingArea* newParkingArea = rerouteParkingArea(rerouteDef, veh, newDestination, newRoute);
405  if (newParkingArea != nullptr) {
406  // adapt plans of any riders
407  for (MSTransportable* p : veh.getPersons()) {
408  p->rerouteParkingArea(veh.getNextParkingArea(), newParkingArea);
409  }
410 
411  if (newDestination) {
412  // update arrival parameters
413  SUMOVehicleParameter* newParameter = new SUMOVehicleParameter();
414  *newParameter = veh.getParameter();
415  newParameter->arrivalPosProcedure = ARRIVAL_POS_GIVEN;
416  newParameter->arrivalPos = newParkingArea->getEndLanePosition();
417  veh.replaceParameter(newParameter);
418  }
419 
420  SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = hasReroutingDevice
421  ? MSRoutingEngine::getRouterTT(veh.getRNGIndex(), rerouteDef->closed)
422  : MSNet::getInstance()->getRouterTT(veh.getRNGIndex(), rerouteDef->closed);
423  const double routeCost = router.recomputeCosts(newRoute, &veh, MSNet::getInstance()->getCurrentTimeStep());
424  ConstMSEdgeVector prevEdges(veh.getCurrentRouteEdge(), veh.getRoute().end());
425  const double previousCost = router.recomputeCosts(prevEdges, &veh, MSNet::getInstance()->getCurrentTimeStep());
426  const double savings = previousCost - routeCost;
427  hasReroutingDevice
429  : MSNet::getInstance()->getRouterTT(veh.getRNGIndex()); // reset closed edges
430  //if (getID() == "ego") std::cout << SIMTIME << " pCost=" << previousCost << " cost=" << routeCost
431  // << " prevEdges=" << toString(prevEdges)
432  // << " newEdges=" << toString(edges)
433  // << "\n";
434 
435  std::string errorMsg;
436  if (veh.replaceParkingArea(newParkingArea, errorMsg)) {
437  veh.replaceRouteEdges(newRoute, routeCost, savings, getID() + ":" + toString(SUMO_TAG_PARKING_ZONE_REROUTE), false, false, false);
438  } else {
439  WRITE_WARNING("Vehicle '" + veh.getID() + "' at rerouter '" + getID()
440  + "' could not reroute to new parkingArea '" + newParkingArea->getID()
441  + "' reason=" + errorMsg + ", time=" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
442  }
443  }
444  return false;
445  }
446 
447  // get rerouting params
448  const MSRoute* newRoute = rerouteDef->routeProbs.getOverallProb() > 0 ? rerouteDef->routeProbs.get() : 0;
449  // we will use the route if given rather than calling our own dijsktra...
450  if (newRoute != nullptr) {
451 #ifdef DEBUG_REROUTER
452  if (DEBUGCOND) {
453  std::cout << " replacedRoute from routeDist " << newRoute->getID() << "\n";
454  }
455 #endif
456  veh.replaceRoute(newRoute, getID());
457  return false; // XXX another interval could appear later but we would have to track whether the currenty interval was already used
458  }
459  const MSEdge* newEdge = lastEdge;
460  // ok, try using a new destination
461  double newArrivalPos = -1;
462  const bool destUnreachable = std::find(rerouteDef->closed.begin(), rerouteDef->closed.end(), lastEdge) != rerouteDef->closed.end();
463  bool keepDestination = false;
464  // if we have a closingReroute, only assign new destinations to vehicles which cannot reach their original destination
465  // if we have a closingLaneReroute, no new destinations should be assigned
466  if (rerouteDef->closed.size() == 0 || destUnreachable) {
467  newEdge = rerouteDef->edgeProbs.getOverallProb() > 0 ? rerouteDef->edgeProbs.get() : route.getLastEdge();
468  if (newEdge == &mySpecialDest_terminateRoute) {
469  keepDestination = true;
470  newEdge = veh.getEdge();
471  newArrivalPos = veh.getPositionOnLane(); // instant arrival
472  } else if (newEdge == &mySpecialDest_keepDestination || newEdge == lastEdge) {
473  if (destUnreachable && rerouteDef->permissions == SVCAll) {
474  // if permissions aren't set vehicles will simply drive through
475  // the closing unless terminated. If the permissions are specified, assume that the user wants
476  // vehicles to stand and wait until the closing ends
477  WRITE_WARNING("Cannot keep destination edge '" + lastEdge->getID() + "' for vehicle '" + veh.getID() + "' due to closed edges. Terminating route.");
478  newEdge = veh.getEdge();
479  } else {
480  newEdge = lastEdge;
481  }
482  } else if (newEdge == nullptr) {
483 #ifdef DEBUG_REROUTER
484  if (DEBUGCOND) {
485  std::cout << " could not find new edge!\n";
486  }
487 #endif
488  assert(false); // this should never happen
489  newEdge = veh.getEdge();
490  }
491  }
492  // we have a new destination, let's replace the vehicle route (if it is affected)
493  if (rerouteDef->closed.size() == 0 || destUnreachable || veh.getRoute().containsAnyOf(rerouteDef->closed)) {
494  ConstMSEdgeVector edges;
495  SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = hasReroutingDevice
496  ? MSRoutingEngine::getRouterTT(veh.getRNGIndex(), rerouteDef->closed)
497  : MSNet::getInstance()->getRouterTT(veh.getRNGIndex(), rerouteDef->closed);
498  router.compute(veh.getEdge(), newEdge, &veh, MSNet::getInstance()->getCurrentTimeStep(), edges);
499  if (edges.size() == 0 && !keepDestination && rerouteDef->edgeProbs.getOverallProb() > 0) {
500  // destination unreachable due to closed intermediate edges. pick among alternative targets
501  RandomDistributor<MSEdge*> edgeProbs2 = rerouteDef->edgeProbs;
502  edgeProbs2.remove(const_cast<MSEdge*>(newEdge));
503  while (edges.size() == 0 && edgeProbs2.getVals().size() > 0) {
504  newEdge = edgeProbs2.get();
505  edgeProbs2.remove(const_cast<MSEdge*>(newEdge));
506  if (newEdge == &mySpecialDest_terminateRoute) {
507  newEdge = veh.getEdge();
508  newArrivalPos = veh.getPositionOnLane(); // instant arrival
509  }
510  if (newEdge == &mySpecialDest_keepDestination && rerouteDef->permissions != SVCAll) {
511  newEdge = lastEdge;
512  break;
513  }
514  router.compute(
515  veh.getEdge(), newEdge, &veh, MSNet::getInstance()->getCurrentTimeStep(), edges);
516  }
517 
518  }
519  const double routeCost = router.recomputeCosts(edges, &veh, MSNet::getInstance()->getCurrentTimeStep());
520  hasReroutingDevice
522  : MSNet::getInstance()->getRouterTT(veh.getRNGIndex()); // reset closed edges
523  const bool useNewRoute = veh.replaceRouteEdges(edges, routeCost, 0, getID());
524 #ifdef DEBUG_REROUTER
525  if (DEBUGCOND) std::cout << " rerouting: newDest=" << newEdge->getID()
526  << " newEdges=" << toString(edges)
527  << " useNewRoute=" << useNewRoute << " newArrivalPos=" << newArrivalPos << " numClosed=" << rerouteDef->closed.size()
528  << " destUnreachable=" << destUnreachable << " containsClosed=" << veh.getRoute().containsAnyOf(rerouteDef->closed) << "\n";
529 #endif
530  if (useNewRoute && newArrivalPos != -1) {
531  // must be called here because replaceRouteEdges may also set the arrivalPos
532  veh.setArrivalPos(newArrivalPos);
533  }
534  }
535  return false; // XXX another interval could appear later but we would have to track whether the currenty interval was already used
536 }
537 
538 
539 void
541  myAmInUserMode = val;
542 }
543 
544 
545 void
547  myUserProbability = prob;
548 }
549 
550 
551 bool
553  return myAmInUserMode;
554 }
555 
556 
557 double
560 }
561 
562 
563 double
565  return myUserProbability;
566 }
567 
568 
569 double
570 MSTriggeredRerouter::getWeight(SUMOVehicle& veh, const std::string param, const double defaultWeight) const {
571  // get custom vehicle parameter
572  if (veh.getParameter().knowsParameter(param)) {
573  try {
574  return StringUtils::toDouble(veh.getParameter().getParameter(param, "-1"));
575  } catch (...) {
576  WRITE_WARNING("Invalid value '" + veh.getParameter().getParameter(param, "-1") + "' for vehicle parameter '" + param + "'");
577  }
578  } else {
579  // get custom vType parameter
580  if (veh.getVehicleType().getParameter().knowsParameter(param)) {
581  try {
582  return StringUtils::toDouble(veh.getVehicleType().getParameter().getParameter(param, "-1"));
583  } catch (...) {
584  WRITE_WARNING("Invalid value '" + veh.getVehicleType().getParameter().getParameter(param, "-1") + "' for vType parameter '" + param + "'");
585  }
586  }
587  }
588  //WRITE_MESSAGE("Vehicle '" +veh.getID() + "' does not supply vehicle parameter '" + param + "'. Using default of " + toString(defaultWeight) + "\n";
589  return defaultWeight;
590 }
591 
592 
595  SUMOVehicle& veh, bool& newDestination, ConstMSEdgeVector& newRoute) const {
596  // reroute destination from initial parking area to the near parking area
597  // if the next stop is a parking area, it is included in the current
598  // alternative set and if it can be observed to be full
599 
600  MSParkingArea* nearParkArea = nullptr;
601  std::vector<ParkingAreaVisible> parks = rerouteDef->parkProbs.getVals();
602 
603  // get vehicle params
604  MSParkingArea* destParkArea = veh.getNextParkingArea();
605  const MSRoute& route = veh.getRoute();
606 
607  if (destParkArea == nullptr) {
608  // not driving towards a parkingArea
609  return nullptr;
610  }
611 
612  bool destVisible = false;
613  for (auto paVis : parks) {
614  if (paVis.first == destParkArea
615  && (paVis.second
616  // if the vehicle is on the destParkArea edge it is always visible
617  || &(destParkArea->getLane().getEdge()) == veh.getEdge())) {
618  destVisible = true;
619  break;
620  }
621  }
622  if (!destVisible) {
623  // cannot determine destination occupancy
624  return nullptr;
625  }
626  if (destParkArea->getLastStepOccupancy() == destParkArea->getCapacity()) {
627  // if the current route ends at the parking area, the new route will
628  // also and at the new area
629  newDestination = (&destParkArea->getLane().getEdge() == route.getLastEdge()
630  && veh.getArrivalPos() >= destParkArea->getBeginLanePosition()
631  && veh.getArrivalPos() <= destParkArea->getEndLanePosition());
632 
633 #ifdef DEBUG_PARKING
634  if (DEBUGCOND) {
635  std::cout << SIMTIME << " veh=" << veh.getID()
636  << " rerouteParkingArea dest=" << destParkArea->getID()
637  << " onDestEdge=" << (&(destParkArea->getLane().getEdge()) == veh.getEdge())
638  << " newDest=" << newDestination
639  << "\n";
640  }
641 #endif
642 
643  typedef std::map<std::string, double> ParkingParamMap_t;
644  typedef std::map<MSParkingArea*, ParkingParamMap_t> MSParkingAreaMap_t;
645 
646  ParkingParamMap_t weights;
647  std::map<MSParkingArea*, ConstMSEdgeVector> newRoutes;
648 
649  // The probability of choosing this area inside the zone
650  weights["probability"] = getWeight(veh, "parking.probability.weight", 0.0);
651 
652  // The capacity of this area
653  weights["capacity"] = getWeight(veh, "parking.capacity.weight", 0.0);
654 
655  // The absolute number of free spaces
656  weights["absfreespace"] = getWeight(veh, "parking.absfreespace.weight", 0.0);
657 
658  // The relative number of free spaces
659  weights["relfreespace"] = getWeight(veh, "parking.relfreespace.weight", 0.0);
660 
661  // The distance to the new parking area
662  weights["distanceto"] = getWeight(veh, "parking.distanceto.weight", getWeight(veh, "parking.distance.weight", 1.0));
663 
664  // The time to reach this area
665  weights["timeto"] = getWeight(veh, "parking.timeto.weight", 0.0);
666 
667  // The distance from the new parking area
668  weights["distancefrom"] = getWeight(veh, "parking.distancefrom.weight", 0.0);
669 
670  // The time to reach the end from this area
671  weights["timefrom"] = getWeight(veh, "parking.timefrom.weight", 0.0);
672 
673  // a map stores maximum values to normalize parking values
674  ParkingParamMap_t maxValues;
675 
676  maxValues["probability"] = 0.0;
677  maxValues["capacity"] = 0.0;
678  maxValues["absfreespace"] = 0.0;
679  maxValues["relfreespace"] = 0.0;
680  maxValues["distanceto"] = 0.0;
681  maxValues["timeto"] = 0.0;
682  maxValues["distancefrom"] = 0.0;
683  maxValues["timefrom"] = 0.0;
684 
685  // a map stores elegible parking areas
686  MSParkingAreaMap_t parkAreas;
687 
689 
690  const std::vector<double>& probs = rerouteDef->parkProbs.getProbs();
691 
692  const double brakeGap = veh.getBrakeGap();
693 
694  for (int i = 0; i < (int)parks.size(); ++i) {
695  MSParkingArea* pa = parks[i].first;
696  const double prob = probs[i];
697  // alternative occupancy is randomized (but never full) if invisible
698  // current destination must be visible at this point
699  int paOccupancy = parks[i].second || pa == destParkArea ? pa->getOccupancy() : RandHelper::rand(pa->getCapacity());
700  if (paOccupancy < pa->getCapacity()) {
701 
702  // a map stores the parking values
703  ParkingParamMap_t parkValues;
704 
705  const RGBColor& c = route.getColor();
706  const MSEdge* parkEdge = &(pa->getLane().getEdge());
707 
708  const bool includeInternalLengths = MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks();
709 
710  // Compute the route from the current edge to the parking area edge
711  ConstMSEdgeVector edgesToPark;
712  if (veh.getEdge() == parkEdge && pa->getEndLanePosition() < veh.getPositionOnLane()) {
713  router.computeLooped(veh.getEdge(), parkEdge, &veh, MSNet::getInstance()->getCurrentTimeStep(), edgesToPark, true);
714  } else {
715  router.compute(veh.getEdge(), parkEdge, &veh, MSNet::getInstance()->getCurrentTimeStep(), edgesToPark, true);
716  }
717 
718  if (edgesToPark.size() > 0) {
719  // Compute the route from the parking area edge to the end of the route
720  ConstMSEdgeVector edgesFromPark;
721 
722  const MSEdge* nextDestination = route.getLastEdge();
723  double nextPos = veh.getArrivalPos();
724  int nextDestinationIndex = route.size() - 1;
725  if (!newDestination) {
726  std::vector<std::pair<int, double> > stopIndices = veh.getStopIndices();
727  if (stopIndices.size() > 1) {
728  nextDestinationIndex = stopIndices[1].first;
729  nextDestination = route.getEdges()[nextDestinationIndex];
730  nextPos = stopIndices[1].second;
731 
732  }
733  if (parkEdge == nextDestination && nextPos < pa->getEndLanePosition()) {
734  router.computeLooped(parkEdge, nextDestination, &veh, MSNet::getInstance()->getCurrentTimeStep(), edgesFromPark, true);
735  } else {
736  router.compute(parkEdge, nextDestination, &veh, MSNet::getInstance()->getCurrentTimeStep(), edgesFromPark, true);
737  }
738  }
739 
740  if (edgesFromPark.size() > 0 || newDestination) {
741 
742  parkValues["probability"] = prob;
743 
744  if (parkValues["probability"] > maxValues["probability"]) {
745  maxValues["probability"] = parkValues["probability"];
746  }
747 
748  parkValues["capacity"] = (double)(pa->getCapacity());
749  parkValues["absfreespace"] = (double)(pa->getCapacity() - paOccupancy);
750  parkValues["relfreespace"] = parkValues["absfreespace"] / parkValues["capacity"];
751 
752  if (parkValues["capacity"] > maxValues["capacity"]) {
753  maxValues["capacity"] = parkValues["capacity"];
754  }
755 
756  if (parkValues["absfreespace"] > maxValues["absfreespace"]) {
757  maxValues["absfreespace"] = parkValues["absfreespace"];
758  }
759 
760  if (parkValues["relfreespace"] > maxValues["relfreespace"]) {
761  maxValues["relfreespace"] = parkValues["relfreespace"];
762  }
763 
764  MSRoute routeToPark(route.getID() + "!topark#1", edgesToPark, false, &c == &RGBColor::DEFAULT_COLOR ? nullptr : new RGBColor(c), route.getStops());
765 
766  // The distance from the current edge to the new parking area
767  parkValues["distanceto"] = routeToPark.getDistanceBetween(veh.getPositionOnLane(), pa->getBeginLanePosition(),
768  routeToPark.begin(), routeToPark.end() - 1, includeInternalLengths);
769 
770  //std::cout << SIMTIME << " veh=" << veh.getID() << " candidate=" << pa->getID()
771  // << " distanceTo=" << parkValues["distanceto"]
772  // << " brakeGap=" << brakeGap
773  // << " routeToPark=" << toString(edgesToPark)
774  // << " fromPos=" << veh.getPositionOnLane()
775  // << " tPos=" << pa->getBeginLanePosition()
776  // << "\n";
777  if (parkValues["distanceto"] < brakeGap) {
778  //std::cout << " removed: pa too close\n";
779  // to close to stop for this parkingArea
780  continue;
781  }
782 
783  // The time to reach the new parking area
784  parkValues["timeto"] = router.recomputeCosts(edgesToPark, &veh, MSNet::getInstance()->getCurrentTimeStep());
785 
786  if (parkValues["distanceto"] > maxValues["distanceto"]) {
787  maxValues["distanceto"] = parkValues["distanceto"];
788  }
789 
790  if (parkValues["timeto"] > maxValues["timeto"]) {
791  maxValues["timeto"] = parkValues["timeto"];
792  }
793 
794  ConstMSEdgeVector newEdges = edgesToPark;
795 
796  if (newDestination) {
797  parkValues["distancefrom"] = 0;
798  parkValues["timefrom"] = 0;
799  } else {
800  MSRoute routeFromPark(route.getID() + "!frompark#1", edgesFromPark, false,
801  &c == &RGBColor::DEFAULT_COLOR ? nullptr : new RGBColor(c), route.getStops());
802  // The distance from the new parking area to the end of the route
803  parkValues["distancefrom"] = routeFromPark.getDistanceBetween(pa->getBeginLanePosition(), routeFromPark.getLastEdge()->getLength(),
804  routeFromPark.begin(), routeFromPark.end() - 1, includeInternalLengths);
805  // The time to reach this area
806  parkValues["timefrom"] = router.recomputeCosts(edgesFromPark, &veh, MSNet::getInstance()->getCurrentTimeStep());
807  newEdges.insert(newEdges.end(), edgesFromPark.begin() + 1, edgesFromPark.end());
808  newEdges.insert(newEdges.end(), route.begin() + nextDestinationIndex + 1, route.end());
809  }
810 
811  if (parkValues["distancefrom"] > maxValues["distancefrom"]) {
812  maxValues["distancefrom"] = parkValues["distancefrom"];
813  }
814 
815  if (parkValues["timefrom"] > maxValues["timefrom"]) {
816  maxValues["timefrom"] = parkValues["timefrom"];
817  }
818 
819  parkAreas[pa] = parkValues;
820  newRoutes[pa] = newEdges;
821 
822 #ifdef DEBUG_PARKING
823  if (DEBUGCOND) {
824  std::cout << " altPA=" << pa->getID()
825  << " vals=" << joinToString(parkValues, " ", ":")
826  << "\n";
827  }
828 #endif
829  }
830  }
831  }
832  }
833  MSNet::getInstance()->getRouterTT(veh.getRNGIndex()); // reset closed edges
834 
835 #ifdef DEBUG_PARKING
836  if (DEBUGCOND) {
837  std::cout << " maxValues=" << joinToString(maxValues, " ", ":") << "\n";
838  }
839 #endif
840 
841  // minimum cost to get the parking area
842  double minParkingCost = 0.0;
843 
844  for (MSParkingAreaMap_t::iterator it = parkAreas.begin(); it != parkAreas.end(); ++it) {
845  // get the parking values
846  ParkingParamMap_t parkValues = it->second;
847 
848  // normalizing parking values with maximum values (we want to maximize some parameters then we reverse the value)
849  parkValues["probability"] = maxValues["probability"] > 0.0 ? 1.0 - parkValues["probability"] / maxValues["probability"] : 0.0;
850  parkValues["capacity"] = maxValues["capacity"] > 0.0 ? 1.0 - parkValues["capacity"] / maxValues["capacity"] : 0.0;
851  parkValues["absfreespace"] = maxValues["absfreespace"] > 0.0 ? 1.0 - parkValues["absfreespace"] / maxValues["absfreespace"] : 0.0;
852  parkValues["relfreespace"] = maxValues["relfreespace"] > 0.0 ? 1.0 - parkValues["relfreespace"] / maxValues["relfreespace"] : 0.0;
853 
854  parkValues["distanceto"] = maxValues["distanceto"] > 0.0 ? parkValues["distanceto"] / maxValues["distanceto"] : 0.0;
855  parkValues["timeto"] = maxValues["timeto"] > 0.0 ? parkValues["timeto"] / maxValues["timeto"] : 0.0;
856 
857  parkValues["distancefrom"] = maxValues["distancefrom"] > 0.0 ? parkValues["distancefrom"] / maxValues["distancefrom"] : 0.0;
858  parkValues["timefrom"] = maxValues["timefrom"] > 0.0 ? parkValues["timefrom"] / maxValues["timefrom"] : 0.0;
859 
860  // get the parking area cost
861  double parkingCost = 0.0;
862 
863  // sum every index with its weight
864  for (ParkingParamMap_t::iterator pc = parkValues.begin(); pc != parkValues.end(); ++pc) {
865  parkingCost += weights[pc->first] * pc->second;
866  }
867 
868  // get the parking area with minimum cost
869  if (nearParkArea == nullptr || parkingCost < minParkingCost) {
870  minParkingCost = parkingCost;
871  nearParkArea = it->first;
872  newRoute = newRoutes[nearParkArea];
873  }
874 
875 #ifdef DEBUG_PARKING
876  if (DEBUGCOND) {
877  std::cout << " altPA=" << it->first->getID() << " score=" << parkingCost << "\n";
878  }
879 #endif
880  }
881  }
882 
883 #ifdef DEBUG_PARKING
884  if (DEBUGCOND) {
885  std::cout << " parkingResult=" << Named::getIDSecure(nearParkArea) << "\n";
886  }
887 #endif
888 
889  return nearParkArea;
890 }
891 
892 
893 bool
895  if (myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getOriginalID()) > 0) {
896  return true;
897  } else {
899  for (auto vTypeDist : vTypeDists) {
900  if (myVehicleTypes.count(vTypeDist) > 0) {
901  return true;
902  }
903  }
904  return false;
905  }
906 }
907 
908 
909 /****************************************************************************/
910 
SUMOAbstractRouter::compute
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...
MSTriggeredRerouter::myCurrentIntervalBegin
SUMOTime myCurrentIntervalBegin
The first and the last time steps of the interval.
Definition: MSTriggeredRerouter.h:235
MSStoppingPlace::getLane
const MSLane & getLane() const
Returns the lane this stop is located at.
Definition: MSStoppingPlace.cpp:57
MSTriggeredRerouter::notifyMove
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.
Definition: MSTriggeredRerouter.cpp:349
MSTriggeredRerouter::getCurrentReroute
const RerouteInterval * getCurrentReroute(SUMOTime time, SUMOVehicle &veh) const
Returns the rerouting definition valid for the given time and vehicle, 0 if none.
Definition: MSTriggeredRerouter.cpp:313
MSMoveReminder::NOTIFICATION_LANE_CHANGE
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
Definition: MSMoveReminder.h:99
SUMOVehicle::getRNGIndex
virtual int getRNGIndex() const =0
RGBColor::DEFAULT_COLOR
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:203
MSTriggeredRerouter::RerouteInterval::routeProbs
RandomDistributor< const MSRoute * > routeProbs
The distributions of new routes to use.
Definition: MSTriggeredRerouter.h:107
RandomDistributor::add
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
Definition: RandomDistributor.h:70
MSNet::hasInternalLinks
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:643
MSTriggeredRerouter::RerouteInterval
Definition: MSTriggeredRerouter.h:91
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
MSNet::getRouterTT
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:968
MSNet::getStoppingPlace
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:911
ToString.h
SUMOTrafficObject::getWaitingTime
virtual SUMOTime getWaitingTime() const =0
ARRIVAL_POS_GIVEN
@ ARRIVAL_POS_GIVEN
The arrival position is given.
Definition: SUMOVehicleParameter.h:234
MSLane::dictionary
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1866
SUMOSAXAttributes::hasAttribute
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
MSParkingArea
A lane area vehicles can halt at.
Definition: MSParkingArea.h:59
MSEventControl::addEvent
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Definition: MSEventControl.cpp:52
MSDevice_Routing
A device that performs vehicle rerouting based on current edge speeds.
Definition: MSDevice_Routing.h:60
SUMO_ATTR_DISALLOW
@ SUMO_ATTR_DISALLOW
Definition: SUMOXMLDefinitions.h:783
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
SUMOVehicle::replaceParameter
virtual void replaceParameter(const SUMOVehicleParameter *newParameter)=0
Replaces the vehicle's parameter.
SUMOVehicle::getRNG
virtual std::mt19937 * getRNG() const =0
Returns the associated RNG for this vehicle.
SUMOVehicle::replaceRouteEdges
virtual bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true)=0
Replaces the current route by the given edges.
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:41
SUMOVehicle::getParameter
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
MESegment
A single mesoscopic segment (cell)
Definition: MESegment.h:49
MSStoppingPlace::getEndLanePosition
double getEndLanePosition() const
Returns the end position of this stop.
Definition: MSStoppingPlace.cpp:69
SUMOVehicle::getStopIndices
virtual std::vector< std::pair< int, double > > getStopIndices() const =0
return list of route indices and stop positions for the remaining stops
MSRoute::end
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:75
SUMOVehicle::replaceParkingArea
virtual bool replaceParkingArea(MSParkingArea *parkingArea, std::string &errorMsg)=0
Replaces a stop.
OptionsCont.h
SUMOTrafficObject::getEdge
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
MSParkingArea::getLastStepOccupancy
int getLastStepOccupancy() const
Returns the area occupancy at the end of the last simulation step.
Definition: MSParkingArea.h:115
SUMOTrafficObject::isVehicle
virtual bool isVehicle() const =0
Get the vehicle's ID.
StringUtils::toDouble
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
Definition: StringUtils.cpp:345
MESegment::addDetector
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Definition: MESegment.cpp:211
MSTriggeredRerouter::RerouteInterval::permissions
SVCPermissions permissions
The permissions to use.
Definition: MSTriggeredRerouter.h:109
MSNet::getBeginOfTimestepEvents
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:429
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
MsgHandler.h
SUMOVehicle::getCurrentRouteEdge
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
MSTriggeredRerouter::myCurrentIntervalEnd
SUMOTime myCurrentIntervalEnd
Definition: MSTriggeredRerouter.h:235
MSStoppingPlace::getBeginLanePosition
double getBeginLanePosition() const
Returns the begin position of this stop.
Definition: MSStoppingPlace.cpp:63
WrappingCommand.h
SUMOVehicle::getAccumulatedWaitingTime
virtual SUMOTime getAccumulatedWaitingTime() const =0
SUMOSAXHandler.h
MSTriggeredRerouter::myUserProbability
double myUserProbability
Definition: MSTriggeredRerouter.h:220
MSGlobals::gNumSimThreads
static int gNumSimThreads
how many threads to use for simulation
Definition: MSGlobals.h:123
MSRoute::getLastEdge
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:87
MSTriggeredRerouter::getUserProbability
double getUserProbability() const
Returns the rerouting probability given by the user.
Definition: MSTriggeredRerouter.cpp:564
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
WrappingCommand
A wrapper for a Command function.
Definition: WrappingCommand.h:51
MSTriggeredRerouter::myCurrentPermissions
SVCPermissions myCurrentPermissions
List of permissions for closed edges.
Definition: MSTriggeredRerouter.h:241
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:75
MSTriggeredRerouter::myCurrentClosedLanes
std::vector< MSLane * > myCurrentClosedLanes
List of closed lanes.
Definition: MSTriggeredRerouter.h:239
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:90
MSRoute::getEdges
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:120
MSTriggeredRerouter::myVehicleTypes
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
Definition: MSTriggeredRerouter.h:229
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
MSEdge.h
MSTriggeredRerouter::rerouteParkingArea
MSParkingArea * rerouteParkingArea(const MSTriggeredRerouter::RerouteInterval *rerouteDef, SUMOVehicle &veh, bool &newDestination, ConstMSEdgeVector &newRoute) const
Definition: MSTriggeredRerouter.cpp:594
MSTriggeredRerouter::setPermissions
SUMOTime setPermissions(const SUMOTime currentTime)
Sets the edge permission if there are any defined in the closingEdge.
Definition: MSTriggeredRerouter.cpp:277
MSTransportable
Definition: MSTransportable.h:58
MSRoute::getColor
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:367
MSTriggeredRerouter::MSTriggeredRerouter
MSTriggeredRerouter(const std::string &id, const MSEdgeVector &edges, double prob, const std::string &file, bool off, SUMOTime timeThreshold, const std::string &vTypes)
Constructor.
Definition: MSTriggeredRerouter.cpp:71
MSTriggeredRerouter::RerouteInterval::edgeProbs
RandomDistributor< MSEdge * > edgeProbs
The distributions of new destinations to use.
Definition: MSTriggeredRerouter.h:105
MSRoutingEngine::getRouterTT
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
Definition: MSRoutingEngine.cpp:307
MSEdge::getLength
double getLength() const
return the length of the edge
Definition: MSEdge.h:589
MSRoute
Definition: MSRoute.h:66
MSTriggeredRerouter::myTimeThreshold
SUMOTime myTimeThreshold
Definition: MSTriggeredRerouter.h:226
SVC_AUTHORITY
@ SVC_AUTHORITY
authorities vehicles
Definition: SUMOVehicleClass.h:145
MSTriggeredRerouter::myCurrentParkProb
RandomDistributor< ParkingAreaVisible > myCurrentParkProb
new destinations with probabilities
Definition: MSTriggeredRerouter.h:243
SUMOVehicle::getNextParkingArea
virtual MSParkingArea * getNextParkingArea()=0
Parameterised::getParameter
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
Definition: Parameterised.cpp:72
MSVehicle.h
MSMoveReminder
Something on a lane to be noticed about vehicle movement.
Definition: MSMoveReminder.h:66
MSTriggeredRerouter::setUserMode
void setUserMode(bool val)
Sets whether the process is currently steered by the user.
Definition: MSTriggeredRerouter.cpp:540
SUMO_ATTR_BEGIN
@ SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:678
MESegment.h
SUMOVehicle::getPersons
virtual const std::vector< MSTransportable * > & getPersons() const =0
retrieve riding persons
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
SUMO_TAG_PARKING_ZONE_REROUTE
@ SUMO_TAG_PARKING_ZONE_REROUTE
entry for an alternative parking zone
Definition: SUMOXMLDefinitions.h:198
MSTriggeredRerouter::myProbability
double myProbability
The probability and the user-given probability.
Definition: MSTriggeredRerouter.h:220
parseVehicleClasses
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
Definition: SUMOVehicleClass.cpp:222
MSVehicleType::getOriginalID
const std::string & getOriginalID() const
Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise.
Definition: MSVehicleType.h:555
SUMOVehicle::getRoute
virtual const MSRoute & getRoute() const =0
Returns the current route.
RandomDistributor::get
T get(std::mt19937 *which=0) const
Draw a sample of the distribution.
Definition: RandomDistributor.h:113
SUMO_TAG_DEST_PROB_REROUTE
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destiny of a reroute
Definition: SUMOXMLDefinitions.h:190
MSRoute::size
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:81
RGBColor
Definition: RGBColor.h:39
MSTriggeredRerouter::notifyLeave
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes the reminder.
Definition: MSTriggeredRerouter.cpp:356
RandHelper::rand
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:53
SIMTIME
#define SIMTIME
Definition: SUMOTime.h:63
MSTriggeredRerouter::notifyEnter
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Tries to reroute the vehicle.
Definition: MSTriggeredRerouter.cpp:363
MSTriggeredRerouter::getWeight
double getWeight(SUMOVehicle &veh, const std::string param, const double defaultWeight) const
Definition: MSTriggeredRerouter.cpp:570
MSTriggeredRerouter::mySpecialDest_keepDestination
static MSEdge mySpecialDest_keepDestination
special destination values
Definition: MSTriggeredRerouter.h:252
SUMO_ATTR_PROB
@ SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:629
MSVehicleControl::getVTypeDistributionMembership
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
Definition: MSVehicleControl.cpp:384
MSEdgeWeightsStorage.h
SUMOAbstractRouter::computeLooped
bool computeLooped(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)
Builds the route between the given edges using the minimum effort at the given time if from == to,...
Definition: SUMOAbstractRouter.h:130
RandomDistributor::remove
bool remove(T val)
Removes a value with an assigned probability from the distribution.
Definition: RandomDistributor.h:94
MSTriggeredRerouter::setUserUsageProbability
void setUserUsageProbability(double prob)
Sets the probability with which a vehicle is rerouted given by the user.
Definition: MSTriggeredRerouter.cpp:546
SUMOVehicle::setArrivalPos
virtual void setArrivalPos(double arrivalPos)=0
Sets this vehicle's desired arrivalPos for its current route.
MSNet::getCurrentTimeStep
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:283
StringTokenizer
Definition: StringTokenizer.h:61
MSTriggeredRerouter::myEndElement
virtual void myEndElement(int element)
Called when a closing tag occurs.
Definition: MSTriggeredRerouter.cpp:236
MSParkingArea::getCapacity
int getCapacity() const
Returns the area capacity.
Definition: MSParkingArea.cpp:348
MSEdge::dictionary
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....
Definition: MSEdge.cpp:765
SUMOVehicle::getDevice
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
FXConditionalLock
A scoped lock which only triggers on condition.
Definition: FXConditionalLock.h:36
SUMOVehicle::getLane
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
SUMOVehicle::replaceRoute
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.
SUMO_TAG_PARKING_AREA
@ SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:107
MELoop::getSegmentForEdge
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition: MELoop.cpp:292
SUMOVehicleParameter::arrivalPos
double arrivalPos
(optional) The position the vehicle shall arrive on
Definition: SUMOVehicleParameter.h:522
MSTriggeredRerouter::myCurrentRouteProb
RandomDistributor< const MSRoute * > myCurrentRouteProb
new routes with probabilities
Definition: MSTriggeredRerouter.h:247
MSTriggeredRerouter::RerouteInterval::closedLanes
std::vector< MSLane * > closedLanes
The list of closed lanes.
Definition: MSTriggeredRerouter.h:101
ProcessError
Definition: UtilExceptions.h:39
SUMOVehicleParameter::arrivalPosProcedure
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
Definition: SUMOVehicleParameter.h:525
SUMO_TAG_ROUTE_PROB_REROUTE
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
Definition: SUMOXMLDefinitions.h:196
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSGlobals.h
UtilExceptions.h
MSDevice_Routing.h
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
RandomDistributor::clear
void clear()
Clears the distribution.
Definition: RandomDistributor.h:138
SUMOSAXAttributes::getOpt
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.
Definition: SUMOSAXAttributes.h:518
MSTriggeredRerouter::~MSTriggeredRerouter
virtual ~MSTriggeredRerouter()
Destructor.
Definition: MSTriggeredRerouter.cpp:104
RandomDistributor::getProbs
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
Definition: RandomDistributor.h:162
SUMOVehicle::getBrakeGap
virtual double getBrakeGap() const =0
get distance for coming to a stop (used for rerouting checks)
MSParkingArea.h
MSRoutingEngine.h
MSTriggeredRerouter::myCurrentEdgeProb
RandomDistributor< MSEdge * > myCurrentEdgeProb
new destinations with probabilities
Definition: MSTriggeredRerouter.h:245
SUMO_TAG_CLOSING_REROUTE
@ SUMO_TAG_CLOSING_REROUTE
reroute of type closing
Definition: SUMOXMLDefinitions.h:192
RandomDistributor< MSEdge * >
MSTrigger
An abstract device that changes the state of the micro simulation.
Definition: MSTrigger.h:40
MSGlobals::gUsingInternalLanes
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:68
SUMOAbstractRouter< MSEdge, SUMOVehicle >
MSTriggeredRerouter::RerouteInterval::begin
SUMOTime begin
The begin time these definitions are valid.
Definition: MSTriggeredRerouter.h:95
MSLane::getEdge
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:669
MSTriggeredRerouter::mySpecialDest_terminateRoute
static MSEdge mySpecialDest_terminateRoute
Definition: MSTriggeredRerouter.h:253
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
MSParkingArea::getOccupancy
int getOccupancy() const
Returns the area occupancy.
Definition: MSParkingArea.cpp:354
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
SUMOSAXAttributes::getOptSUMOTimeReporting
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.
Definition: SUMOSAXAttributes.cpp:90
MSGlobals::gMesoNet
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:105
MSTriggeredRerouter::inUserMode
bool inUserMode() const
Returns whether the user is setting the rerouting probability.
Definition: MSTriggeredRerouter.cpp:552
SUMOAbstractRouter::recomputeCosts
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
Definition: SUMOAbstractRouter.h:195
MSTriggeredRerouter.h
MSTriggeredRerouter::myAmInUserMode
bool myAmInUserMode
Information whether the current rerouting probability is the user-given.
Definition: MSTriggeredRerouter.h:223
MSTransportable.h
SVCAll
const SVCPermissions SVCAll
all VClasses are allowed
Definition: SUMOVehicleClass.cpp:146
SUMO_ATTR_VISIBLE
@ SUMO_ATTR_VISIBLE
Definition: SUMOXMLDefinitions.h:896
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
MSRoute.h
SUMO_ATTR_ALLOW
@ SUMO_ATTR_ALLOW
Definition: SUMOXMLDefinitions.h:782
MSRoute::getStops
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:376
MSVehicleType::getParameter
const SUMOVTypeParameter & getParameter() const
Definition: MSVehicleType.h:560
joinToString
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:246
SUMOVehicle::getArrivalPos
virtual double getArrivalPos() const =0
Returns this vehicle's desired arrivalPos for its current route (may change on reroute)
MSRoute::begin
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
StringTokenizer::getVector
std::vector< std::string > getVector()
return vector of strings
Definition: StringTokenizer.cpp:191
MSTriggeredRerouter::myIntervals
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
Definition: MSTriggeredRerouter.h:217
MSRoute::dictionary
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:113
config.h
EDGEFUNC_UNKNOWN
@ EDGEFUNC_UNKNOWN
Definition: SUMOXMLDefinitions.h:1080
Named::getIDSecure
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition: Named.h:69
SUMO_TAG_CLOSING_LANE_REROUTE
@ SUMO_TAG_CLOSING_LANE_REROUTE
lane of a reroute of type closing
Definition: SUMOXMLDefinitions.h:194
RandHelper.h
DijkstraRouter.h
SUMO_ATTR_END
@ SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:680
DEBUGCOND
#define DEBUGCOND
Definition: MSTriggeredRerouter.cpp:59
MELoop.h
Command.h
SUMO_TAG_INTERVAL
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
Definition: SUMOXMLDefinitions.h:159
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:35
MSEventControl.h
MSLane.h
SUMOSAXAttributes::getStringSecure
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
MSTriggeredRerouter::myStartElement
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: MSTriggeredRerouter.cpp:109
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
MSRoute::containsAnyOf
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:238
MSTriggeredRerouter::RerouteInterval::end
SUMOTime end
The end time these definitions are valid.
Definition: MSTriggeredRerouter.h:97
MSTriggeredRerouter::RerouteInterval::closed
MSEdgeVector closed
The list of closed edges.
Definition: MSTriggeredRerouter.h:99
RandomDistributor::getOverallProb
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
Definition: RandomDistributor.h:133
MSRoute::getDistanceBetween
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....
Definition: MSRoute.cpp:278
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
MSMoveReminder::NOTIFICATION_JUNCTION
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
Definition: MSMoveReminder.h:95
MSTriggeredRerouter::RerouteInterval::closedLanesAffected
MSEdgeVector closedLanesAffected
The list of edges that are affect by closed lanes.
Definition: MSTriggeredRerouter.h:103
MSTriggeredRerouter::RerouteInterval::parkProbs
RandomDistributor< ParkingAreaVisible > parkProbs
The distributions of new parking areas to use as destinations.
Definition: MSTriggeredRerouter.h:111
MSTriggeredRerouter::myCurrentClosed
MSEdgeVector myCurrentClosed
List of closed edges.
Definition: MSTriggeredRerouter.h:237
SUMOXMLDefinitions.h
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
MSTriggeredRerouter::vehicleApplies
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
Definition: MSTriggeredRerouter.cpp:894
RandomDistributor::getVals
const std::vector< T > & getVals() const
Returns the members of the distribution.
Definition: RandomDistributor.h:151
Parameterised::knowsParameter
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
Definition: Parameterised.cpp:66
MSTriggeredRerouter::getProbability
double getProbability() const
Returns the rerouting probability.
Definition: MSTriggeredRerouter.cpp:558