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