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