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