Eclipse SUMO - Simulation of Urban MObility
ROMAAssignments.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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // Assignment methods
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <vector>
25 #include <algorithm>
26 #include <utils/common/SUMOTime.h>
30 #include <router/ROEdge.h>
31 #include <router/RONet.h>
32 #include <router/RORoute.h>
33 #include <od/ODMatrix.h>
34 #include "ROMAEdge.h"
35 #include "ROMAAssignments.h"
36 
37 
38 // ===========================================================================
39 // static member variables
40 // ===========================================================================
41 std::map<const ROEdge* const, double> ROMAAssignments::myPenalties;
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 
48 ROMAAssignments::ROMAAssignments(const SUMOTime begin, const SUMOTime end, const bool additiveTraffic,
49  const double adaptionFactor, const int maxAlternatives, RONet& net, ODMatrix& matrix,
51  : myBegin(begin), myEnd(end), myAdditiveTraffic(additiveTraffic), myAdaptionFactor(adaptionFactor),
52  myMaxAlternatives(maxAlternatives), myNet(net), myMatrix(matrix), myRouter(router) {
54 }
55 
56 
58  delete myDefaultVehicle;
59 }
60 
61 // based on the definitions in PTV-Validate and in the VISUM-Cologne network
62 double
64  if (edge->isTazConnector()) {
65  return 0;
66  }
67  const int roadClass = -edge->getPriority();
68  // TODO: differ road class 1 from the unknown road class 1!!!
69  if (edge->getNumLanes() == 0) {
70  // TAZ have no cost
71  return 0;
72  } else if (roadClass == 0 || roadClass == 1) {
73  return edge->getNumLanes() * 2000.; //CR13 in table.py
74  } else if (roadClass == 2 && edge->getSpeedLimit() <= 11.) {
75  return edge->getNumLanes() * 1333.33; //CR5 in table.py
76  } else if (roadClass == 2 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 16.) {
77  return edge->getNumLanes() * 1500.; //CR3 in table.py
78  } else if (roadClass == 2 && edge->getSpeedLimit() > 16.) {
79  return edge->getNumLanes() * 2000.; //CR13 in table.py
80  } else if (roadClass == 3 && edge->getSpeedLimit() <= 11.) {
81  return edge->getNumLanes() * 800.; //CR5 in table.py
82  } else if (roadClass == 3 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
83  return edge->getNumLanes() * 875.; //CR5 in table.py
84  } else if (roadClass == 3 && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
85  return edge->getNumLanes() * 1500.; //CR4 in table.py
86  } else if (roadClass == 3 && edge->getSpeedLimit() > 16.) {
87  return edge->getNumLanes() * 1800.; //CR13 in table.py
88  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() <= 5.) {
89  return edge->getNumLanes() * 200.; //CR7 in table.py
90  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 5. && edge->getSpeedLimit() <= 7.) {
91  return edge->getNumLanes() * 412.5; //CR7 in table.py
92  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 7. && edge->getSpeedLimit() <= 9.) {
93  return edge->getNumLanes() * 600.; //CR6 in table.py
94  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 9. && edge->getSpeedLimit() <= 11.) {
95  return edge->getNumLanes() * 800.; //CR5 in table.py
96  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
97  return edge->getNumLanes() * 1125.; //CR5 in table.py
98  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
99  return edge->getNumLanes() * 1583.; //CR4 in table.py
100  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 16. && edge->getSpeedLimit() <= 18.) {
101  return edge->getNumLanes() * 1100.; //CR3 in table.py
102  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 18. && edge->getSpeedLimit() <= 22.) {
103  return edge->getNumLanes() * 1200.; //CR3 in table.py
104  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 22. && edge->getSpeedLimit() <= 26.) {
105  return edge->getNumLanes() * 1300.; //CR3 in table.py
106  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 26.) {
107  return edge->getNumLanes() * 1400.; //CR3 in table.py
108  }
109  return edge->getNumLanes() * 800.; //CR5 in table.py
110 }
111 
112 
113 // based on the definitions in PTV-Validate and in the VISUM-Cologne network
114 double
115 ROMAAssignments::capacityConstraintFunction(const ROEdge* edge, const double flow) const {
116  if (edge->isTazConnector()) {
117  return 0;
118  }
119  const int roadClass = -edge->getPriority();
120  const double capacity = getCapacity(edge);
121  // TODO: differ road class 1 from the unknown road class 1!!!
122  if (edge->getNumLanes() == 0) {
123  // TAZ have no cost
124  return 0;
125  } else if (roadClass == 0 || roadClass == 1) {
126  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.3)) * 2.); //CR13 in table.py
127  } else if (roadClass == 2 && edge->getSpeedLimit() <= 11.) {
128  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
129  } else if (roadClass == 2 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 16.) {
130  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
131  } else if (roadClass == 2 && edge->getSpeedLimit() > 16.) {
132  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.3)) * 2.); //CR13 in table.py
133  } else if (roadClass == 3 && edge->getSpeedLimit() <= 11.) {
134  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
135  } else if (roadClass == 3 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
136  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
137  } else if (roadClass == 3 && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
138  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.7 * (flow / (capacity * 1.)) * 2.); //CR4 in table.py
139  } else if (roadClass == 3 && edge->getSpeedLimit() > 16.) {
140  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.3)) * 2.); //CR13 in table.py
141  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() <= 5.) {
142  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.5)) * 3.); //CR7 in table.py
143  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 5. && edge->getSpeedLimit() <= 7.) {
144  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.5)) * 3.); //CR7 in table.py
145  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 7. && edge->getSpeedLimit() <= 9.) {
146  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.8)) * 3.); //CR6 in table.py
147  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 9. && edge->getSpeedLimit() <= 11.) {
148  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
149  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
150  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
151  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
152  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.7 * (flow / (capacity * 1.)) * 2.); //CR4 in table.py
153  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 16. && edge->getSpeedLimit() <= 18.) {
154  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
155  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 18. && edge->getSpeedLimit() <= 22.) {
156  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
157  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 22. && edge->getSpeedLimit() <= 26.) {
158  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
159  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 26.) {
160  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
161  }
162  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
163 }
164 
165 
166 bool
167 ROMAAssignments::addRoute(const ConstROEdgeVector& edges, std::vector<RORoute*>& paths, std::string routeId, double prob) {
168  std::vector<RORoute*>::iterator p;
169  for (p = paths.begin(); p != paths.end(); p++) {
170  if (edges == (*p)->getEdgeVector()) {
171  break;
172  }
173  }
174  if (p == paths.end()) {
175  paths.push_back(new RORoute(routeId, 0., prob, edges, nullptr, std::vector<SUMOVehicleParameter::Stop>()));
176  return true;
177  }
178  (*p)->addProbability(prob);
179  std::iter_swap(paths.end() - 1, p);
180  return false;
181 }
182 
183 
184 const ConstROEdgeVector
185 ROMAAssignments::computePath(ODCell* cell, const SUMOTime time, const double probability, SUMOAbstractRouter<ROEdge, ROVehicle>* router) {
186  const ROEdge* const from = myNet.getEdge(cell->origin + (cell->originIsEdge ? "" : "-source"));
187  if (from == nullptr) {
188  throw ProcessError("Unknown origin '" + cell->origin + "'.");
189  }
190  const ROEdge* const to = myNet.getEdge(cell->destination + (cell->destinationIsEdge ? "" : "-sink"));
191  if (to == nullptr) {
192  throw ProcessError("Unknown destination '" + cell->destination + "'.");
193  }
194  ConstROEdgeVector edges;
195  if (router == nullptr) {
196  router = &myRouter;
197  }
198  if (myMaxAlternatives > 0 && (int)cell->pathsVector.size() < myMaxAlternatives) {
199  router->compute(from, to, myDefaultVehicle, time, edges);
200  if (addRoute(edges, cell->pathsVector, cell->origin + cell->destination + toString(cell->pathsVector.size()), probability)) {
201  return edges;
202  }
203  } else {
204  double minCost = std::numeric_limits<double>::max();
205  RORoute* minRoute = nullptr;
206  for (RORoute* const p : cell->pathsVector) {
207  const double cost = router->recomputeCosts(edges, myDefaultVehicle, time);
208  if (cost < minCost) {
209  minCost = cost;
210  minRoute = p;
211  }
212  }
213  minRoute->addProbability(probability);
214  }
215  return ConstROEdgeVector();
216 }
217 
218 
219 void
220 ROMAAssignments::getKPaths(const int kPaths, const double penalty) {
221  for (ODCell* const c : myMatrix.getCells()) {
222  myPenalties.clear();
223  for (int k = 0; k < kPaths; k++) {
224  for (const ROEdge* const e : computePath(c)) {
225  myPenalties[e] += penalty;
226  }
227  }
228  }
229  myPenalties.clear();
230 }
231 
232 
233 void
235  const double begin = STEPS2TIME(MIN2(myBegin, myMatrix.getCells().front()->begin));
236  for (std::map<std::string, ROEdge*>::const_iterator i = myNet.getEdgeMap().begin(); i != myNet.getEdgeMap().end(); ++i) {
237  ROMAEdge* edge = static_cast<ROMAEdge*>(i->second);
238  edge->setFlow(begin, STEPS2TIME(myEnd), 0.);
239  edge->setHelpFlow(begin, STEPS2TIME(myEnd), 0.);
240  }
241 }
242 
243 
244 void
245 ROMAAssignments::incremental(const int numIter, const bool verbose) {
246  SUMOTime lastBegin = -1;
247  std::vector<int> intervals;
248  int count = 0;
249  for (const ODCell* const c : myMatrix.getCells()) {
250  if (c->begin != lastBegin) {
251  intervals.push_back(count);
252  lastBegin = c->begin;
253  }
254  count++;
255  }
256  lastBegin = -1;
257  for (std::vector<int>::const_iterator offset = intervals.begin(); offset != intervals.end(); offset++) {
258  std::vector<ODCell*>::const_iterator cellsEnd = myMatrix.getCells().end();
259  if (offset != intervals.end() - 1) {
260  cellsEnd = myMatrix.getCells().begin() + (*(offset + 1));
261  }
262  const SUMOTime intervalStart = (*(myMatrix.getCells().begin() + (*offset)))->begin;
263  if (verbose) {
264  WRITE_MESSAGE(" starting interval " + time2string(intervalStart));
265  }
266  std::map<const ROMAEdge*, double> loadedTravelTimes;
267  for (std::map<std::string, ROEdge*>::const_iterator i = myNet.getEdgeMap().begin(); i != myNet.getEdgeMap().end(); ++i) {
268  ROMAEdge* edge = static_cast<ROMAEdge*>(i->second);
269  if (edge->hasLoadedTravelTime(STEPS2TIME(intervalStart))) {
270  loadedTravelTimes[edge] = edge->getTravelTime(myDefaultVehicle, STEPS2TIME(intervalStart));
271  }
272  }
273  for (int t = 0; t < numIter; t++) {
274  if (verbose) {
275  WRITE_MESSAGE(" starting iteration " + toString(t));
276  }
277  std::string lastOrigin = "";
278  int workerIndex = 0;
279  for (std::vector<ODCell*>::const_iterator i = myMatrix.getCells().begin() + (*offset); i != cellsEnd; i++) {
280  ODCell* const c = *i;
281  const double linkFlow = c->vehicleNumber / numIter;
282  const SUMOTime begin = myAdditiveTraffic ? myBegin : c->begin;
283 #ifdef HAVE_FOX
284  if (myNet.getThreadPool().size() > 0) {
285  if (lastOrigin != c->origin) {
286  workerIndex++;
287  if (workerIndex == myNet.getThreadPool().size()) {
288  workerIndex = 0;
289  }
290  myNet.getThreadPool().add(new RONet::BulkmodeTask(false), workerIndex);
291  lastOrigin = c->origin;
292  myNet.getThreadPool().add(new RoutingTask(*this, c, begin, linkFlow), workerIndex);
293  myNet.getThreadPool().add(new RONet::BulkmodeTask(true), workerIndex);
294  } else {
295  myNet.getThreadPool().add(new RoutingTask(*this, c, begin, linkFlow), workerIndex);
296  }
297  continue;
298  }
299 #endif
300  if (lastOrigin != c->origin) {
301  myRouter.setBulkMode(false);
302  lastOrigin = c->origin;
303  }
304  computePath(c, begin, linkFlow);
305  myRouter.setBulkMode(true);
306  }
307 #ifdef HAVE_FOX
308  if (myNet.getThreadPool().size() > 0) {
309  myNet.getThreadPool().waitAll();
310  }
311 #endif
312  for (std::vector<ODCell*>::const_iterator i = myMatrix.getCells().begin() + (*offset); i != cellsEnd; i++) {
313  ODCell* const c = *i;
314  const double linkFlow = c->vehicleNumber / numIter;
315  const SUMOTime begin = myAdditiveTraffic ? myBegin : c->begin;
316  const SUMOTime end = myAdditiveTraffic ? myEnd : c->end;
317  const double intervalLengthInHours = STEPS2TIME(end - begin) / 3600.;
318  const ConstROEdgeVector& edges = c->pathsVector.back()->getEdgeVector();
319  for (ConstROEdgeVector::const_iterator e = edges.begin(); e != edges.end(); e++) {
320  ROMAEdge* edge = static_cast<ROMAEdge*>(myNet.getEdge((*e)->getID()));
321  const double newFlow = edge->getFlow(STEPS2TIME(begin)) + linkFlow;
322  edge->setFlow(STEPS2TIME(begin), STEPS2TIME(end), newFlow);
323  double travelTime = capacityConstraintFunction(edge, newFlow / intervalLengthInHours);
324  if (lastBegin >= 0 && myAdaptionFactor > 0.) {
325  if (loadedTravelTimes.count(edge) != 0) {
326  travelTime = loadedTravelTimes[edge] * myAdaptionFactor + (1. - myAdaptionFactor) * travelTime;
327  } else {
328  travelTime = edge->getTravelTime(myDefaultVehicle, STEPS2TIME(lastBegin)) * myAdaptionFactor + (1. - myAdaptionFactor) * travelTime;
329  }
330  }
331  edge->addTravelTime(travelTime, STEPS2TIME(begin), STEPS2TIME(end));
332  }
333  }
335  }
336  lastBegin = intervalStart;
337  }
338 }
339 
340 
341 void
342 ROMAAssignments::sue(const int maxOuterIteration, const int maxInnerIteration, const int kPaths, const double penalty, const double tolerance, const std::string /* routeChoiceMethod */) {
343  getKPaths(kPaths, penalty);
344  std::map<const double, double> intervals;
345  if (myAdditiveTraffic) {
346  intervals[STEPS2TIME(myBegin)] = STEPS2TIME(myEnd);
347  } else {
348  for (const ODCell* const c : myMatrix.getCells()) {
349  intervals[STEPS2TIME(c->begin)] = STEPS2TIME(c->end);
350  }
351  }
352  for (int outer = 0; outer < maxOuterIteration; outer++) {
353  for (int inner = 0; inner < maxInnerIteration; inner++) {
354  for (const ODCell* const c : myMatrix.getCells()) {
355  const SUMOTime begin = myAdditiveTraffic ? myBegin : c->begin;
356  const SUMOTime end = myAdditiveTraffic ? myEnd : c->end;
357  // update path cost
358  for (std::vector<RORoute*>::const_iterator j = c->pathsVector.begin(); j != c->pathsVector.end(); ++j) {
359  RORoute* r = *j;
361 // std::cout << std::setprecision(20) << r->getID() << ":" << r->getCosts() << std::endl;
362  }
363  // calculate route utilities and probabilities
364  RouteCostCalculator<RORoute, ROEdge, ROVehicle>::getCalculator().calculateProbabilities(c->pathsVector, myDefaultVehicle, 0);
365  // calculate route flows
366  for (std::vector<RORoute*>::const_iterator j = c->pathsVector.begin(); j != c->pathsVector.end(); ++j) {
367  RORoute* r = *j;
368  const double pathFlow = r->getProbability() * c->vehicleNumber;
369  // assign edge flow deltas
370  for (ConstROEdgeVector::const_iterator e = r->getEdgeVector().begin(); e != r->getEdgeVector().end(); e++) {
371  ROMAEdge* edge = static_cast<ROMAEdge*>(myNet.getEdge((*e)->getID()));
372  edge->setHelpFlow(STEPS2TIME(begin), STEPS2TIME(end), edge->getHelpFlow(STEPS2TIME(begin)) + pathFlow);
373  }
374  }
375  }
376  // calculate new edge flows and check for stability
377  int unstableEdges = 0;
378  for (std::map<const double, double>::const_iterator i = intervals.begin(); i != intervals.end(); ++i) {
379  const double intervalLengthInHours = STEPS2TIME(i->second - i->first) / 3600.;
380  for (std::map<std::string, ROEdge*>::const_iterator e = myNet.getEdgeMap().begin(); e != myNet.getEdgeMap().end(); ++e) {
381  ROMAEdge* edge = static_cast<ROMAEdge*>(e->second);
382  const double oldFlow = edge->getFlow(i->first);
383  double newFlow = oldFlow;
384  if (inner == 0 && outer == 0) {
385  newFlow += edge->getHelpFlow(i->first);
386  } else {
387  newFlow += (edge->getHelpFlow(i->first) - oldFlow) / (inner + 1);
388  }
389  // if not lohse:
390  if (newFlow > 0.) {
391  if (fabs(newFlow - oldFlow) / newFlow > tolerance) {
392  unstableEdges++;
393  }
394  } else if (newFlow == 0.) {
395  if (oldFlow != 0. && (fabs(newFlow - oldFlow) / oldFlow > tolerance)) {
396  unstableEdges++;
397  }
398  } else { // newFlow < 0.
399  unstableEdges++;
400  newFlow = 0.;
401  }
402  edge->setFlow(i->first, i->second, newFlow);
403  const double travelTime = capacityConstraintFunction(edge, newFlow / intervalLengthInHours);
404  edge->addTravelTime(travelTime, i->first, i->second);
405  edge->setHelpFlow(i->first, i->second, 0.);
406  }
407  }
408  // if stable break
409  if (unstableEdges == 0) {
410  break;
411  }
412  // additional stability check from python script: if notstable < math.ceil(net.geteffEdgeCounts()*0.005) or notstable < 3: stable = True
413  }
414  // check for a new route, if none available, break
415  // several modifications about when a route is new and when to break are in the original script
416  bool newRoute = false;
417  for (ODCell* const c : myMatrix.getCells()) {
418  newRoute |= !computePath(c).empty();
419  }
420  if (!newRoute) {
421  break;
422  }
423  }
424  // final round of assignment
425  for (const ODCell* const c : myMatrix.getCells()) {
426  // update path cost
427  for (std::vector<RORoute*>::const_iterator j = c->pathsVector.begin(); j != c->pathsVector.end(); ++j) {
428  RORoute* r = *j;
430  }
431  // calculate route utilities and probabilities
432  RouteCostCalculator<RORoute, ROEdge, ROVehicle>::getCalculator().calculateProbabilities(c->pathsVector, myDefaultVehicle, 0);
433  // calculate route flows
434  for (std::vector<RORoute*>::const_iterator j = c->pathsVector.begin(); j != c->pathsVector.end(); ++j) {
435  RORoute* r = *j;
436  r->setProbability(r->getProbability() * c->vehicleNumber);
437  }
438  }
439 }
440 
441 
442 double
443 ROMAAssignments::getPenalizedEffort(const ROEdge* const e, const ROVehicle* const v, double t) {
444  const std::map<const ROEdge* const, double>::const_iterator i = myPenalties.find(e);
445  return i == myPenalties.end() ? e->getEffort(v, t) : e->getEffort(v, t) + i->second;
446 }
447 
448 
449 double
450 ROMAAssignments::getPenalizedTT(const ROEdge* const e, const ROVehicle* const v, double t) {
451  const std::map<const ROEdge* const, double>::const_iterator i = myPenalties.find(e);
452  return i == myPenalties.end() ? e->getTravelTime(v, t) : e->getTravelTime(v, t) + i->second;
453 }
454 
455 
456 double
457 ROMAAssignments::getTravelTime(const ROEdge* const e, const ROVehicle* const v, double t) {
458  return e->getTravelTime(v, t);
459 }
460 
461 
462 #ifdef HAVE_FOX
463 // ---------------------------------------------------------------------------
464 // ROMAAssignments::RoutingTask-methods
465 // ---------------------------------------------------------------------------
466 void
467 ROMAAssignments::RoutingTask::run(FXWorkerThread* context) {
468  myAssign.computePath(myCell, myBegin, myLinkFlow, &static_cast<RONet::WorkerThread*>(context)->getVehicleRouter(SVC_IGNORING));
469 }
470 #endif
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:278
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:54
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:31
@ SVC_IGNORING
vehicles ignoring classes
const std::string DEFAULT_VTYPE_ID
T MIN2(T a, T b)
Definition: StdDefs.h:73
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A thread repeatingly calculating incoming tasks.
IDMap::const_iterator begin() const
Returns a reference to the begin iterator for the internal map.
IDMap::const_iterator end() const
Returns a reference to the end iterator for the internal map.
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:67
const std::vector< ODCell * > & getCells()
Definition: ODMatrix.h:246
A basic edge for routing applications.
Definition: ROEdge.h:70
bool hasLoadedTravelTime(double time) const
Returns whether a travel time for this edge was loaded.
Definition: ROEdge.cpp:180
int getNumLanes() const
Returns the number of lanes this edge has.
Definition: ROEdge.h:251
int getPriority() const
get edge priority (road class)
Definition: ROEdge.h:500
bool isTazConnector() const
Definition: ROEdge.h:159
double getSpeedLimit() const
Returns the speed allowed on this edge.
Definition: ROEdge.h:225
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:186
void addTravelTime(double value, double timeBegin, double timeEnd)
Adds a travel time value.
Definition: ROEdge.cpp:143
double getEffort(const ROVehicle *const veh, double time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:150
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:210
ROMAAssignments(const SUMOTime begin, const SUMOTime end, const bool additiveTraffic, const double adaptionFactor, const int maxAlternatives, RONet &net, ODMatrix &matrix, SUMOAbstractRouter< ROEdge, ROVehicle > &router)
Constructor.
const double myAdaptionFactor
ODMatrix & myMatrix
void sue(const int maxOuterIteration, const int maxInnerIteration, const int kPaths, const double penalty, const double tolerance, const std::string routeChoiceMethod)
void getKPaths(const int kPaths, const double penalty)
get the k shortest paths
static double getPenalizedEffort(const ROEdge *const e, const ROVehicle *const v, double t)
Returns the effort to pass an edge including penalties.
void incremental(const int numIter, const bool verbose)
double capacityConstraintFunction(const ROEdge *edge, const double flow) const
const bool myAdditiveTraffic
static double getCapacity(const ROEdge *edge)
const int myMaxAlternatives
ROVehicle * myDefaultVehicle
const SUMOTime myEnd
static double getPenalizedTT(const ROEdge *const e, const ROVehicle *const v, double t)
Returns the traveltime on an edge including penalties.
static double getTravelTime(const ROEdge *const e, const ROVehicle *const v, double t)
Returns the traveltime on an edge without penalties.
static std::map< const ROEdge *const, double > myPenalties
SUMOAbstractRouter< ROEdge, ROVehicle > & myRouter
bool addRoute(const ConstROEdgeVector &edges, std::vector< RORoute * > &paths, std::string routeId, double prob)
add a route and check for duplicates
const SUMOTime myBegin
const ConstROEdgeVector computePath(ODCell *cell, const SUMOTime time=0, const double probability=0., SUMOAbstractRouter< ROEdge, ROVehicle > *router=nullptr)
~ROMAAssignments()
Destructor.
A basic edge for routing applications.
Definition: ROMAEdge.h:55
double getHelpFlow(const double time) const
Definition: ROMAEdge.h:91
void setFlow(const double begin, const double end, const double flow)
Definition: ROMAEdge.h:79
double getFlow(const double time) const
Definition: ROMAEdge.h:83
void setHelpFlow(const double begin, const double end, const double flow)
Definition: ROMAEdge.h:87
The router's network representation.
Definition: RONet.h:62
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:334
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:157
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition: RONet.h:399
A complete router's route.
Definition: RORoute.h:52
void setProbability(double prob)
Sets the probability of the route.
Definition: RORoute.cpp:70
double getProbability() const
Returns the probability the driver will take this route with.
Definition: RORoute.h:120
void addProbability(double prob)
add additional vehicles/probability
Definition: RORoute.cpp:81
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
Definition: RORoute.h:152
void setCosts(double costs)
Sets the costs of the route.
Definition: RORoute.cpp:64
A vehicle as used by router.
Definition: ROVehicle.h:50
static RouteCostCalculator< R, E, V > & getCalculator()
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
virtual void reset(const V *const vehicle)
reset internal caches, used by CHRouter
void setBulkMode(const bool mode)
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...
Structure representing possible vehicle parameter.
A single O/D-matrix cell.
Definition: ODCell.h:48
std::string destination
Name of the destination district.
Definition: ODCell.h:62
std::string origin
Name of the origin district.
Definition: ODCell.h:59
std::vector< RORoute * > pathsVector
the list of paths / routes
Definition: ODCell.h:68
double vehicleNumber
The number of vehicles.
Definition: ODCell.h:50
bool originIsEdge
the origin "district" is an edge id
Definition: ODCell.h:74
SUMOTime end
The end time this cell describes.
Definition: ODCell.h:56
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:53
bool destinationIsEdge
the destination "district" is an edge id
Definition: ODCell.h:77