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