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