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