SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  myNoWritten++;
249  dev.writeAttr(SUMO_ATTR_FROM, (*i).from).writeAttr(SUMO_ATTR_TO, (*i).to);
250  writeDefaultAttrs(dev, noVtype, i->cell);
251  dev.closeTag();
252  }
253  while (vehicles.size() != 0 && vehicles.back().depart == t) {
254  vehicles.pop_back();
255  }
256  if (!vehicles.empty()) {
257  t = vehicles.back().depart;
258  }
259  if (next != myContainer.end() && (t > (*next)->begin || vehicles.empty())) {
260  t = (*next)->begin;
261  }
262  if (next == myContainer.end() && vehicles.empty()) {
263  break;
264  }
265  }
266 }
267 
268 
269 void
270 ODMatrix::writeFlows(const SUMOTime begin, const SUMOTime end,
271  OutputDevice& dev, bool noVtype,
272  const std::string& prefix) {
273  if (myContainer.size() == 0) {
274  return;
275  }
276  size_t flowName = 0;
277  sort(myContainer.begin(), myContainer.end(), cell_by_begin_sorter());
278  // recheck begin time
279  for (std::vector<ODCell*>::const_iterator i = myContainer.begin(); i != myContainer.end(); ++i) {
280  const ODCell* const c = *i;
281  if (c->end > begin && c->begin < end) {
282  dev.openTag(SUMO_TAG_FLOW).writeAttr(SUMO_ATTR_ID, prefix + toString(flowName++));
285  writeDefaultAttrs(dev, noVtype, *i);
286  dev.closeTag();
287  }
288  }
289 }
290 
291 
292 std::string
294  std::string line;
295  do {
296  line = lr.readLine();
297  if (line[0] != '*') {
298  return StringUtils::prune(line);
299  }
300  } while (lr.good() && lr.hasMore());
301  throw ProcessError();
302 }
303 
304 
305 SUMOTime
306 ODMatrix::parseSingleTime(const std::string& time) {
307  if (time.find('.') == std::string::npos) {
308  throw OutOfBoundsException();
309  }
310  std::string hours = time.substr(0, time.find('.'));
311  std::string minutes = time.substr(time.find('.') + 1);
312  return TIME2STEPS(TplConvert::_2int(hours.c_str()) * 3600 + TplConvert::_2int(minutes.c_str()) * 60);
313 }
314 
315 
316 std::pair<SUMOTime, SUMOTime>
318  std::string line = getNextNonCommentLine(lr);
319  try {
321  SUMOTime begin = parseSingleTime(st.next());
322  SUMOTime end = parseSingleTime(st.next());
323  if (begin >= end) {
324  throw ProcessError("Begin time is larger than end time.");
325  }
326  return std::make_pair(begin, end);
327  } catch (OutOfBoundsException&) {
328  throw ProcessError("Broken period definition '" + line + "'.");
329  } catch (NumberFormatException&) {
330  throw ProcessError("Broken period definition '" + line + "'.");
331  }
332 }
333 
334 SUMOReal
336  std::string line = getNextNonCommentLine(lr);
337  SUMOReal factor = -1;
338  try {
339  factor = TplConvert::_2SUMOReal(line.c_str()) * scale;
340  } catch (NumberFormatException&) {
341  throw ProcessError("Broken factor: '" + line + "'.");
342  }
343  return factor;
344 }
345 
346 void
348  std::string vehType, bool matrixHasVehType) {
349  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as VMR");
350  // parse first defs
351  std::string line;
352  if (matrixHasVehType) {
353  line = getNextNonCommentLine(lr);
354  if (vehType == "") {
355  vehType = StringUtils::prune(line);
356  }
357  }
358 
359  // parse time
360  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
361  SUMOTime begin = times.first;
362  SUMOTime end = times.second;
363 
364  // factor
365  SUMOReal factor = readFactor(lr, scale);
366 
367  // districts
368  line = getNextNonCommentLine(lr);
369  int districtNo = TplConvert::_2int(StringUtils::prune(line).c_str());
370  // parse district names (normally ints)
371  std::vector<std::string> names;
372  do {
373  line = getNextNonCommentLine(lr);
375  while (st2.hasNext()) {
376  names.push_back(st2.next());
377  }
378  } while ((int) names.size() != districtNo);
379 
380  // parse the cells
381  for (std::vector<std::string>::iterator si = names.begin(); si != names.end(); ++si) {
382  std::vector<std::string>::iterator di = names.begin();
383  //
384  do {
385  line = getNextNonCommentLine(lr);
386  if (line.length() == 0) {
387  continue;
388  }
389  try {
391  while (st2.hasNext()) {
392  assert(di != names.end());
393  SUMOReal vehNumber = TplConvert::_2SUMOReal(st2.next().c_str()) * factor;
394  if (vehNumber != 0) {
395  add(vehNumber, begin, end, *si, *di, vehType);
396  }
397  if (di == names.end()) {
398  throw ProcessError("More entries than districts found.");
399  }
400  ++di;
401  }
402  } catch (NumberFormatException&) {
403  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
404  }
405  if (!lr.hasMore()) {
406  break;
407  }
408  } while (di != names.end());
409  }
411 }
412 
413 
414 void
416  std::string vehType, bool matrixHasVehType) {
417  PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR");
418  // parse first defs
419  std::string line;
420  if (matrixHasVehType) {
421  line = getNextNonCommentLine(lr);
422  int type = TplConvert::_2int(StringUtils::prune(line).c_str());
423  if (vehType == "") {
424  vehType = toString(type);
425  }
426  }
427 
428  // parse time
429  std::pair<SUMOTime, SUMOTime> times = readTime(lr);
430  SUMOTime begin = times.first;
431  SUMOTime end = times.second;
432 
433  // factor
434  SUMOReal factor = readFactor(lr, scale);
435 
436  // parse the cells
437  while (lr.hasMore()) {
438  line = getNextNonCommentLine(lr);
439  if (line.length() == 0) {
440  continue;
441  }
443  if (st2.size() == 0) {
444  continue;
445  }
446  try {
447  std::string sourceD = st2.next();
448  std::string destD = st2.next();
449  SUMOReal vehNumber = TplConvert::_2SUMOReal(st2.next().c_str()) * factor;
450  if (vehNumber != 0) {
451  add(vehNumber, begin, end, sourceD, destD, vehType);
452  }
453  } catch (OutOfBoundsException&) {
454  throw ProcessError("Missing at least one information in line '" + line + "'.");
455  } catch (NumberFormatException&) {
456  throw ProcessError("Not numeric vehicle number in line '" + line + "'.");
457  }
458  }
460 }
461 
462 
463 
464 SUMOReal
466  return myNoLoaded;
467 }
468 
469 
470 SUMOReal
472  return myNoWritten;
473 }
474 
475 
476 SUMOReal
478  return myNoDiscarded;
479 }
480 
481 
482 void
483 ODMatrix::applyCurve(const Distribution_Points& ps, ODCell* cell, std::vector<ODCell*>& newCells) {
484  for (size_t i = 0; i < ps.getAreaNo(); ++i) {
485  ODCell* ncell = new ODCell();
486  ncell->begin = TIME2STEPS(ps.getAreaBegin(i));
487  ncell->end = TIME2STEPS(ps.getAreaEnd(i));
488  ncell->origin = cell->origin;
489  ncell->destination = cell->destination;
490  ncell->vehicleType = cell->vehicleType;
491  ncell->vehicleNumber = cell->vehicleNumber * ps.getAreaPerc(i);
492  newCells.push_back(ncell);
493  }
494 }
495 
496 
497 void
499  std::vector<ODCell*> oldCells = myContainer;
500  myContainer.clear();
501  for (std::vector<ODCell*>::iterator i = oldCells.begin(); i != oldCells.end(); ++i) {
502  std::vector<ODCell*> newCells;
503  applyCurve(ps, *i, newCells);
504  copy(newCells.begin(), newCells.end(), back_inserter(myContainer));
505  delete *i;
506  }
507 }
508 
509 
510 void
512  std::vector<std::string> files = oc.getStringVector("od-matrix-files");
513  for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
514  LineReader lr(*i);
515  if (!lr.good()) {
516  throw ProcessError("Could not open '" + (*i) + "'.");
517  }
518  std::string type = lr.readLine();
519  // get the type only
520  if (type.find(';') != std::string::npos) {
521  type = type.substr(0, type.find(';'));
522  }
523  // parse type-dependant
524  if (type.length() > 1 && type[1] == 'V') {
525  // process ptv's 'V'-matrices
526  if (type.find('N') != std::string::npos) {
527  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
528  }
529  readV(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
530  } else if (type.length() > 1 && type[1] == 'O') {
531  // process ptv's 'O'-matrices
532  if (type.find('N') != std::string::npos) {
533  throw ProcessError("'" + *i + "' does not contain the needed information about the time described.");
534  }
535  readO(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos);
536  } else {
537  throw ProcessError("'" + *i + "' uses an unknown matrix type '" + type + "'.");
538  }
539  }
540  std::vector<std::string> amitranFiles = oc.getStringVector("od-amitran-files");
541  for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) {
542  if (!FileHelpers::isReadable(*i)) {
543  throw ProcessError("Could not access matrix file '" + *i + "' to load.");
544  }
545  PROGRESS_BEGIN_MESSAGE("Loading matrix in Amitran format from '" + *i + "'");
546  ODAmitranHandler handler(*this, *i);
547  if (!XMLSubSys::runParser(handler, *i)) {
549  } else {
551  }
552  }
553 }
554 
555 
556 void
558  std::vector<std::string> routeFiles = oc.getStringVector("route-files");
559  for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) {
560  if (!FileHelpers::isReadable(*i)) {
561  throw ProcessError("Could not access route file '" + *i + "' to load.");
562  }
563  PROGRESS_BEGIN_MESSAGE("Loading routes and trips from '" + *i + "'");
564  if (!XMLSubSys::runParser(handler, *i)) {
566  } else {
568  }
569  }
570 }
571 
572 
574 ODMatrix::parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours) {
575  bool interpolating = !timelineDayInHours;
576  PositionVector points;
577  SUMOReal prob = 0;
578  if (timelineDayInHours) {
579  if (def.size() != 24) {
580  throw ProcessError("Assuming 24 entries for a day timeline, but got " + toString(def.size()) + ".");
581  }
582  for (int chour = 0; chour < 24; ++chour) {
583  prob = TplConvert::_2SUMOReal(def[chour].c_str());
584  points.push_back(Position((SUMOReal)(chour * 3600), prob));
585  }
586  points.push_back(Position((SUMOReal)(24 * 3600), prob));
587  } else {
588  size_t i = 0;
589  while (i < def.size()) {
590  StringTokenizer st2(def[i++], ":");
591  if (st2.size() != 2) {
592  throw ProcessError("Broken time line definition: missing a value in '" + def[i - 1] + "'.");
593  }
594  int time = TplConvert::_2int(st2.next().c_str());
595  prob = TplConvert::_2SUMOReal(st2.next().c_str());
596  points.push_back(Position((SUMOReal) time, prob));
597  }
598  }
599  return Distribution_Points("N/A", points, interpolating);
600 }
601 
602 /****************************************************************************/
SUMOReal getNoLoaded() const
Returns the number of loaded vehicles.
Definition: ODMatrix.cpp:465
SUMOReal myNoLoaded
Number of loaded vehicles.
Definition: ODMatrix.h:346
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:359
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 &quot;into&quot;.
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:349
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:343
SUMOReal getAreaEnd(size_t index) const
An internal representation of a single vehicle.
Definition: ODMatrix.h:251
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:74
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:259
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:306
#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:511
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:477
~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:347
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:415
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
Definition: ODMatrix.h:257
void loadRoutes(OptionsCont &oc, SUMOSAXHandler &handler)
read SUMO routes
Definition: ODMatrix.cpp:557
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:471
SUMOReal vehicleNumber
The number of vehicles.
Definition: ODCell.h:60
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:395
size_t size() const
SUMOReal myNoDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:352
std::vector< ODCell * > myContainer
The loaded cells.
Definition: ODMatrix.h:340
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:270
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
SUMOReal readFactor(LineReader &lr, SUMOReal scale)
Definition: ODMatrix.cpp:335
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:317
void push_back(const PositionVector &p)
Appends all positions from the given vector.
static int _2int(const E *const data)
Definition: TplConvert.h:114
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:293
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:255
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:498
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:215
#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:261
ODMatrix(const ODDistrictCont &dc)
Constructor.
Definition: ODMatrix.cpp:62
std::string id
The id of the vehicle.
Definition: ODMatrix.h:253
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:574
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.