Eclipse SUMO - Simulation of Urban MObility
ODMatrix.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2006-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 // An O/D (origin/destination) matrix
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <iostream>
27 #include <algorithm>
28 #include <list>
29 #include <iterator>
31 #include <utils/common/StdDefs.h>
33 #include <utils/common/ToString.h>
38 #include <utils/common/SUMOTime.h>
42 #include <utils/xml/XMLSubSys.h>
43 #include "ODAmitranHandler.h"
44 #include "ODMatrix.h"
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
51  : myDistricts(dc), myNumLoaded(0), myNumWritten(0), myNumDiscarded(0), myBegin(-1), myEnd(-1) {}
52 
53 
55  for (std::vector<ODCell*>::iterator i = myContainer.begin(); i != myContainer.end(); ++i) {
56  delete *i;
57  }
58  myContainer.clear();
59 }
60 
61 
62 bool
63 ODMatrix::add(double vehicleNumber, SUMOTime begin,
64  SUMOTime end, const std::string& origin, const std::string& destination,
65  const std::string& vehicleType, const bool originIsEdge, const bool destinationIsEdge) {
66  myNumLoaded += vehicleNumber;
67  if (!originIsEdge && !destinationIsEdge && myDistricts.get(origin) == nullptr && myDistricts.get(destination) == nullptr) {
68  WRITE_WARNING("Missing origin '" + origin + "' and destination '" + destination + "' (" + toString(vehicleNumber) + " vehicles).");
69  myNumDiscarded += vehicleNumber;
70  myMissingDistricts.insert(origin);
71  myMissingDistricts.insert(destination);
72  return false;
73  } else if (!originIsEdge && myDistricts.get(origin) == 0 && vehicleNumber > 0) {
74  WRITE_ERROR("Missing origin '" + origin + "' (" + toString(vehicleNumber) + " vehicles).");
75  myNumDiscarded += vehicleNumber;
76  myMissingDistricts.insert(origin);
77  return false;
78  } else if (!destinationIsEdge && myDistricts.get(destination) == 0 && vehicleNumber > 0) {
79  WRITE_ERROR("Missing destination '" + destination + "' (" + toString(vehicleNumber) + " vehicles).");
80  myNumDiscarded += vehicleNumber;
81  myMissingDistricts.insert(destination);
82  return false;
83  }
84  if (!originIsEdge && myDistricts.get(origin)->sourceNumber() == 0) {
85  WRITE_ERROR("District '" + origin + "' has no source.");
86  myNumDiscarded += vehicleNumber;
87  return false;
88  } else if (!destinationIsEdge && myDistricts.get(destination)->sinkNumber() == 0) {
89  WRITE_ERROR("District '" + destination + "' has no sink.");
90  myNumDiscarded += vehicleNumber;
91  return false;
92  }
93  ODCell* cell = new ODCell();
94  cell->begin = begin;
95  cell->end = end;
96  cell->origin = origin;
97  cell->destination = destination;
98  cell->vehicleType = vehicleType;
99  cell->vehicleNumber = vehicleNumber;
100  cell->originIsEdge = originIsEdge;
101  cell->destinationIsEdge = destinationIsEdge;
102  myContainer.push_back(cell);
103  return true;
104 }
105 
106 
107 bool
108 ODMatrix::add(const std::string& id, const SUMOTime depart,
109  const std::string& fromTaz, const std::string& toTaz,
110  const std::string& vehicleType, const bool originIsEdge, const bool destinationIsEdge) {
111  if (myMissingDistricts.count(fromTaz) > 0 || myMissingDistricts.count(toTaz) > 0) {
112  myNumLoaded += 1.;
113  myNumDiscarded += 1.;
114  return false;
115  }
116  // we start looking from the end because there is a high probability that the input is sorted by time
117  std::vector<ODCell*>& odList = myShortCut[std::make_pair(fromTaz, toTaz)];
118  ODCell* cell = nullptr;
119  for (std::vector<ODCell*>::const_reverse_iterator c = odList.rbegin(); c != odList.rend(); ++c) {
120  if ((*c)->begin <= depart && (*c)->end > depart && (*c)->vehicleType == vehicleType) {
121  cell = *c;
122  break;
123  }
124  }
125  if (cell == nullptr) {
126  const SUMOTime interval = string2time(OptionsCont::getOptions().getString("aggregation-interval"));
127  const int intervalIdx = (int)(depart / interval);
128  if (add(1., intervalIdx * interval, (intervalIdx + 1) * interval, fromTaz, toTaz, vehicleType, originIsEdge, destinationIsEdge)) {
129  cell = myContainer.back();
130  odList.push_back(cell);
131  } else {
132  return false;
133  }
134  } else {
135  myNumLoaded += 1.;
136  cell->vehicleNumber += 1.;
137  }
138  cell->departures[depart].push_back(id);
139  return true;
140 }
141 
142 
143 double
145  int& vehName, std::vector<ODVehicle>& into,
146  const bool uniform, const bool differSourceSink,
147  const std::string& prefix) {
148  int vehicles2insert = (int) cell->vehicleNumber;
149  // compute whether the fraction forces an additional vehicle insertion
150  if (RandHelper::rand() < cell->vehicleNumber - (double)vehicles2insert) {
151  vehicles2insert++;
152  }
153  if (vehicles2insert == 0) {
154  return cell->vehicleNumber;
155  }
156 
157  const double offset = (double)(cell->end - cell->begin) / (double) vehicles2insert / (double) 2.;
158  for (int i = 0; i < vehicles2insert; ++i) {
159  ODVehicle veh;
160  veh.id = prefix + toString(vehName++);
161 
162  if (uniform) {
163  veh.depart = (SUMOTime)(offset + cell->begin + ((double)(cell->end - cell->begin) * (double) i / (double) vehicles2insert));
164  } else {
165  veh.depart = (SUMOTime)RandHelper::rand(cell->begin, cell->end);
166  }
167  const bool canDiffer = myDistricts.get(cell->origin)->sourceNumber() > 1 || myDistricts.get(cell->destination)->sinkNumber() > 1;
168  do {
171  } while (canDiffer && differSourceSink && (veh.to == veh.from));
172  if (!canDiffer && differSourceSink && (veh.to == veh.from)) {
173  WRITE_WARNING("Cannot find different source and sink edge for origin '" + cell->origin + "' and destination '" + cell->destination + "'.");
174  }
175  veh.cell = cell;
176  into.push_back(veh);
177  }
178  return cell->vehicleNumber - vehicles2insert;
179 }
180 
181 
182 void
183 ODMatrix::writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
184  const ODCell* const cell) {
185  const OptionsCont& oc = OptionsCont::getOptions();
186  if (!noVtype && cell->vehicleType != "") {
188  }
190  if (oc.isSet("departlane") && oc.getString("departlane") != "default") {
191  dev.writeAttr(SUMO_ATTR_DEPARTLANE, oc.getString("departlane"));
192  }
193  if (oc.isSet("departpos")) {
194  dev.writeAttr(SUMO_ATTR_DEPARTPOS, oc.getString("departpos"));
195  }
196  if (oc.isSet("departspeed") && oc.getString("departspeed") != "default") {
197  dev.writeAttr(SUMO_ATTR_DEPARTSPEED, oc.getString("departspeed"));
198  }
199  if (oc.isSet("arrivallane")) {
200  dev.writeAttr(SUMO_ATTR_ARRIVALLANE, oc.getString("arrivallane"));
201  }
202  if (oc.isSet("arrivalpos")) {
203  dev.writeAttr(SUMO_ATTR_ARRIVALPOS, oc.getString("arrivalpos"));
204  }
205  if (oc.isSet("arrivalspeed")) {
206  dev.writeAttr(SUMO_ATTR_ARRIVALSPEED, oc.getString("arrivalspeed"));
207  }
208 }
209 
210 
211 void
213  OutputDevice& dev, const bool uniform,
214  const bool differSourceSink, const bool noVtype,
215  const std::string& prefix, const bool stepLog,
216  bool pedestrians, bool persontrips) {
217  if (myContainer.size() == 0) {
218  return;
219  }
220  std::map<std::pair<std::string, std::string>, double> fractionLeft;
221  int vehName = 0;
222  sortByBeginTime();
223  // recheck begin time
224  begin = MAX2(begin, myContainer.front()->begin);
225  std::vector<ODCell*>::iterator next = myContainer.begin();
226  std::vector<ODVehicle> vehicles;
227  SUMOTime lastOut = -DELTA_T;
228  // go through the time steps
229  for (SUMOTime t = begin; t < end;) {
230  if (stepLog && t - lastOut >= DELTA_T) {
231  std::cout << "Parsing time " + time2string(t) << '\r';
232  lastOut = t;
233  }
234  // recheck whether a new cell got valid
235  bool changed = false;
236  while (next != myContainer.end() && (*next)->begin <= t && (*next)->end > t) {
237  std::pair<std::string, std::string> odID = std::make_pair((*next)->origin, (*next)->destination);
238  // check whether the current cell must be extended by the last fraction
239  if (fractionLeft.find(odID) != fractionLeft.end()) {
240  (*next)->vehicleNumber += fractionLeft[odID];
241  fractionLeft[odID] = 0;
242  }
243  // get the new departures (into tmp)
244  const int oldSize = (int)vehicles.size();
245  const double fraction = computeDeparts(*next, vehName, vehicles, uniform, differSourceSink, prefix);
246  if (oldSize != (int)vehicles.size()) {
247  changed = true;
248  }
249  if (fraction != 0) {
250  fractionLeft[odID] = fraction;
251  }
252  ++next;
253  }
254  if (changed) {
255  sort(vehicles.begin(), vehicles.end(), descending_departure_comperator());
256  }
257  for (std::vector<ODVehicle>::reverse_iterator i = vehicles.rbegin(); i != vehicles.rend() && (*i).depart == t; ++i) {
258  if (t >= begin) {
259  myNumWritten++;
260  if (pedestrians) {
262  dev.writeAttr(SUMO_ATTR_DEPARTPOS, "random");
263  dev.openTag(SUMO_TAG_WALK);
264  dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to);
265  dev.writeAttr(SUMO_ATTR_ARRIVALPOS, "random");
266  dev.closeTag();
267  dev.closeTag();
268  } else if (persontrips) {
270  dev.writeAttr(SUMO_ATTR_DEPARTPOS, "random");
272  dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to);
273  dev.writeAttr(SUMO_ATTR_ARRIVALPOS, "random");
274  dev.closeTag();
275  dev.closeTag();
276  } else {
278  dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to);
279  writeDefaultAttrs(dev, noVtype, i->cell);
280  dev.closeTag();
281  }
282  }
283  }
284  while (vehicles.size() != 0 && vehicles.back().depart == t) {
285  vehicles.pop_back();
286  }
287  if (!vehicles.empty()) {
288  t = vehicles.back().depart;
289  }
290  if (next != myContainer.end() && (t > (*next)->begin || vehicles.empty())) {
291  t = (*next)->begin;
292  }
293  if (next == myContainer.end() && vehicles.empty()) {
294  break;
295  }
296  }
297 }
298 
299 
300 void
301 ODMatrix::writeFlows(const SUMOTime begin, const SUMOTime end,
302  OutputDevice& dev, bool noVtype,
303  const std::string& prefix,
304  bool asProbability, bool pedestrians, bool persontrips) {
305  if (myContainer.size() == 0) {
306  return;
307  }
308  int flowName = 0;
309  sortByBeginTime();
310  // recheck begin time
311  for (std::vector<ODCell*>::const_iterator i = myContainer.begin(); i != myContainer.end(); ++i) {
312  const ODCell* const c = *i;
313  if (c->end > begin && c->begin < end) {
314  const double probability = asProbability ? float(c->vehicleNumber) / STEPS2TIME(c->end - c->begin) : 1;
315  if (probability <= 0) {
316  continue;
317  }
318  //Person flows
319  if (pedestrians) {
320  dev.openTag(SUMO_TAG_PERSONFLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++));
322  if (!asProbability) {
324  } else {
325  if (probability > 1) {
326  WRITE_WARNING("Flow density of " + toString(probability) + " vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
328  } else {
329  dev.setPrecision(6);
330  dev.writeAttr(SUMO_ATTR_PROB, probability);
331  dev.setPrecision();
332  }
333  }
334  dev.openTag(SUMO_TAG_WALK);
336  dev.writeAttr(SUMO_ATTR_ARRIVALPOS, "random");
337  dev.closeTag();
338  dev.closeTag();
339  } else if (persontrips) {
340  dev.openTag(SUMO_TAG_PERSONFLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++));
342  if (!asProbability) {
344  } else {
345  if (probability > 1) {
346  WRITE_WARNING("Flow density of " + toString(probability) + " vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
348  } else {
349  dev.setPrecision(6);
350  dev.writeAttr(SUMO_ATTR_PROB, probability);
351  dev.setPrecision();
352  }
353  }
356  dev.writeAttr(SUMO_ATTR_ARRIVALPOS, "random");
357  dev.closeTag();
358  dev.closeTag();
359  } else {
360  // Normal flow output
361  dev.openTag(SUMO_TAG_FLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++));
364 
365  if (!asProbability) {
367  } else {
368  if (probability > 1) {
369  WRITE_WARNING("Flow density of " + toString(probability) + " vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
371  } else {
372  dev.setPrecision(6);
373  dev.writeAttr(SUMO_ATTR_PROB, probability);
374  dev.setPrecision();
375  }
376  }
377  writeDefaultAttrs(dev, noVtype, *i);
378  dev.closeTag();
379  }
380  }
381  }
382 }
383 
384 
385 std::string
387  while (lr.good() && lr.hasMore()) {
388  const std::string line = lr.readLine();
389  if (line[0] != '*') {
390  return StringUtils::prune(line);
391  }
392  }
393  throw ProcessError("End of file while reading " + lr.getFileName() + ".");
394 }
395 
396 
397 SUMOTime
398 ODMatrix::parseSingleTime(const std::string& time) {
399  if (time.find('.') == std::string::npos) {
400  throw OutOfBoundsException();
401  }
402  std::string hours = time.substr(0, time.find('.'));
403  std::string minutes = time.substr(time.find('.') + 1);
404  return TIME2STEPS(StringUtils::toInt(hours) * 3600 + StringUtils::toInt(minutes) * 60);
405 }
406 
407 
408 std::pair<SUMOTime, SUMOTime>
410  std::string line = getNextNonCommentLine(lr);
411  try {
413  myBegin = parseSingleTime(st.next());
414  myEnd = parseSingleTime(st.next());
415  if (myBegin >= myEnd) {
416  throw ProcessError("Matrix begin time " + time2string(myBegin) + " is larger than end time " + time2string(myEnd) + ".");
417  }
418  return std::make_pair(myBegin, myEnd);
419  } catch (OutOfBoundsException&) {
420  throw ProcessError("Broken period definition '" + line + "'.");
421  } catch (NumberFormatException&) {
422  throw ProcessError("Broken period definition '" + line + "'.");
423  }
424 }
425 
426 
427 double
428 ODMatrix::readFactor(LineReader& lr, double scale) {
429  std::string line = getNextNonCommentLine(lr);
430  double factor = -1;
431  try {
432  factor = StringUtils::toDouble(line) * scale;
433  } catch (NumberFormatException&) {
434  throw ProcessError("Broken factor: '" + line + "'.");
435  }
436  return factor;
437 }
438 
439 void
440 ODMatrix::readV(LineReader& lr, double scale,
441  std::string vehType, bool matrixHasVehType) {
442  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as VMR");
443  // parse first defs
444  std::string line;
445  if (matrixHasVehType) {
446  line = getNextNonCommentLine(lr);
447  if (vehType == "") {
448  vehType = StringUtils::prune(line);
449  }
450  }
451 
452  // parse time
453  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
454  SUMOTime begin = times.first;
455  SUMOTime end = times.second;
456 
457  // factor
458  double factor = readFactor(lr, scale);
459 
460  // districts
461  line = getNextNonCommentLine(lr);
462  const int numDistricts = StringUtils::toInt(StringUtils::prune(line));
463  // parse district names (normally ints)
464  std::vector<std::string> names;
465  while ((int)names.size() != numDistricts) {
466  line = getNextNonCommentLine(lr);
468  while (st2.hasNext()) {
469  names.push_back(st2.next());
470  }
471  }
472 
473  // parse the cells
474  for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) {
475  std::vector<std::string>::iterator di = names.begin();
476  //
477  do {
478  line = getNextNonCommentLine(lr);
479  if (line.length() == 0) {
480  continue;
481  }
482  try {
484  while (st2.hasNext()) {
485  assert(di != names.end());
486  double vehNumber = StringUtils::toDouble(st2.next()) * factor;
487  if (vehNumber != 0) {
488  add(vehNumber, begin, end, *si, *di, vehType);
489  }
490  if (di == names.end()) {
491  throw ProcessError("More entries than districts found.");
492  }
493  ++di;
494  }
495  } catch (NumberFormatException&) {
496  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
497  }
498  if (!lr.hasMore()) {
499  break;
500  }
501  } while (di != names.end());
502  }
504 }
505 
506 
507 void
508 ODMatrix::readO(LineReader& lr, double scale,
509  std::string vehType, bool matrixHasVehType) {
510  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR");
511  // parse first defs
512  std::string line;
513  if (matrixHasVehType) {
514  line = getNextNonCommentLine(lr);
515  int type = StringUtils::toInt(StringUtils::prune(line));
516  if (vehType == "") {
517  vehType = toString(type);
518  }
519  }
520 
521  // parse time
522  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
523  SUMOTime begin = times.first;
524  SUMOTime end = times.second;
525 
526  // factor
527  double factor = readFactor(lr, scale);
528 
529  // parse the cells
530  while (lr.hasMore()) {
531  line = getNextNonCommentLine(lr);
532  if (line.length() == 0) {
533  continue;
534  }
536  if (st2.size() == 0) {
537  continue;
538  }
539  try {
540  std::string sourceD = st2.next();
541  std::string destD = st2.next();
542  double vehNumber = StringUtils::toDouble(st2.next()) * factor;
543  if (vehNumber != 0) {
544  add(vehNumber, begin, end, sourceD, destD, vehType);
545  }
546  } catch (OutOfBoundsException&) {
547  throw ProcessError("Missing at least one information in line '" + line + "'.");
548  } catch (NumberFormatException&) {
549  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
550  }
551  }
553 }
554 
555 
556 
557 double
559  return myNumLoaded;
560 }
561 
562 
563 double
565  return myNumWritten;
566 }
567 
568 
569 double
571  return myNumDiscarded;
572 }
573 
574 
575 void
576 ODMatrix::applyCurve(const Distribution_Points& ps, ODCell* cell, std::vector<ODCell*>& newCells) {
577  const std::vector<double>& times = ps.getVals();
578  for (int i = 0; i < (int)times.size() - 1; ++i) {
579  ODCell* ncell = new ODCell();
580  ncell->begin = TIME2STEPS(times[i]);
581  ncell->end = TIME2STEPS(times[i + 1]);
582  ncell->origin = cell->origin;
583  ncell->destination = cell->destination;
584  ncell->vehicleType = cell->vehicleType;
585  ncell->vehicleNumber = cell->vehicleNumber * ps.getProbs()[i] / ps.getOverallProb();
586  newCells.push_back(ncell);
587  }
588 }
589 
590 
591 void
593  std::vector<ODCell*> oldCells = myContainer;
594  myContainer.clear();
595  for (std::vector<ODCell*>::iterator i = oldCells.begin(); i != oldCells.end(); ++i) {
596  std::vector<ODCell*> newCells;
597  applyCurve(ps, *i, newCells);
598  copy(newCells.begin(), newCells.end(), back_inserter(myContainer));
599  delete *i;
600  }
601 }
602 
603 
604 void
606  std::vector<std::string> files = oc.getStringVector("od-matrix-files");
607  for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
608  LineReader lr(*i);
609  if (!lr.good()) {
610  throw ProcessError("Could not open '" + (*i) + "'.");
611  }
612  std::string type = lr.readLine();
613  // get the type only
614  if (type.find(';') != std::string::npos) {
615  type = type.substr(0, type.find(';'));
616  }
617  // parse type-dependant
618  if (type.length() > 1 && type[1] == 'V') {
619  // process ptv's 'V'-matrices
620  if (type.find('N') != std::string::npos) {
621  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
622  }
623  readV(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
624  } else if (type.length() > 1 && type[1] == 'O') {
625  // process ptv's 'O'-matrices
626  if (type.find('N') != std::string::npos) {
627  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
628  }
629  readO(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
630  } else {
631  throw ProcessError("'" + *i + "' uses an unknown matrix type '" + type + "'.");
632  }
633  }
634  std::vector<std::string> amitranFiles = oc.getStringVector("od-amitran-files");
635  for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) {
636  if (!FileHelpers::isReadable(*i)) {
637  throw ProcessError("Could not access matrix file '" + *i + "' to load.");
638  }
639  PROGRESS_BEGIN_MESSAGE("Loading matrix in Amitran format from '" + *i + "'");
640  ODAmitranHandler handler(*this, *i);
641  if (!XMLSubSys::runParser(handler, *i)) {
643  } else {
645  }
646  }
647 }
648 
649 
650 void
652  std::vector<std::string> routeFiles = oc.getStringVector("route-files");
653  for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) {
654  if (!FileHelpers::isReadable(*i)) {
655  throw ProcessError("Could not access route file '" + *i + "' to load.");
656  }
657  PROGRESS_BEGIN_MESSAGE("Loading routes and trips from '" + *i + "'");
658  if (!XMLSubSys::runParser(handler, *i)) {
660  } else {
662  }
663  }
664 }
665 
666 
668 ODMatrix::parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours) {
669  Distribution_Points result("N/A");
670  if (timelineDayInHours) {
671  if (def.size() != 24) {
672  throw ProcessError("Assuming 24 entries for a day timeline, but got " + toString(def.size()) + ".");
673  }
674  for (int chour = 0; chour < 24; ++chour) {
675  result.add(chour * 3600., StringUtils::toDouble(def[chour]));
676  }
677  result.add(24 * 3600., 0.); // dummy value to finish the last interval
678  } else {
679  for (int i = 0; i < (int)def.size(); i++) {
680  StringTokenizer st2(def[i], ":");
681  if (st2.size() != 2) {
682  throw ProcessError("Broken time line definition: missing a value in '" + def[i] + "'.");
683  }
684  const double time = StringUtils::toDouble(st2.next());
685  result.add(time, StringUtils::toDouble(st2.next()));
686  }
687  }
688  return result;
689 }
690 
691 
692 void
694  std::sort(myContainer.begin(), myContainer.end(), cell_by_begin_comparator());
695 }
696 
697 
698 /****************************************************************************/
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
SUMO_ATTR_TYPE
@ SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
RandomDistributor::add
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
Definition: RandomDistributor.h:70
ODMatrix::parseTimeLine
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:668
ToString.h
XMLSubSys::runParser
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:112
SUMO_ATTR_DEPART
@ SUMO_ATTR_DEPART
Definition: SUMOXMLDefinitions.h:431
ODCell::originIsEdge
bool originIsEdge
the origin "district" is an edge id
Definition: ODCell.h:76
LineReader.h
ODMatrix::write
void write(SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool uniform, const bool differSourceSink, const bool noVtype, const std::string &prefix, const bool stepLog, bool pedestrians, bool persontrips)
Writes the vehicles stored in the matrix assigning the sources and sinks.
Definition: ODMatrix.cpp:212
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
ODMatrix::ODMatrix
ODMatrix(const ODDistrictCont &dc)
Constructor.
Definition: ODMatrix.cpp:50
SUMOTime.h
ODCell::vehicleNumber
double vehicleNumber
The number of vehicles.
Definition: ODCell.h:52
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:41
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
DELTA_T
SUMOTime DELTA_T
Definition: SUMOTime.cpp:36
LineReader::readLine
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
Definition: LineReader.cpp:68
PROGRESS_FAILED_MESSAGE
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:282
OptionsCont.h
StringTokenizer::hasNext
bool hasNext()
returns the information whether further substrings exist
Definition: StringTokenizer.cpp:94
StringUtils::toDouble
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
Definition: StringUtils.cpp:345
MsgHandler.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
SUMOSAXHandler.h
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
SUMO_TAG_PERSON
@ SUMO_TAG_PERSON
Definition: SUMOXMLDefinitions.h:295
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMO_TAG_PERSONTRIP
@ SUMO_TAG_PERSONTRIP
Definition: SUMOXMLDefinitions.h:296
ODMatrix::myDistricts
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:360
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
StringTokenizer::next
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
Definition: StringTokenizer.cpp:99
SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_ARRIVALPOS
Definition: SUMOXMLDefinitions.h:437
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
ODMatrix.h
SUMO_ATTR_FROM_TAZ
@ SUMO_ATTR_FROM_TAZ
Definition: SUMOXMLDefinitions.h:646
StringTokenizer::WHITECHARS
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
Definition: StringTokenizer.h:67
ODDistrictCont::getRandomSourceFromDistrict
std::string getRandomSourceFromDistrict(const std::string &name) const
Returns the id of a random source from the named district.
Definition: ODDistrictCont.cpp:49
ODMatrix::myNumWritten
double myNumWritten
Number of written vehicles.
Definition: ODMatrix.h:369
ODDistrict::sinkNumber
int sinkNumber() const
Returns the number of sinks.
Definition: ODDistrict.cpp:70
ODMatrix::loadMatrix
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
Definition: ODMatrix.cpp:605
ODMatrix::myBegin
SUMOTime myBegin
parsed time bounds
Definition: ODMatrix.h:375
ODAmitranHandler.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
OptionsCont::getStringVector
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
Definition: OptionsCont.cpp:235
ODMatrix::computeDeparts
double computeDeparts(ODCell *cell, int &vehName, std::vector< ODVehicle > &into, const bool uniform, const bool differSourceSink, const std::string &prefix)
Computes the vehicle departs stored in the given cell and saves them in "into".
Definition: ODMatrix.cpp:144
SUMO_ATTR_BEGIN
@ SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:678
SUMO_ATTR_TO
@ SUMO_ATTR_TO
Definition: SUMOXMLDefinitions.h:640
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
ODMatrix::parseSingleTime
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:398
ODMatrix::add
bool add(double vehicleNumber, SUMOTime begin, SUMOTime end, const std::string &origin, const std::string &destination, const std::string &vehicleType, const bool originIsEdge=false, const bool destinationIsEdge=false)
Builds a single cell from the given values, verifying them.
Definition: ODMatrix.cpp:63
ODMatrix::ODVehicle::cell
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
Definition: ODMatrix.h:271
NumberFormatException
Definition: UtilExceptions.h:95
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
SUMO_ATTR_ARRIVALSPEED
@ SUMO_ATTR_ARRIVALSPEED
Definition: SUMOXMLDefinitions.h:439
ODMatrix::loadRoutes
void loadRoutes(OptionsCont &oc, SUMOSAXHandler &handler)
read SUMO routes
Definition: ODMatrix.cpp:651
RandHelper::rand
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:53
ODMatrix::ODVehicle::id
std::string id
The id of the vehicle.
Definition: ODMatrix.h:267
SUMO_TAG_FLOW
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
Definition: SUMOXMLDefinitions.h:149
SUMO_ATTR_PROB
@ SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:629
ODCell
A single O/D-matrix cell.
Definition: ODCell.h:50
StringUtils::prune
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
Definition: StringUtils.cpp:48
ODMatrix::ODVehicle::depart
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:269
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
ODMatrix::ODVehicle
An internal representation of a single vehicle.
Definition: ODMatrix.h:265
ODCell::vehicleType
std::string vehicleType
Name of the vehicle type.
Definition: ODCell.h:67
StringTokenizer
Definition: StringTokenizer.h:61
LineReader::getFileName
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:171
ODCell::destination
std::string destination
Name of the destination district.
Definition: ODCell.h:64
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
SUMO_ATTR_DEPARTSPEED
@ SUMO_ATTR_DEPARTSPEED
Definition: SUMOXMLDefinitions.h:435
SUMO_ATTR_DEPARTLANE
@ SUMO_ATTR_DEPARTLANE
Definition: SUMOXMLDefinitions.h:432
OutputDevice.h
ProcessError
Definition: UtilExceptions.h:39
ODDistrictCont::getRandomSinkFromDistrict
std::string getRandomSinkFromDistrict(const std::string &name) const
Returns the id of a random sink from the named district.
Definition: ODDistrictCont.cpp:59
OutOfBoundsException
Definition: UtilExceptions.h:134
ODMatrix::myShortCut
std::map< const std::pair< const std::string, const std::string >, std::vector< ODCell * > > myShortCut
The loaded cells indexed by origin and destination.
Definition: ODMatrix.h:357
ODMatrix::descending_departure_comperator
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:417
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
ODMatrix::myContainer
std::vector< ODCell * > myContainer
The loaded cells.
Definition: ODMatrix.h:354
ODDistrict::sourceNumber
int sourceNumber() const
Returns the number of sources.
Definition: ODDistrict.cpp:76
RandomDistributor::getProbs
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
Definition: RandomDistributor.h:162
LineReader::hasMore
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:52
ODMatrix::myNumDiscarded
double myNumDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:372
ODMatrix::~ODMatrix
~ODMatrix()
Destructor.
Definition: ODMatrix.cpp:54
LineReader
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:50
string2time
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:44
StringTokenizer::size
int size() const
returns the number of existing substrings
Definition: StringTokenizer.cpp:137
LineReader::good
bool good() const
Returns the information whether the stream is readable.
Definition: LineReader.cpp:217
ODCell::end
SUMOTime end
The end time this cell describes.
Definition: ODCell.h:58
ODMatrix::readFactor
double readFactor(LineReader &lr, double scale)
Definition: ODMatrix.cpp:428
ODAmitranHandler
An XML-Handler for districts.
Definition: ODAmitranHandler.h:45
ODDistrictCont
A container for districts.
Definition: ODDistrictCont.h:41
SUMO_ATTR_FROM
@ SUMO_ATTR_FROM
Definition: SUMOXMLDefinitions.h:639
ODMatrix::ODVehicle::to
std::string to
The edge the vehicles shall end at.
Definition: ODMatrix.h:275
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:208
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:278
ODMatrix::getNumLoaded
double getNumLoaded() const
Returns the number of loaded vehicles.
Definition: ODMatrix.cpp:558
PROGRESS_BEGIN_MESSAGE
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:278
SUMO_ATTR_TO_TAZ
@ SUMO_ATTR_TO_TAZ
Definition: SUMOXMLDefinitions.h:647
SUMO_TAG_WALK
@ SUMO_TAG_WALK
Definition: SUMOXMLDefinitions.h:298
Distribution_Points
Definition: Distribution_Points.h:39
ODMatrix::readTime
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:409
ODCell::origin
std::string origin
Name of the origin district.
Definition: ODCell.h:61
ODMatrix::getNumWritten
double getNumWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:564
ODMatrix::getNextNonCommentLine
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:386
NamedObjectCont::get
T get(const std::string &id) const
Retrieves an item.
Definition: NamedObjectCont.h:98
ODMatrix::sortByBeginTime
void sortByBeginTime()
Definition: ODMatrix.cpp:693
ODCell::destinationIsEdge
bool destinationIsEdge
the destination "district" is an edge id
Definition: ODCell.h:79
PROGRESS_DONE_MESSAGE
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:279
ODMatrix::readO
void readO(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
Definition: ODMatrix.cpp:508
FileHelpers::isReadable
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:49
ODMatrix::getNumDiscarded
double getNumDiscarded() const
Returns the number of discarded vehicles.
Definition: ODMatrix.cpp:570
config.h
SUMO_TAG_PERSONFLOW
@ SUMO_TAG_PERSONFLOW
Definition: SUMOXMLDefinitions.h:299
ODMatrix::writeFlows
void writeFlows(const SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool noVtype, const std::string &prefix, bool asProbability=false, bool pedestrians=false, bool persontrips=false)
Writes the flows stored in the matrix.
Definition: ODMatrix.cpp:301
RandHelper.h
StringTokenizer.h
ODMatrix::applyCurve
void applyCurve(const Distribution_Points &ps)
Splits the stored cells dividing them on the given time line.
Definition: ODMatrix.cpp:592
SUMO_ATTR_END
@ SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:680
StdDefs.h
ODMatrix::readV
void readV(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
Definition: ODMatrix.cpp:440
SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_DEPARTPOS
Definition: SUMOXMLDefinitions.h:433
ODMatrix::cell_by_begin_comparator
Used for sorting the cells by the begin time they describe.
Definition: ODMatrix.h:381
ODCell::begin
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:55
ODMatrix::myEnd
SUMOTime myEnd
Definition: ODMatrix.h:375
RandomDistributor::getOverallProb
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
Definition: RandomDistributor.h:133
ODMatrix::myNumLoaded
double myNumLoaded
Number of loaded vehicles.
Definition: ODMatrix.h:366
SUMO_ATTR_NUMBER
@ SUMO_ATTR_NUMBER
Definition: SUMOXMLDefinitions.h:666
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
ODCell::departures
std::map< SUMOTime, std::vector< std::string > > departures
mapping of departure times to departing vehicles, if already fixed
Definition: ODCell.h:73
SUMO_ATTR_ARRIVALLANE
@ SUMO_ATTR_ARRIVALLANE
Definition: SUMOXMLDefinitions.h:436
ODMatrix::ODVehicle::from
std::string from
The edge the vehicles shall start at.
Definition: ODMatrix.h:273
SUMO_TAG_TRIP
@ SUMO_TAG_TRIP
a single trip definition (used by router)
Definition: SUMOXMLDefinitions.h:145
RandomDistributor::getVals
const std::vector< T > & getVals() const
Returns the members of the distribution.
Definition: RandomDistributor.h:151
ODMatrix::writeDefaultAttrs
void writeDefaultAttrs(OutputDevice &dev, const bool noVtype, const ODCell *const cell)
Helper function for flow and trip output writing the depart and arrival attributes.
Definition: ODMatrix.cpp:183
XMLSubSys.h
ODMatrix::myMissingDistricts
std::set< std::string > myMissingDistricts
The missing districts already warned about.
Definition: ODMatrix.h:363