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-2016 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 #ifdef CHECK_MEMORY_LEAKS
55 #include <foreign/nvwa/debug_new.h>
56 #endif // CHECK_MEMORY_LEAKS
57 
58 
59 // ===========================================================================
60 // method definitions
61 // ===========================================================================
63  : myDistricts(dc), myNoLoaded(0), myNoWritten(0), myNoDiscarded(0) {}
64 
65 
67  for (std::vector<ODCell*>::iterator i = myContainer.begin(); i != myContainer.end(); ++i) {
68  delete *i;
69  }
70  myContainer.clear();
71 }
72 
73 
74 void
75 ODMatrix::add(SUMOReal vehicleNumber, SUMOTime begin,
76  SUMOTime end, const std::string& origin, const std::string& destination,
77  const std::string& vehicleType) {
78  myNoLoaded += vehicleNumber;
79  if (myDistricts.get(origin) == 0 && myDistricts.get(destination) == 0) {
80  WRITE_WARNING("Missing origin '" + origin + "' and destination '" + destination + "' (" + toString(vehicleNumber) + " vehicles).");
81  } else if (myDistricts.get(origin) == 0 && vehicleNumber > 0) {
82  WRITE_ERROR("Missing origin '" + origin + "' (" + toString(vehicleNumber) + " vehicles).");
83  myNoDiscarded += vehicleNumber;
84  } else if (myDistricts.get(destination) == 0 && vehicleNumber > 0) {
85  WRITE_ERROR("Missing destination '" + destination + "' (" + toString(vehicleNumber) + " vehicles).");
86  myNoDiscarded += vehicleNumber;
87  } else {
88  if (myDistricts.get(origin)->sourceNumber() == 0) {
89  WRITE_ERROR("District '" + origin + "' has no source.");
90  myNoDiscarded += vehicleNumber;
91  } else if (myDistricts.get(destination)->sinkNumber() == 0) {
92  WRITE_ERROR("District '" + destination + "' has no sink.");
93  myNoDiscarded += vehicleNumber;
94  } else {
95  ODCell* cell = new ODCell();
96  cell->begin = begin;
97  cell->end = end;
98  cell->origin = origin;
99  cell->destination = destination;
100  cell->vehicleType = vehicleType;
101  cell->vehicleNumber = vehicleNumber;
102  myContainer.push_back(cell);
103  }
104  }
105 }
106 
107 
108 void
109 ODMatrix::add(const std::string& id, const SUMOTime depart,
110  const std::pair<const std::string, const std::string>& od,
111  const std::string& vehicleType) {
112  // we start looking from the end because there is a high probability that the input is sorted by time
113  std::vector<ODCell*>& odList = myShortCut[od];
114  ODCell* cell = 0;
115  for (std::vector<ODCell*>::const_reverse_iterator c = odList.rbegin(); c != odList.rend(); ++c) {
116  if ((*c)->begin <= depart && (*c)->end > depart && (*c)->vehicleType == vehicleType) {
117  cell = *c;
118  break;
119  }
120  }
121  if (cell == 0) {
122  const SUMOTime interval = string2time(OptionsCont::getOptions().getString("aggregation-interval"));
123  const int intervalIdx = (int)(depart / interval);
124  add(1., intervalIdx * interval, (intervalIdx + 1) * interval, od.first, od.second, vehicleType);
125  cell = myContainer.back();
126  odList.push_back(cell);
127  } else {
128  cell->vehicleNumber += 1.;
129  }
130  cell->departures[depart].push_back(id);
131 }
132 
133 
134 SUMOReal
136  size_t& vehName, std::vector<ODVehicle>& into,
137  const bool uniform, const bool differSourceSink,
138  const std::string& prefix) {
139  int vehicles2insert = (int) cell->vehicleNumber;
140  // compute whether the fraction forces an additional vehicle insertion
141  if (RandHelper::rand() < cell->vehicleNumber - (SUMOReal)vehicles2insert) {
142  vehicles2insert++;
143  }
144  if (vehicles2insert == 0) {
145  return cell->vehicleNumber;
146  }
147 
148  const SUMOReal offset = (SUMOReal)(cell->end - cell->begin) / (SUMOReal) vehicles2insert / (SUMOReal) 2.;
149  for (int i = 0; i < vehicles2insert; ++i) {
150  ODVehicle veh;
151  veh.id = prefix + toString(vehName++);
152 
153  if (uniform) {
154  veh.depart = (SUMOTime)(offset + cell->begin + ((SUMOReal)(cell->end - cell->begin) * (SUMOReal) i / (SUMOReal) vehicles2insert));
155  } else {
156  veh.depart = (SUMOTime)RandHelper::rand(cell->begin, cell->end);
157  }
158  const bool canDiffer = myDistricts.get(cell->origin)->sourceNumber() > 1 || myDistricts.get(cell->destination)->sinkNumber() > 1;
159  do {
162  } while (canDiffer && differSourceSink && (veh.to == veh.from));
163  if (!canDiffer && differSourceSink && (veh.to == veh.from)) {
164  WRITE_WARNING("Cannot find different source and sink edge for origin '" + cell->origin + "' and destination '" + cell->destination + "'.");
165  }
166  veh.cell = cell;
167  into.push_back(veh);
168  }
169  return cell->vehicleNumber - vehicles2insert;
170 }
171 
172 
173 void
174 ODMatrix::writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
175  const ODCell* const cell) {
176  const OptionsCont& oc = OptionsCont::getOptions();
177  if (!noVtype && cell->vehicleType != "") {
179  }
181  if (oc.isSet("departlane") && oc.getString("departlane") != "default") {
182  dev.writeAttr(SUMO_ATTR_DEPARTLANE, oc.getString("departlane"));
183  }
184  if (oc.isSet("departpos")) {
185  dev.writeAttr(SUMO_ATTR_DEPARTPOS, oc.getString("departpos"));
186  }
187  if (oc.isSet("departspeed") && oc.getString("departspeed") != "default") {
188  dev.writeAttr(SUMO_ATTR_DEPARTSPEED, oc.getString("departspeed"));
189  }
190  if (oc.isSet("arrivallane")) {
191  dev.writeAttr(SUMO_ATTR_ARRIVALLANE, oc.getString("arrivallane"));
192  }
193  if (oc.isSet("arrivalpos")) {
194  dev.writeAttr(SUMO_ATTR_ARRIVALPOS, oc.getString("arrivalpos"));
195  }
196  if (oc.isSet("arrivalspeed")) {
197  dev.writeAttr(SUMO_ATTR_ARRIVALSPEED, oc.getString("arrivalspeed"));
198  }
199 }
200 
201 
202 void
204  OutputDevice& dev, const bool uniform,
205  const bool differSourceSink, const bool noVtype,
206  const std::string& prefix, const bool stepLog) {
207  if (myContainer.size() == 0) {
208  return;
209  }
210  std::map<std::pair<std::string, std::string>, SUMOReal> fractionLeft;
211  size_t vehName = 0;
212  sortByBeginTime();
213  // recheck begin time
214  begin = MAX2(begin, myContainer.front()->begin);
215  std::vector<ODCell*>::iterator next = myContainer.begin();
216  std::vector<ODVehicle> vehicles;
217  SUMOTime lastOut = -DELTA_T;
218  // go through the time steps
219  for (SUMOTime t = begin; t < end;) {
220  if (stepLog && t - lastOut >= DELTA_T) {
221  std::cout << "Parsing time " + time2string(t) << '\r';
222  lastOut = t;
223  }
224  // recheck whether a new cell got valid
225  bool changed = false;
226  while (next != myContainer.end() && (*next)->begin <= t && (*next)->end > t) {
227  std::pair<std::string, std::string> odID = std::make_pair((*next)->origin, (*next)->destination);
228  // check whether the current cell must be extended by the last fraction
229  if (fractionLeft.find(odID) != fractionLeft.end()) {
230  (*next)->vehicleNumber += fractionLeft[odID];
231  fractionLeft[odID] = 0;
232  }
233  // get the new departures (into tmp)
234  const size_t oldSize = vehicles.size();
235  const SUMOReal fraction = computeDeparts(*next, vehName, vehicles, uniform, differSourceSink, prefix);
236  if (oldSize != vehicles.size()) {
237  changed = true;
238  }
239  if (fraction != 0) {
240  fractionLeft[odID] = fraction;
241  }
242  ++next;
243  }
244  if (changed) {
245  sort(vehicles.begin(), vehicles.end(), descending_departure_comperator());
246  }
247  for (std::vector<ODVehicle>::reverse_iterator i = vehicles.rbegin(); i != vehicles.rend() && (*i).depart == t; ++i) {
248  if (t >= begin) {
249  myNoWritten++;
251  dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to);
252  writeDefaultAttrs(dev, noVtype, i->cell);
253  dev.closeTag();
254  }
255  }
256  while (vehicles.size() != 0 && vehicles.back().depart == t) {
257  vehicles.pop_back();
258  }
259  if (!vehicles.empty()) {
260  t = vehicles.back().depart;
261  }
262  if (next != myContainer.end() && (t > (*next)->begin || vehicles.empty())) {
263  t = (*next)->begin;
264  }
265  if (next == myContainer.end() && vehicles.empty()) {
266  break;
267  }
268  }
269 }
270 
271 
272 void
273 ODMatrix::writeFlows(const SUMOTime begin, const SUMOTime end,
274  OutputDevice& dev, bool noVtype,
275  const std::string& prefix) {
276  if (myContainer.size() == 0) {
277  return;
278  }
279  size_t flowName = 0;
280  sortByBeginTime();
281  // recheck begin time
282  for (std::vector<ODCell*>::const_iterator i = myContainer.begin(); i != myContainer.end(); ++i) {
283  const ODCell* const c = *i;
284  if (c->end > begin && c->begin < end) {
285  dev.openTag(SUMO_TAG_FLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++));
288  writeDefaultAttrs(dev, noVtype, *i);
289  dev.closeTag();
290  }
291  }
292 }
293 
294 
295 std::string
297  std::string line;
298  do {
299  line = lr.readLine();
300  if (line[0] != '*') {
301  return StringUtils::prune(line);
302  }
303  } while (lr.good() && lr.hasMore());
304  throw ProcessError();
305 }
306 
307 
308 SUMOTime
309 ODMatrix::parseSingleTime(const std::string& time) {
310  if (time.find('.') == std::string::npos) {
311  throw OutOfBoundsException();
312  }
313  std::string hours = time.substr(0, time.find('.'));
314  std::string minutes = time.substr(time.find('.') + 1);
315  return TIME2STEPS(TplConvert::_2int(hours.c_str()) * 3600 + TplConvert::_2int(minutes.c_str()) * 60);
316 }
317 
318 
319 std::pair<SUMOTime, SUMOTime>
321  std::string line = getNextNonCommentLine(lr);
322  try {
324  SUMOTime begin = parseSingleTime(st.next());
325  SUMOTime end = parseSingleTime(st.next());
326  if (begin >= end) {
327  throw ProcessError("Begin time is larger than end time.");
328  }
329  return std::make_pair(begin, end);
330  } catch (OutOfBoundsException&) {
331  throw ProcessError("Broken period definition '" + line + "'.");
332  } catch (NumberFormatException&) {
333  throw ProcessError("Broken period definition '" + line + "'.");
334  }
335 }
336 
337 SUMOReal
339  std::string line = getNextNonCommentLine(lr);
340  SUMOReal factor = -1;
341  try {
342  factor = TplConvert::_2SUMOReal(line.c_str()) * scale;
343  } catch (NumberFormatException&) {
344  throw ProcessError("Broken factor: '" + line + "'.");
345  }
346  return factor;
347 }
348 
349 void
351  std::string vehType, bool matrixHasVehType) {
352  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as VMR");
353  // parse first defs
354  std::string line;
355  if (matrixHasVehType) {
356  line = getNextNonCommentLine(lr);
357  if (vehType == "") {
358  vehType = StringUtils::prune(line);
359  }
360  }
361 
362  // parse time
363  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
364  SUMOTime begin = times.first;
365  SUMOTime end = times.second;
366 
367  // factor
368  SUMOReal factor = readFactor(lr, scale);
369 
370  // districts
371  line = getNextNonCommentLine(lr);
372  int districtNo = TplConvert::_2int(StringUtils::prune(line).c_str());
373  // parse district names (normally ints)
374  std::vector<std::string> names;
375  do {
376  line = getNextNonCommentLine(lr);
378  while (st2.hasNext()) {
379  names.push_back(st2.next());
380  }
381  } while ((int) names.size() != districtNo);
382 
383  // parse the cells
384  for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) {
385  std::vector<std::string>::iterator di = names.begin();
386  //
387  do {
388  line = getNextNonCommentLine(lr);
389  if (line.length() == 0) {
390  continue;
391  }
392  try {
394  while (st2.hasNext()) {
395  assert(di != names.end());
396  SUMOReal vehNumber = TplConvert::_2SUMOReal(st2.next().c_str()) * factor;
397  if (vehNumber != 0) {
398  add(vehNumber, begin, end, *si, *di, vehType);
399  }
400  if (di == names.end()) {
401  throw ProcessError("More entries than districts found.");
402  }
403  ++di;
404  }
405  } catch (NumberFormatException&) {
406  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
407  }
408  if (!lr.hasMore()) {
409  break;
410  }
411  } while (di != names.end());
412  }
414 }
415 
416 
417 void
419  std::string vehType, bool matrixHasVehType) {
420  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR");
421  // parse first defs
422  std::string line;
423  if (matrixHasVehType) {
424  line = getNextNonCommentLine(lr);
425  int type = TplConvert::_2int(StringUtils::prune(line).c_str());
426  if (vehType == "") {
427  vehType = toString(type);
428  }
429  }
430 
431  // parse time
432  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
433  SUMOTime begin = times.first;
434  SUMOTime end = times.second;
435 
436  // factor
437  SUMOReal factor = readFactor(lr, scale);
438 
439  // parse the cells
440  while (lr.hasMore()) {
441  line = getNextNonCommentLine(lr);
442  if (line.length() == 0) {
443  continue;
444  }
446  if (st2.size() == 0) {
447  continue;
448  }
449  try {
450  std::string sourceD = st2.next();
451  std::string destD = st2.next();
452  SUMOReal vehNumber = TplConvert::_2SUMOReal(st2.next().c_str()) * factor;
453  if (vehNumber != 0) {
454  add(vehNumber, begin, end, sourceD, destD, vehType);
455  }
456  } catch (OutOfBoundsException&) {
457  throw ProcessError("Missing at least one information in line '" + line + "'.");
458  } catch (NumberFormatException&) {
459  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
460  }
461  }
463 }
464 
465 
466 
467 SUMOReal
469  return myNoLoaded;
470 }
471 
472 
473 SUMOReal
475  return myNoWritten;
476 }
477 
478 
479 SUMOReal
481  return myNoDiscarded;
482 }
483 
484 
485 void
486 ODMatrix::applyCurve(const Distribution_Points& ps, ODCell* cell, std::vector<ODCell*>& newCells) {
487  for (size_t i = 0; i < ps.getAreaNo(); ++i) {
488  ODCell* ncell = new ODCell();
489  ncell->begin = TIME2STEPS(ps.getAreaBegin(i));
490  ncell->end = TIME2STEPS(ps.getAreaEnd(i));
491  ncell->origin = cell->origin;
492  ncell->destination = cell->destination;
493  ncell->vehicleType = cell->vehicleType;
494  ncell->vehicleNumber = cell->vehicleNumber * ps.getAreaPerc(i);
495  newCells.push_back(ncell);
496  }
497 }
498 
499 
500 void
502  std::vector<ODCell*> oldCells = myContainer;
503  myContainer.clear();
504  for (std::vector<ODCell*>::iterator i = oldCells.begin(); i != oldCells.end(); ++i) {
505  std::vector<ODCell*> newCells;
506  applyCurve(ps, *i, newCells);
507  copy(newCells.begin(), newCells.end(), back_inserter(myContainer));
508  delete *i;
509  }
510 }
511 
512 
513 void
515  std::vector<std::string> files = oc.getStringVector("od-matrix-files");
516  for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
517  LineReader lr(*i);
518  if (!lr.good()) {
519  throw ProcessError("Could not open '" + (*i) + "'.");
520  }
521  std::string type = lr.readLine();
522  // get the type only
523  if (type.find(';') != std::string::npos) {
524  type = type.substr(0, type.find(';'));
525  }
526  // parse type-dependant
527  if (type.length() > 1 && type[1] == 'V') {
528  // process ptv's 'V'-matrices
529  if (type.find('N') != std::string::npos) {
530  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
531  }
532  readV(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
533  } else if (type.length() > 1 && type[1] == 'O') {
534  // process ptv's 'O'-matrices
535  if (type.find('N') != std::string::npos) {
536  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
537  }
538  readO(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
539  } else {
540  throw ProcessError("'" + *i + "' uses an unknown matrix type '" + type + "'.");
541  }
542  }
543  std::vector<std::string> amitranFiles = oc.getStringVector("od-amitran-files");
544  for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) {
545  if (!FileHelpers::isReadable(*i)) {
546  throw ProcessError("Could not access matrix file '" + *i + "' to load.");
547  }
548  PROGRESS_BEGIN_MESSAGE("Loading matrix in Amitran format from '" + *i + "'");
549  ODAmitranHandler handler(*this, *i);
550  if (!XMLSubSys::runParser(handler, *i)) {
552  } else {
554  }
555  }
556 }
557 
558 
559 void
561  std::vector<std::string> routeFiles = oc.getStringVector("route-files");
562  for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) {
563  if (!FileHelpers::isReadable(*i)) {
564  throw ProcessError("Could not access route file '" + *i + "' to load.");
565  }
566  PROGRESS_BEGIN_MESSAGE("Loading routes and trips from '" + *i + "'");
567  if (!XMLSubSys::runParser(handler, *i)) {
569  } else {
571  }
572  }
573 }
574 
575 
577 ODMatrix::parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours) {
578  bool interpolating = !timelineDayInHours;
579  PositionVector points;
580  SUMOReal prob = 0;
581  if (timelineDayInHours) {
582  if (def.size() != 24) {
583  throw ProcessError("Assuming 24 entries for a day timeline, but got " + toString(def.size()) + ".");
584  }
585  for (int chour = 0; chour < 24; ++chour) {
586  prob = TplConvert::_2SUMOReal(def[chour].c_str());
587  points.push_back(Position((SUMOReal)(chour * 3600), prob));
588  }
589  points.push_back(Position((SUMOReal)(24 * 3600), prob));
590  } else {
591  size_t i = 0;
592  while (i < def.size()) {
593  StringTokenizer st2(def[i++], ":");
594  if (st2.size() != 2) {
595  throw ProcessError("Broken time line definition: missing a value in '" + def[i - 1] + "'.");
596  }
597  int time = TplConvert::_2int(st2.next().c_str());
598  prob = TplConvert::_2SUMOReal(st2.next().c_str());
599  points.push_back(Position((SUMOReal) time, prob));
600  }
601  }
602  return Distribution_Points("N/A", points, interpolating);
603 }
604 
605 
606 void
608  std::sort(myContainer.begin(), myContainer.end(), cell_by_begin_comparator());
609 }
610 
611 
612 /****************************************************************************/
SUMOReal getNoLoaded() const
Returns the number of loaded vehicles.
Definition: ODMatrix.cpp:468
SUMOReal myNoLoaded
Number of loaded vehicles.
Definition: ODMatrix.h:350
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:174
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
Used for sorting the cells by the begin time they describe.
Definition: ODMatrix.h:363
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) ...
long long int SUMOTime
Definition: SUMOTime.h:43
std::string next()
SUMOReal computeDeparts(ODCell *cell, size_t &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:135
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:58
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
Definition: LineReader.cpp:80
static SUMOReal _2SUMOReal(const E *const data)
Definition: TplConvert.h:242
static const int WHITECHARS
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:58
SUMOReal getAreaPerc(size_t index) const
SUMOReal myNoWritten
Number of written vehicles.
Definition: ODMatrix.h:353
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:347
SUMOReal getAreaEnd(size_t index) const
An internal representation of a single vehicle.
Definition: ODMatrix.h:252
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
void add(SUMOReal 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:75
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
#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:260
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:114
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:309
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
Definition: ODMatrix.cpp:514
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)
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:205
unsigned int sinkNumber() const
Returns the number of sinks.
Definition: ODDistrict.cpp:82
SUMOReal getNoDiscarded() const
Returns the number of discarded vehicles.
Definition: ODMatrix.cpp:480
~ODMatrix()
Destructor.
Definition: ODMatrix.cpp:66
A single O/D-matrix cell.
Definition: ODCell.h:58
void readV(LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
Definition: ODMatrix.cpp:350
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.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
void readO(LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
Definition: ODMatrix.cpp:418
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
Definition: ODMatrix.h:258
void loadRoutes(OptionsCont &oc, SUMOSAXHandler &handler)
read SUMO routes
Definition: ODMatrix.cpp:560
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
A container for districts.
SUMOReal getAreaBegin(size_t index) const
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
unsigned int sourceNumber() const
Returns the number of sources.
Definition: ODDistrict.cpp:88
SUMOReal getNoWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:474
SUMOReal vehicleNumber
The number of vehicles.
Definition: ODCell.h:60
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:399
std::map< SUMOTime, std::vector< std::string > > departures
mapping of departure times to departing vehicles, if already fixed
Definition: ODCell.h:81
size_t size() const
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:344
SUMOReal myNoDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:356
void sortByBeginTime()
Definition: ODMatrix.cpp:607
std::vector< ODCell * > myContainer
The loaded cells.
Definition: ODMatrix.h:341
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
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:229
void writeFlows(const SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool noVtype, const std::string &prefix)
Writes the flows stored in the matrix.
Definition: ODMatrix.cpp:273
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
SUMOReal readFactor(LineReader &lr, SUMOReal scale)
Definition: ODMatrix.cpp:338
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:183
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:320
static int _2int(const E *const data)
Definition: TplConvert.h:114
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:296
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:256
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
Definition: StringUtils.cpp:56
A storage for options typed value containers)
Definition: OptionsCont.h:108
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:501
std::string vehicleType
Name of the vehicle type.
Definition: ODCell.h:75
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.
#define SUMOReal
Definition: config.h:213
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:64
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:203
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:262
ODMatrix(const ODDistrictCont &dc)
Constructor.
Definition: ODMatrix.cpp:62
std::string id
The id of the vehicle.
Definition: ODMatrix.h:254
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:577
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.