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 = 0;
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 == 0) {
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  dev.openTag(SUMO_TAG_FLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++));
315  if (!asProbability) {
317  } else {
318  const double probability = float(c->vehicleNumber) / STEPS2TIME(c->end - c->begin);
319  if (probability > 1) {
320  WRITE_WARNING("Flow density of " + toString(probability) + " vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
322  } else {
323  dev.setPrecision(6);
324  dev.writeAttr(SUMO_ATTR_PROB, probability);
325  dev.setPrecision();
326  }
327  }
328  writeDefaultAttrs(dev, noVtype, *i);
329  dev.closeTag();
330  }
331  }
332 }
333 
334 
335 std::string
337  while (lr.good() && lr.hasMore()) {
338  const std::string line = lr.readLine();
339  if (line[0] != '*') {
340  return StringUtils::prune(line);
341  }
342  }
343  throw ProcessError("End of file while reading " + lr.getFileName() + ".");
344 }
345 
346 
347 SUMOTime
348 ODMatrix::parseSingleTime(const std::string& time) {
349  if (time.find('.') == std::string::npos) {
350  throw OutOfBoundsException();
351  }
352  std::string hours = time.substr(0, time.find('.'));
353  std::string minutes = time.substr(time.find('.') + 1);
354  return TIME2STEPS(TplConvert::_2int(hours.c_str()) * 3600 + TplConvert::_2int(minutes.c_str()) * 60);
355 }
356 
357 
358 std::pair<SUMOTime, SUMOTime>
360  std::string line = getNextNonCommentLine(lr);
361  try {
363  SUMOTime begin = parseSingleTime(st.next());
364  SUMOTime end = parseSingleTime(st.next());
365  if (begin >= end) {
366  throw ProcessError("Begin time is larger than end time.");
367  }
368  return std::make_pair(begin, end);
369  } catch (OutOfBoundsException&) {
370  throw ProcessError("Broken period definition '" + line + "'.");
371  } catch (NumberFormatException&) {
372  throw ProcessError("Broken period definition '" + line + "'.");
373  }
374 }
375 
376 double
377 ODMatrix::readFactor(LineReader& lr, double scale) {
378  std::string line = getNextNonCommentLine(lr);
379  double factor = -1;
380  try {
381  factor = TplConvert::_2double(line.c_str()) * scale;
382  } catch (NumberFormatException&) {
383  throw ProcessError("Broken factor: '" + line + "'.");
384  }
385  return factor;
386 }
387 
388 void
389 ODMatrix::readV(LineReader& lr, double scale,
390  std::string vehType, bool matrixHasVehType) {
391  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as VMR");
392  // parse first defs
393  std::string line;
394  if (matrixHasVehType) {
395  line = getNextNonCommentLine(lr);
396  if (vehType == "") {
397  vehType = StringUtils::prune(line);
398  }
399  }
400 
401  // parse time
402  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
403  SUMOTime begin = times.first;
404  SUMOTime end = times.second;
405 
406  // factor
407  double factor = readFactor(lr, scale);
408 
409  // districts
410  line = getNextNonCommentLine(lr);
411  const int numDistricts = TplConvert::_2int(StringUtils::prune(line).c_str());
412  // parse district names (normally ints)
413  std::vector<std::string> names;
414  while ((int)names.size() != numDistricts) {
415  line = getNextNonCommentLine(lr);
417  while (st2.hasNext()) {
418  names.push_back(st2.next());
419  }
420  }
421 
422  // parse the cells
423  for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) {
424  std::vector<std::string>::iterator di = names.begin();
425  //
426  do {
427  line = getNextNonCommentLine(lr);
428  if (line.length() == 0) {
429  continue;
430  }
431  try {
433  while (st2.hasNext()) {
434  assert(di != names.end());
435  double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor;
436  if (vehNumber != 0) {
437  add(vehNumber, begin, end, *si, *di, vehType);
438  }
439  if (di == names.end()) {
440  throw ProcessError("More entries than districts found.");
441  }
442  ++di;
443  }
444  } catch (NumberFormatException&) {
445  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
446  }
447  if (!lr.hasMore()) {
448  break;
449  }
450  } while (di != names.end());
451  }
453 }
454 
455 
456 void
457 ODMatrix::readO(LineReader& lr, double scale,
458  std::string vehType, bool matrixHasVehType) {
459  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR");
460  // parse first defs
461  std::string line;
462  if (matrixHasVehType) {
463  line = getNextNonCommentLine(lr);
464  int type = TplConvert::_2int(StringUtils::prune(line).c_str());
465  if (vehType == "") {
466  vehType = toString(type);
467  }
468  }
469 
470  // parse time
471  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
472  SUMOTime begin = times.first;
473  SUMOTime end = times.second;
474 
475  // factor
476  double factor = readFactor(lr, scale);
477 
478  // parse the cells
479  while (lr.hasMore()) {
480  line = getNextNonCommentLine(lr);
481  if (line.length() == 0) {
482  continue;
483  }
485  if (st2.size() == 0) {
486  continue;
487  }
488  try {
489  std::string sourceD = st2.next();
490  std::string destD = st2.next();
491  double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor;
492  if (vehNumber != 0) {
493  add(vehNumber, begin, end, sourceD, destD, vehType);
494  }
495  } catch (OutOfBoundsException&) {
496  throw ProcessError("Missing at least one information in line '" + line + "'.");
497  } catch (NumberFormatException&) {
498  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
499  }
500  }
502 }
503 
504 
505 
506 double
508  return myNumLoaded;
509 }
510 
511 
512 double
514  return myNumWritten;
515 }
516 
517 
518 double
520  return myNumDiscarded;
521 }
522 
523 
524 void
525 ODMatrix::applyCurve(const Distribution_Points& ps, ODCell* cell, std::vector<ODCell*>& newCells) {
526  const std::vector<double>& times = ps.getVals();
527  for (int i = 0; i < (int)times.size() - 1; ++i) {
528  ODCell* ncell = new ODCell();
529  ncell->begin = TIME2STEPS(times[i]);
530  ncell->end = TIME2STEPS(times[i + 1]);
531  ncell->origin = cell->origin;
532  ncell->destination = cell->destination;
533  ncell->vehicleType = cell->vehicleType;
534  ncell->vehicleNumber = cell->vehicleNumber * ps.getProbs()[i] / ps.getOverallProb();
535  newCells.push_back(ncell);
536  }
537 }
538 
539 
540 void
542  std::vector<ODCell*> oldCells = myContainer;
543  myContainer.clear();
544  for (std::vector<ODCell*>::iterator i = oldCells.begin(); i != oldCells.end(); ++i) {
545  std::vector<ODCell*> newCells;
546  applyCurve(ps, *i, newCells);
547  copy(newCells.begin(), newCells.end(), back_inserter(myContainer));
548  delete *i;
549  }
550 }
551 
552 
553 void
555  std::vector<std::string> files = oc.getStringVector("od-matrix-files");
556  for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
557  LineReader lr(*i);
558  if (!lr.good()) {
559  throw ProcessError("Could not open '" + (*i) + "'.");
560  }
561  std::string type = lr.readLine();
562  // get the type only
563  if (type.find(';') != std::string::npos) {
564  type = type.substr(0, type.find(';'));
565  }
566  // parse type-dependant
567  if (type.length() > 1 && type[1] == 'V') {
568  // process ptv's 'V'-matrices
569  if (type.find('N') != std::string::npos) {
570  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
571  }
572  readV(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
573  } else if (type.length() > 1 && type[1] == 'O') {
574  // process ptv's 'O'-matrices
575  if (type.find('N') != std::string::npos) {
576  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
577  }
578  readO(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
579  } else {
580  throw ProcessError("'" + *i + "' uses an unknown matrix type '" + type + "'.");
581  }
582  }
583  std::vector<std::string> amitranFiles = oc.getStringVector("od-amitran-files");
584  for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) {
585  if (!FileHelpers::isReadable(*i)) {
586  throw ProcessError("Could not access matrix file '" + *i + "' to load.");
587  }
588  PROGRESS_BEGIN_MESSAGE("Loading matrix in Amitran format from '" + *i + "'");
589  ODAmitranHandler handler(*this, *i);
590  if (!XMLSubSys::runParser(handler, *i)) {
592  } else {
594  }
595  }
596 }
597 
598 
599 void
601  std::vector<std::string> routeFiles = oc.getStringVector("route-files");
602  for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) {
603  if (!FileHelpers::isReadable(*i)) {
604  throw ProcessError("Could not access route file '" + *i + "' to load.");
605  }
606  PROGRESS_BEGIN_MESSAGE("Loading routes and trips from '" + *i + "'");
607  if (!XMLSubSys::runParser(handler, *i)) {
609  } else {
611  }
612  }
613 }
614 
615 
617 ODMatrix::parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours) {
618  Distribution_Points result("N/A");
619  if (timelineDayInHours) {
620  if (def.size() != 24) {
621  throw ProcessError("Assuming 24 entries for a day timeline, but got " + toString(def.size()) + ".");
622  }
623  for (int chour = 0; chour < 24; ++chour) {
624  result.add(chour * 3600., TplConvert::_2double(def[chour].c_str()));
625  }
626  result.add(24 * 3600., 0.); // dummy value to finish the last interval
627  } else {
628  for (int i = 0; i < (int)def.size(); i++) {
629  StringTokenizer st2(def[i], ":");
630  if (st2.size() != 2) {
631  throw ProcessError("Broken time line definition: missing a value in '" + def[i] + "'.");
632  }
633  const double time = TplConvert::_2double(st2.next().c_str());
634  result.add(time, TplConvert::_2double(st2.next().c_str()));
635  }
636  }
637  return result;
638 }
639 
640 
641 void
643  std::sort(myContainer.begin(), myContainer.end(), cell_by_begin_comparator());
644 }
645 
646 
647 /****************************************************************************/
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:67
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:68
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:348
double vehicleNumber
The number of vehicles.
Definition: ODCell.h:53
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
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:554
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:247
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
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:600
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:244
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:401
double readFactor(LineReader &lr, double scale)
Definition: ODMatrix.cpp:377
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
void sortByBeginTime()
Definition: ODMatrix.cpp:642
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:507
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:248
double getNumWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:513
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:359
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:336
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:45
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
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:305
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:541
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:389
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:457
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:519
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:245
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:617