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