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  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++;
265  dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to);
266  writeDefaultAttrs(dev, noVtype, i->cell);
267  dev.closeTag();
268  }
269  }
270  while (vehicles.size() != 0 && vehicles.back().depart == t) {
271  vehicles.pop_back();
272  }
273  if (!vehicles.empty()) {
274  t = vehicles.back().depart;
275  }
276  if (next != myContainer.end() && (t > (*next)->begin || vehicles.empty())) {
277  t = (*next)->begin;
278  }
279  if (next == myContainer.end() && vehicles.empty()) {
280  break;
281  }
282  }
283 }
284 
285 
286 void
287 ODMatrix::writeFlows(const SUMOTime begin, const SUMOTime end,
288  OutputDevice& dev, bool noVtype,
289  const std::string& prefix,
290  bool asProbability) {
291  if (myContainer.size() == 0) {
292  return;
293  }
294  int flowName = 0;
295  sortByBeginTime();
296  // recheck begin time
297  for (std::vector<ODCell*>::const_iterator i = myContainer.begin(); i != myContainer.end(); ++i) {
298  const ODCell* const c = *i;
299  if (c->end > begin && c->begin < end) {
300  dev.openTag(SUMO_TAG_FLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++));
303  if (!asProbability) {
305  } else {
306  const double probability = float(c->vehicleNumber) / STEPS2TIME(c->end - c->begin);
307  if (probability > 1) {
308  WRITE_WARNING("Flow density of " + toString(probability) + " vehicles per second, cannot be represented with a simple probability. Falling back to even spacing.");
310  } else {
311  dev.setPrecision(6);
312  dev.writeAttr(SUMO_ATTR_PROB, probability);
313  dev.setPrecision();
314  }
315  }
316  writeDefaultAttrs(dev, noVtype, *i);
317  dev.closeTag();
318  }
319  }
320 }
321 
322 
323 std::string
325  std::string line;
326  do {
327  line = lr.readLine();
328  if (line[0] != '*') {
329  return StringUtils::prune(line);
330  }
331  } while (lr.good() && lr.hasMore());
332  throw ProcessError();
333 }
334 
335 
336 SUMOTime
337 ODMatrix::parseSingleTime(const std::string& time) {
338  if (time.find('.') == std::string::npos) {
339  throw OutOfBoundsException();
340  }
341  std::string hours = time.substr(0, time.find('.'));
342  std::string minutes = time.substr(time.find('.') + 1);
343  return TIME2STEPS(TplConvert::_2int(hours.c_str()) * 3600 + TplConvert::_2int(minutes.c_str()) * 60);
344 }
345 
346 
347 std::pair<SUMOTime, SUMOTime>
349  std::string line = getNextNonCommentLine(lr);
350  try {
352  SUMOTime begin = parseSingleTime(st.next());
353  SUMOTime end = parseSingleTime(st.next());
354  if (begin >= end) {
355  throw ProcessError("Begin time is larger than end time.");
356  }
357  return std::make_pair(begin, end);
358  } catch (OutOfBoundsException&) {
359  throw ProcessError("Broken period definition '" + line + "'.");
360  } catch (NumberFormatException&) {
361  throw ProcessError("Broken period definition '" + line + "'.");
362  }
363 }
364 
365 double
366 ODMatrix::readFactor(LineReader& lr, double scale) {
367  std::string line = getNextNonCommentLine(lr);
368  double factor = -1;
369  try {
370  factor = TplConvert::_2double(line.c_str()) * scale;
371  } catch (NumberFormatException&) {
372  throw ProcessError("Broken factor: '" + line + "'.");
373  }
374  return factor;
375 }
376 
377 void
378 ODMatrix::readV(LineReader& lr, double scale,
379  std::string vehType, bool matrixHasVehType) {
380  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as VMR");
381  // parse first defs
382  std::string line;
383  if (matrixHasVehType) {
384  line = getNextNonCommentLine(lr);
385  if (vehType == "") {
386  vehType = StringUtils::prune(line);
387  }
388  }
389 
390  // parse time
391  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
392  SUMOTime begin = times.first;
393  SUMOTime end = times.second;
394 
395  // factor
396  double factor = readFactor(lr, scale);
397 
398  // districts
399  line = getNextNonCommentLine(lr);
400  int districtNo = TplConvert::_2int(StringUtils::prune(line).c_str());
401  // parse district names (normally ints)
402  std::vector<std::string> names;
403  do {
404  line = getNextNonCommentLine(lr);
406  while (st2.hasNext()) {
407  names.push_back(st2.next());
408  }
409  } while ((int) names.size() != districtNo);
410 
411  // parse the cells
412  for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) {
413  std::vector<std::string>::iterator di = names.begin();
414  //
415  do {
416  line = getNextNonCommentLine(lr);
417  if (line.length() == 0) {
418  continue;
419  }
420  try {
422  while (st2.hasNext()) {
423  assert(di != names.end());
424  double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor;
425  if (vehNumber != 0) {
426  add(vehNumber, begin, end, *si, *di, vehType);
427  }
428  if (di == names.end()) {
429  throw ProcessError("More entries than districts found.");
430  }
431  ++di;
432  }
433  } catch (NumberFormatException&) {
434  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
435  }
436  if (!lr.hasMore()) {
437  break;
438  }
439  } while (di != names.end());
440  }
442 }
443 
444 
445 void
446 ODMatrix::readO(LineReader& lr, double scale,
447  std::string vehType, bool matrixHasVehType) {
448  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR");
449  // parse first defs
450  std::string line;
451  if (matrixHasVehType) {
452  line = getNextNonCommentLine(lr);
453  int type = TplConvert::_2int(StringUtils::prune(line).c_str());
454  if (vehType == "") {
455  vehType = toString(type);
456  }
457  }
458 
459  // parse time
460  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
461  SUMOTime begin = times.first;
462  SUMOTime end = times.second;
463 
464  // factor
465  double factor = readFactor(lr, scale);
466 
467  // parse the cells
468  while (lr.hasMore()) {
469  line = getNextNonCommentLine(lr);
470  if (line.length() == 0) {
471  continue;
472  }
474  if (st2.size() == 0) {
475  continue;
476  }
477  try {
478  std::string sourceD = st2.next();
479  std::string destD = st2.next();
480  double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor;
481  if (vehNumber != 0) {
482  add(vehNumber, begin, end, sourceD, destD, vehType);
483  }
484  } catch (OutOfBoundsException&) {
485  throw ProcessError("Missing at least one information in line '" + line + "'.");
486  } catch (NumberFormatException&) {
487  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
488  }
489  }
491 }
492 
493 
494 
495 double
497  return myNumLoaded;
498 }
499 
500 
501 double
503  return myNumWritten;
504 }
505 
506 
507 double
509  return myNumDiscarded;
510 }
511 
512 
513 void
514 ODMatrix::applyCurve(const Distribution_Points& ps, ODCell* cell, std::vector<ODCell*>& newCells) {
515  const std::vector<double>& times = ps.getVals();
516  for (int i = 0; i < (int)times.size() - 1; ++i) {
517  ODCell* ncell = new ODCell();
518  ncell->begin = TIME2STEPS(times[i]);
519  ncell->end = TIME2STEPS(times[i + 1]);
520  ncell->origin = cell->origin;
521  ncell->destination = cell->destination;
522  ncell->vehicleType = cell->vehicleType;
523  ncell->vehicleNumber = cell->vehicleNumber * ps.getProbs()[i] / ps.getOverallProb();
524  newCells.push_back(ncell);
525  }
526 }
527 
528 
529 void
531  std::vector<ODCell*> oldCells = myContainer;
532  myContainer.clear();
533  for (std::vector<ODCell*>::iterator i = oldCells.begin(); i != oldCells.end(); ++i) {
534  std::vector<ODCell*> newCells;
535  applyCurve(ps, *i, newCells);
536  copy(newCells.begin(), newCells.end(), back_inserter(myContainer));
537  delete *i;
538  }
539 }
540 
541 
542 void
544  std::vector<std::string> files = oc.getStringVector("od-matrix-files");
545  for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
546  LineReader lr(*i);
547  if (!lr.good()) {
548  throw ProcessError("Could not open '" + (*i) + "'.");
549  }
550  std::string type = lr.readLine();
551  // get the type only
552  if (type.find(';') != std::string::npos) {
553  type = type.substr(0, type.find(';'));
554  }
555  // parse type-dependant
556  if (type.length() > 1 && type[1] == 'V') {
557  // process ptv's 'V'-matrices
558  if (type.find('N') != std::string::npos) {
559  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
560  }
561  readV(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
562  } else if (type.length() > 1 && type[1] == 'O') {
563  // process ptv's 'O'-matrices
564  if (type.find('N') != std::string::npos) {
565  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
566  }
567  readO(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
568  } else {
569  throw ProcessError("'" + *i + "' uses an unknown matrix type '" + type + "'.");
570  }
571  }
572  std::vector<std::string> amitranFiles = oc.getStringVector("od-amitran-files");
573  for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) {
574  if (!FileHelpers::isReadable(*i)) {
575  throw ProcessError("Could not access matrix file '" + *i + "' to load.");
576  }
577  PROGRESS_BEGIN_MESSAGE("Loading matrix in Amitran format from '" + *i + "'");
578  ODAmitranHandler handler(*this, *i);
579  if (!XMLSubSys::runParser(handler, *i)) {
581  } else {
583  }
584  }
585 }
586 
587 
588 void
590  std::vector<std::string> routeFiles = oc.getStringVector("route-files");
591  for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) {
592  if (!FileHelpers::isReadable(*i)) {
593  throw ProcessError("Could not access route file '" + *i + "' to load.");
594  }
595  PROGRESS_BEGIN_MESSAGE("Loading routes and trips from '" + *i + "'");
596  if (!XMLSubSys::runParser(handler, *i)) {
598  } else {
600  }
601  }
602 }
603 
604 
606 ODMatrix::parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours) {
607  Distribution_Points result("N/A");
608  if (timelineDayInHours) {
609  if (def.size() != 24) {
610  throw ProcessError("Assuming 24 entries for a day timeline, but got " + toString(def.size()) + ".");
611  }
612  for (int chour = 0; chour < 24; ++chour) {
613  result.add(chour * 3600., TplConvert::_2double(def[chour].c_str()));
614  }
615  result.add(24 * 3600., 0.); // dummy value to finish the last interval
616  } else {
617  for (int i = 0; i < (int)def.size(); i++) {
618  StringTokenizer st2(def[i], ":");
619  if (st2.size() != 2) {
620  throw ProcessError("Broken time line definition: missing a value in '" + def[i] + "'.");
621  }
622  const double time = TplConvert::_2double(st2.next().c_str());
623  result.add(time, TplConvert::_2double(st2.next().c_str()));
624  }
625  }
626  return result;
627 }
628 
629 
630 void
632  std::sort(myContainer.begin(), myContainer.end(), cell_by_begin_comparator());
633 }
634 
635 
636 /****************************************************************************/
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:256
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:54
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:76
static const int WHITECHARS
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:179
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:58
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:225
An internal representation of a single vehicle.
Definition: ODMatrix.h:257
int sourceNumber() const
Returns the number of sources.
Definition: ODDistrict.cpp:84
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:70
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
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:110
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:337
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
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
Definition: ODMatrix.cpp:543
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
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
~ODMatrix()
Destructor.
Definition: ODMatrix.cpp:62
double myNumDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:364
A single O/D-matrix cell.
Definition: ODCell.h:58
double myNumWritten
Number of written vehicles.
Definition: ODMatrix.h:361
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
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:69
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:65
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:589
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:47
static double rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
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:202
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:407
double readFactor(LineReader &lr, double scale)
Definition: ODMatrix.cpp:366
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:349
void sortByBeginTime()
Definition: ODMatrix.cpp:631
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:63
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:496
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
double getNumWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:502
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:348
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:324
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: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
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:60
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:297
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:530
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:378
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:446
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
double getNumDiscarded() const
Returns the number of discarded vehicles.
Definition: ODMatrix.cpp:508
a single trip definition (used by router)
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)
Writes the vehicles stored in the matrix assigning the sources and sinks.
Definition: ODMatrix.cpp:217
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: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: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:287
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:78
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:606