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-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 /****************************************************************************/
16 // Assignment methods
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <vector>
26 #include <algorithm>
27 #include <utils/common/SUMOTime.h>
31 #include <router/ROEdge.h>
32 #include <router/RONet.h>
33 #include <router/RORoute.h>
34 #include <od/ODMatrix.h>
35 #include "ROMAEdge.h"
36 #include "ROMAAssignments.h"
37 
38 
39 // ===========================================================================
40 // static member variables
41 // ===========================================================================
42 std::map<const ROEdge* const, double> ROMAAssignments::myPenalties;
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 
49 ROMAAssignments::ROMAAssignments(const SUMOTime begin, const SUMOTime end, const bool additiveTraffic,
50  const double adaptionFactor, const int maxAlternatives, RONet& net, ODMatrix& matrix,
52  : myBegin(begin), myEnd(end), myAdditiveTraffic(additiveTraffic), myAdaptionFactor(adaptionFactor),
53  myMaxAlternatives(maxAlternatives), myNet(net), myMatrix(matrix), myRouter(router) {
55 }
56 
57 
59  delete myDefaultVehicle;
60 }
61 
62 // based on the definitions in PTV-Validate and in the VISUM-Cologne network
63 double
65  if (edge->isTazConnector()) {
66  return 0;
67  }
68  const int roadClass = -edge->getPriority();
69  // TODO: differ road class 1 from the unknown road class 1!!!
70  if (edge->getNumLanes() == 0) {
71  // TAZ have no cost
72  return 0;
73  } else if (roadClass == 0 || roadClass == 1) {
74  return edge->getNumLanes() * 2000.; //CR13 in table.py
75  } else if (roadClass == 2 && edge->getSpeedLimit() <= 11.) {
76  return edge->getNumLanes() * 1333.33; //CR5 in table.py
77  } else if (roadClass == 2 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 16.) {
78  return edge->getNumLanes() * 1500.; //CR3 in table.py
79  } else if (roadClass == 2 && edge->getSpeedLimit() > 16.) {
80  return edge->getNumLanes() * 2000.; //CR13 in table.py
81  } else if (roadClass == 3 && edge->getSpeedLimit() <= 11.) {
82  return edge->getNumLanes() * 800.; //CR5 in table.py
83  } else if (roadClass == 3 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
84  return edge->getNumLanes() * 875.; //CR5 in table.py
85  } else if (roadClass == 3 && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
86  return edge->getNumLanes() * 1500.; //CR4 in table.py
87  } else if (roadClass == 3 && edge->getSpeedLimit() > 16.) {
88  return edge->getNumLanes() * 1800.; //CR13 in table.py
89  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() <= 5.) {
90  return edge->getNumLanes() * 200.; //CR7 in table.py
91  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 5. && edge->getSpeedLimit() <= 7.) {
92  return edge->getNumLanes() * 412.5; //CR7 in table.py
93  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 7. && edge->getSpeedLimit() <= 9.) {
94  return edge->getNumLanes() * 600.; //CR6 in table.py
95  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 9. && edge->getSpeedLimit() <= 11.) {
96  return edge->getNumLanes() * 800.; //CR5 in table.py
97  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
98  return edge->getNumLanes() * 1125.; //CR5 in table.py
99  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
100  return edge->getNumLanes() * 1583.; //CR4 in table.py
101  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 16. && edge->getSpeedLimit() <= 18.) {
102  return edge->getNumLanes() * 1100.; //CR3 in table.py
103  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 18. && edge->getSpeedLimit() <= 22.) {
104  return edge->getNumLanes() * 1200.; //CR3 in table.py
105  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 22. && edge->getSpeedLimit() <= 26.) {
106  return edge->getNumLanes() * 1300.; //CR3 in table.py
107  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 26.) {
108  return edge->getNumLanes() * 1400.; //CR3 in table.py
109  }
110  return edge->getNumLanes() * 800.; //CR5 in table.py
111 }
112 
113 
114 // based on the definitions in PTV-Validate and in the VISUM-Cologne network
115 double
116 ROMAAssignments::capacityConstraintFunction(const ROEdge* edge, const double flow) const {
117  if (edge->isTazConnector()) {
118  return 0;
119  }
120  const int roadClass = -edge->getPriority();
121  const double capacity = getCapacity(edge);
122  // TODO: differ road class 1 from the unknown road class 1!!!
123  if (edge->getNumLanes() == 0) {
124  // TAZ have no cost
125  return 0;
126  } else if (roadClass == 0 || roadClass == 1) {
127  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.3)) * 2.); //CR13 in table.py
128  } else if (roadClass == 2 && edge->getSpeedLimit() <= 11.) {
129  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
130  } else if (roadClass == 2 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 16.) {
131  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
132  } else if (roadClass == 2 && edge->getSpeedLimit() > 16.) {
133  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.3)) * 2.); //CR13 in table.py
134  } else if (roadClass == 3 && edge->getSpeedLimit() <= 11.) {
135  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
136  } else if (roadClass == 3 && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
137  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
138  } else if (roadClass == 3 && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
139  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.7 * (flow / (capacity * 1.)) * 2.); //CR4 in table.py
140  } else if (roadClass == 3 && edge->getSpeedLimit() > 16.) {
141  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.3)) * 2.); //CR13 in table.py
142  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() <= 5.) {
143  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.5)) * 3.); //CR7 in table.py
144  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 5. && edge->getSpeedLimit() <= 7.) {
145  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.5)) * 3.); //CR7 in table.py
146  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 7. && edge->getSpeedLimit() <= 9.) {
147  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.8)) * 3.); //CR6 in table.py
148  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 9. && edge->getSpeedLimit() <= 11.) {
149  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
150  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 11. && edge->getSpeedLimit() <= 13.) {
151  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
152  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 13. && edge->getSpeedLimit() <= 16.) {
153  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.7 * (flow / (capacity * 1.)) * 2.); //CR4 in table.py
154  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 16. && edge->getSpeedLimit() <= 18.) {
155  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
156  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 18. && edge->getSpeedLimit() <= 22.) {
157  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
158  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 22. && edge->getSpeedLimit() <= 26.) {
159  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
160  } else if ((roadClass >= 4 || roadClass == -1) && edge->getSpeedLimit() > 26.) {
161  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 1.)) * 2.); //CR3 in table.py
162  }
163  return edge->getLength() / edge->getSpeedLimit() * (1. + 1.*(flow / (capacity * 0.9)) * 3.); //CR5 in table.py
164 }
165 
166 
167 bool
168 ROMAAssignments::addRoute(const ConstROEdgeVector& edges, std::vector<RORoute*>& paths, std::string routeId, double prob) {
169  std::vector<RORoute*>::iterator p;
170  for (p = paths.begin(); p != paths.end(); p++) {
171  if (edges == (*p)->getEdgeVector()) {
172  break;
173  }
174  }
175  if (p == paths.end()) {
176  paths.push_back(new RORoute(routeId, 0., prob, edges, nullptr, std::vector<SUMOVehicleParameter::Stop>()));
177  return true;
178  }
179  (*p)->addProbability(prob);
180  std::iter_swap(paths.end() - 1, p);
181  return false;
182 }
183 
184 
185 const ConstROEdgeVector
186 ROMAAssignments::computePath(ODCell* cell, const SUMOTime time, const double probability, SUMOAbstractRouter<ROEdge, ROVehicle>* router) {
187  const ROEdge* const from = myNet.getEdge(cell->origin + (cell->originIsEdge ? "" : "-source"));
188  if (from == nullptr) {
189  throw ProcessError("Unknown origin '" + cell->origin + "'.");
190  }
191  const ROEdge* const to = myNet.getEdge(cell->destination + (cell->destinationIsEdge ? "" : "-sink"));
192  if (to == nullptr) {
193  throw ProcessError("Unknown destination '" + cell->destination + "'.");
194  }
195  ConstROEdgeVector edges;
196  if (router == nullptr) {
197  router = &myRouter;
198  }
199  if (myMaxAlternatives > 0 && (int)cell->pathsVector.size() < myMaxAlternatives) {
200  router->compute(from, to, myDefaultVehicle, time, edges);
201  if (addRoute(edges, cell->pathsVector, cell->origin + cell->destination + toString(cell->pathsVector.size()), probability)) {
202  return edges;
203  }
204  } else {
205  double minCost = std::numeric_limits<double>::max();
206  RORoute* minRoute = nullptr;
207  for (RORoute* const p : cell->pathsVector) {
208  const double cost = router->recomputeCosts(edges, myDefaultVehicle, time);
209  if (cost < minCost) {
210  minCost = cost;
211  minRoute = p;
212  }
213  }
214  minRoute->addProbability(probability);
215  }
216  return ConstROEdgeVector();
217 }
218 
219 
220 void
221 ROMAAssignments::getKPaths(const int kPaths, const double penalty) {
222  for (ODCell* const c : myMatrix.getCells()) {
223  myPenalties.clear();
224  for (int k = 0; k < kPaths; k++) {
225  for (const ROEdge* const e : computePath(c)) {
226  myPenalties[e] += penalty;
227  }
228  }
229  }
230  myPenalties.clear();
231 }
232 
233 
234 void
236  const double begin = STEPS2TIME(MIN2(myBegin, myMatrix.getCells().front()->begin));
237  for (std::map<std::string, ROEdge*>::const_iterator i = myNet.getEdgeMap().begin(); i != myNet.getEdgeMap().end(); ++i) {
238  ROMAEdge* edge = static_cast<ROMAEdge*>(i->second);
239  edge->setFlow(begin, STEPS2TIME(myEnd), 0.);
240  edge->setHelpFlow(begin, STEPS2TIME(myEnd), 0.);
241  }
242 }
243 
244 
245 void
246 ROMAAssignments::incremental(const int numIter, const bool verbose) {
247  SUMOTime lastBegin = -1;
248  std::vector<int> intervals;
249  int count = 0;
250  for (const ODCell* const c : myMatrix.getCells()) {
251  if (c->begin != lastBegin) {
252  intervals.push_back(count);
253  lastBegin = c->begin;
254  }
255  count++;
256  }
257  lastBegin = -1;
258  for (std::vector<int>::const_iterator offset = intervals.begin(); offset != intervals.end(); offset++) {
259  std::vector<ODCell*>::const_iterator cellsEnd = myMatrix.getCells().end();
260  if (offset != intervals.end() - 1) {
261  cellsEnd = myMatrix.getCells().begin() + (*(offset + 1));
262  }
263  const SUMOTime intervalStart = (*(myMatrix.getCells().begin() + (*offset)))->begin;
264  if (verbose) {
265  WRITE_MESSAGE(" starting interval " + time2string(intervalStart));
266  }
267  std::map<const ROMAEdge*, double> loadedTravelTimes;
268  for (std::map<std::string, ROEdge*>::const_iterator i = myNet.getEdgeMap().begin(); i != myNet.getEdgeMap().end(); ++i) {
269  ROMAEdge* edge = static_cast<ROMAEdge*>(i->second);
270  if (edge->hasLoadedTravelTime(STEPS2TIME(intervalStart))) {
271  loadedTravelTimes[edge] = edge->getTravelTime(myDefaultVehicle, STEPS2TIME(intervalStart));
272  }
273  }
274  for (int t = 0; t < numIter; t++) {
275  if (verbose) {
276  WRITE_MESSAGE(" starting iteration " + toString(t));
277  }
278  std::string lastOrigin = "";
279  int workerIndex = 0;
280  for (std::vector<ODCell*>::const_iterator i = myMatrix.getCells().begin() + (*offset); i != cellsEnd; i++) {
281  ODCell* const c = *i;
282  const double linkFlow = c->vehicleNumber / numIter;
283  const SUMOTime begin = myAdditiveTraffic ? myBegin : c->begin;
284 #ifdef HAVE_FOX
285  if (myNet.getThreadPool().size() > 0) {
286  if (lastOrigin != c->origin) {
287  workerIndex++;
288  if (workerIndex == myNet.getThreadPool().size()) {
289  workerIndex = 0;
290  }
291  myNet.getThreadPool().add(new RONet::BulkmodeTask(false), workerIndex);
292  lastOrigin = c->origin;
293  myNet.getThreadPool().add(new RoutingTask(*this, c, begin, linkFlow), workerIndex);
294  myNet.getThreadPool().add(new RONet::BulkmodeTask(true), workerIndex);
295  } else {
296  myNet.getThreadPool().add(new RoutingTask(*this, c, begin, linkFlow), workerIndex);
297  }
298  continue;
299  }
300 #endif
301  if (lastOrigin != c->origin) {
302  myRouter.setBulkMode(false);
303  lastOrigin = c->origin;
304  }
305  computePath(c, begin, linkFlow);
306  myRouter.setBulkMode(true);
307  }
308 #ifdef HAVE_FOX
309  if (myNet.getThreadPool().size() > 0) {
310  myNet.getThreadPool().waitAll();
311  }
312 #endif
313  for (std::vector<ODCell*>::const_iterator i = myMatrix.getCells().begin() + (*offset); i != cellsEnd; i++) {
314  ODCell* const c = *i;
315  const double linkFlow = c->vehicleNumber / numIter;
316  const SUMOTime begin = myAdditiveTraffic ? myBegin : c->begin;
317  const SUMOTime end = myAdditiveTraffic ? myEnd : c->end;
318  const double intervalLengthInHours = STEPS2TIME(end - begin) / 3600.;
319  const ConstROEdgeVector& edges = c->pathsVector.back()->getEdgeVector();
320  for (ConstROEdgeVector::const_iterator e = edges.begin(); e != edges.end(); e++) {
321  ROMAEdge* edge = static_cast<ROMAEdge*>(myNet.getEdge((*e)->getID()));
322  const double newFlow = edge->getFlow(STEPS2TIME(begin)) + linkFlow;
323  edge->setFlow(STEPS2TIME(begin), STEPS2TIME(end), newFlow);
324  double travelTime = capacityConstraintFunction(edge, newFlow / intervalLengthInHours);
325  if (lastBegin >= 0 && myAdaptionFactor > 0.) {
326  if (loadedTravelTimes.count(edge) != 0) {
327  travelTime = loadedTravelTimes[edge] * myAdaptionFactor + (1. - myAdaptionFactor) * travelTime;
328  } else {
329  travelTime = edge->getTravelTime(myDefaultVehicle, STEPS2TIME(lastBegin)) * myAdaptionFactor + (1. - myAdaptionFactor) * travelTime;
330  }
331  }
332  edge->addTravelTime(travelTime, STEPS2TIME(begin), STEPS2TIME(end));
333  }
334  }
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());
469 }
470 #endif
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...
ROEdge::getPriority
int getPriority() const
get edge priority (road class)
Definition: ROEdge.h:474
ROEdge::getNumLanes
int getNumLanes() const
Returns the number of lanes this edge has.
Definition: ROEdge.h:245
RORoute::getProbability
double getProbability() const
Returns the probability the driver will take this route with.
Definition: RORoute.h:122
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
ODCell::originIsEdge
bool originIsEdge
the origin "district" is an edge id
Definition: ODCell.h:76
ROEdge::getTravelTime
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:183
SUMOTime.h
ODCell::vehicleNumber
double vehicleNumber
The number of vehicles.
Definition: ODCell.h:52
ROMAAssignments::getKPaths
void getKPaths(const int kPaths, const double penalty)
get the k shortest paths
Definition: ROMAAssignments.cpp:221
ROMAAssignments::incremental
void incremental(const int numIter, const bool verbose)
Definition: ROMAAssignments.cpp:246
ROMAAssignments.h
RouteCostCalculator.h
RONet::getEdge
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:152
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
RORoute::getEdgeVector
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
Definition: RORoute.h:154
RORoute::addProbability
void addProbability(double prob)
add additional vehicles/probability
Definition: RORoute.cpp:82
ROMAAssignments::myAdditiveTraffic
const bool myAdditiveTraffic
Definition: ROMAAssignments.h:133
RORoute::setCosts
void setCosts(double costs)
Sets the costs of the route.
Definition: RORoute.cpp:65
ROMAEdge
A basic edge for routing applications.
Definition: ROMAEdge.h:57
RONet
The router's network representation.
Definition: RONet.h:63
RouteCostCalculator::getCalculator
static RouteCostCalculator< R, E, V > & getCalculator()
Definition: RouteCostCalculator.h:107
ROMAAssignments::ROMAAssignments
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.
Definition: ROMAAssignments.cpp:49
ODMatrix.h
ROVehicle
A vehicle as used by router.
Definition: ROVehicle.h:52
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
RORoute.h
ROEdge::getEffort
double getEffort(const ROVehicle *const veh, double time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:147
ROMAEdge::getFlow
double getFlow(const double time) const
Definition: ROMAEdge.h:85
ROMAAssignments::myRouter
SUMOAbstractRouter< ROEdge, ROVehicle > & myRouter
Definition: ROMAAssignments.h:138
ROMAEdge::setHelpFlow
void setHelpFlow(const double begin, const double end, const double flow)
Definition: ROMAEdge.h:89
ODCell
A single O/D-matrix cell.
Definition: ODCell.h:50
ROEdge::addTravelTime
void addTravelTime(double value, double timeBegin, double timeEnd)
Adds a travel time value.
Definition: ROEdge.cpp:140
RONet.h
ROMAAssignments::myAdaptionFactor
const double myAdaptionFactor
Definition: ROMAAssignments.h:134
DEFAULT_VTYPE_ID
const std::string DEFAULT_VTYPE_ID
ROMAAssignments::myPenalties
static std::map< const ROEdge *const, double > myPenalties
Definition: ROMAAssignments.h:139
NamedObjectCont::begin
IDMap::const_iterator begin() const
Returns a reference to the begin iterator for the internal map.
Definition: NamedObjectCont.h:144
ODCell::destination
std::string destination
Name of the destination district.
Definition: ODCell.h:64
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
ROMAEdge::setFlow
void setFlow(const double begin, const double end, const double flow)
Definition: ROMAEdge.h:81
ProcessError
Definition: UtilExceptions.h:39
ROMAAssignments::myNet
RONet & myNet
Definition: ROMAAssignments.h:136
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
RORoute
A complete router's route.
Definition: RORoute.h:54
SUMOAbstractRouter::setBulkMode
void setBulkMode(const bool mode)
Definition: SUMOAbstractRouter.h:230
ROMAAssignments::getPenalizedEffort
static double getPenalizedEffort(const ROEdge *const e, const ROVehicle *const v, double t)
Returns the effort to pass an edge including penalties.
Definition: ROMAAssignments.cpp:443
ODCell::pathsVector
std::vector< RORoute * > pathsVector
the list of paths / routes
Definition: ODCell.h:70
ROEdge::isTazConnector
bool isTazConnector() const
Definition: ROEdge.h:161
ROMAAssignments::~ROMAAssignments
~ROMAAssignments()
Destructor.
Definition: ROMAAssignments.cpp:58
ROMAAssignments::addRoute
bool addRoute(const ConstROEdgeVector &edges, std::vector< RORoute * > &paths, std::string routeId, double prob)
add a route and check for duplicates
Definition: ROMAAssignments.cpp:168
ODMatrix
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:69
ODCell::end
SUMOTime end
The end time this cell describes.
Definition: ODCell.h:58
ROMAAssignments::myEnd
const SUMOTime myEnd
Definition: ROMAAssignments.h:132
ROMAAssignments::resetFlows
void resetFlows()
Definition: ROMAAssignments.cpp:235
SUMOAbstractRouter< ROEdge, ROVehicle >
RORoute::setProbability
void setProbability(double prob)
Sets the probability of the route.
Definition: RORoute.cpp:71
RONet::getEdgeMap
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition: RONet.h:392
ROMAAssignments::myDefaultVehicle
ROVehicle * myDefaultVehicle
Definition: ROMAAssignments.h:140
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
ROMAAssignments::capacityConstraintFunction
double capacityConstraintFunction(const ROEdge *edge, const double flow) const
Definition: ROMAAssignments.cpp:116
ROMAAssignments::getCapacity
static double getCapacity(const ROEdge *edge)
Definition: ROMAAssignments.cpp:64
SUMOAbstractRouter::recomputeCosts
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
Definition: SUMOAbstractRouter.h:195
NamedObjectCont::end
IDMap::const_iterator end() const
Returns a reference to the end iterator for the internal map.
Definition: NamedObjectCont.h:149
ROEdge::getLength
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:204
ODCell::origin
std::string origin
Name of the origin district.
Definition: ODCell.h:61
Distribution_Points.h
ODCell::destinationIsEdge
bool destinationIsEdge
the destination "district" is an edge id
Definition: ODCell.h:79
ROEdge::hasLoadedTravelTime
bool hasLoadedTravelTime(double time) const
Returns whether a travel time for this edge was loaded.
Definition: ROEdge.cpp:177
ROMAAssignments::computePath
const ConstROEdgeVector computePath(ODCell *cell, const SUMOTime time=0, const double probability=0., SUMOAbstractRouter< ROEdge, ROVehicle > *router=nullptr)
Definition: ROMAAssignments.cpp:186
ROEdge
A basic edge for routing applications.
Definition: ROEdge.h:72
ROMAAssignments::myMaxAlternatives
const int myMaxAlternatives
Definition: ROMAAssignments.h:135
config.h
ROEdge::getSpeedLimit
double getSpeedLimit() const
Returns the speed allowed on this edge.
Definition: ROEdge.h:219
ODCell::begin
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:55
RONet::getVehicleTypeSecure
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:278
SUMOAbstractRouter.h
ROMAAssignments::getTravelTime
static double getTravelTime(const ROEdge *const e, const ROVehicle *const v, double t)
Returns the traveltime on an edge without penalties.
Definition: ROMAAssignments.cpp:457
ROMAAssignments::myMatrix
ODMatrix & myMatrix
Definition: ROMAAssignments.h:137
ROEdge.h
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:277
ROMAEdge::getHelpFlow
double getHelpFlow(const double time) const
Definition: ROMAEdge.h:93
ConstROEdgeVector
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:56
FXWorkerThread
A thread repeatingly calculating incoming tasks.
Definition: FXWorkerThread.h:48
ROMAEdge.h
ODMatrix::getCells
const std::vector< ODCell * > & getCells()
Definition: ODMatrix.h:246
ROMAAssignments::getPenalizedTT
static double getPenalizedTT(const ROEdge *const e, const ROVehicle *const v, double t)
Returns the traveltime on an edge including penalties.
Definition: ROMAAssignments.cpp:450
ROMAAssignments::sue
void sue(const int maxOuterIteration, const int maxInnerIteration, const int kPaths, const double penalty, const double tolerance, const std::string routeChoiceMethod)
Definition: ROMAAssignments.cpp:342
ROMAAssignments::myBegin
const SUMOTime myBegin
Definition: ROMAAssignments.h:131