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