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