SUMO - Simulation of Urban MObility
ODMatrix.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // An O/D (origin/destination) matrix
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2006-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef ODMatrix_h
23 #define ODMatrix_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <iostream>
36 #include <sstream>
37 #include <fstream>
38 #include <vector>
39 #include <cstdlib>
40 #include <ctime>
41 #include <algorithm>
42 #include <set>
43 #include <string>
44 #include <utils/common/SUMOTime.h>
45 #include "ODCell.h"
46 #include "ODDistrictCont.h"
49 #include <utils/common/SUMOTime.h>
50 
51 // ===========================================================================
52 // class declarations
53 // ===========================================================================
54 class OutputDevice;
55 class SUMOSAXHandler;
56 
57 
58 // ===========================================================================
59 // class definitions
60 // ===========================================================================
76 class ODMatrix {
77 public:
82  ODMatrix(const ODDistrictCont& dc);
83 
84 
86  ~ODMatrix();
87 
88 
111  bool add(double vehicleNumber, SUMOTime begin,
112  SUMOTime end, const std::string& origin, const std::string& destination,
113  const std::string& vehicleType);
114 
126  bool add(const std::string& id, const SUMOTime depart,
127  const std::pair<const std::string, const std::string>& od,
128  const std::string& vehicleType);
129 
137  void writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
138  const ODCell* const cell);
139 
165  void write(SUMOTime begin, const SUMOTime end,
166  OutputDevice& dev, const bool uniform,
167  const bool differSourceSink, const bool noVtype,
168  const std::string& prefix, const bool stepLog,
169  bool pedestrians, bool persontrips);
170 
171 
181  void writeFlows(const SUMOTime begin, const SUMOTime end,
182  OutputDevice& dev, const bool noVtype,
183  const std::string& prefix,
184  bool asProbability = false);
185 
186 
193  double getNumLoaded() const;
194 
195 
202  double getNumWritten() const;
203 
204 
211  double getNumDiscarded() const;
212 
213 
217  void applyCurve(const Distribution_Points& ps);
218 
219 
223  void readO(LineReader& lr, double scale,
224  std::string vehType, bool matrixHasVehType);
225 
229  void readV(LineReader& lr, double scale,
230  std::string vehType, bool matrixHasVehType);
231 
235  void loadMatrix(OptionsCont& oc);
236 
240  void loadRoutes(OptionsCont& oc, SUMOSAXHandler& handler);
241 
245  Distribution_Points parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours);
246 
247  const std::vector<ODCell*>& getCells() {
248  return myContainer;
249  }
250 
251  void sortByBeginTime();
252 
253 protected:
258  struct ODVehicle {
260  std::string id;
266  std::string from;
268  std::string to;
269 
270  };
271 
272 
298  double computeDeparts(ODCell* cell,
299  int& vehName, std::vector<ODVehicle>& into,
300  const bool uniform, const bool differSourceSink,
301  const std::string& prefix);
302 
303 
319  void applyCurve(const Distribution_Points& ps, ODCell* cell,
320  std::vector<ODCell*>& newCells);
321 
322 
323 private:
327  std::string getNextNonCommentLine(LineReader& lr);
328 
332  SUMOTime parseSingleTime(const std::string& time);
333 
337  std::pair<SUMOTime, SUMOTime> readTime(LineReader& lr);
338 
342  double readFactor(LineReader& lr, double scale);
343 
344 
345 private:
347  std::vector<ODCell*> myContainer;
348 
350  std::map<const std::pair<const std::string, const std::string>, std::vector<ODCell*> > myShortCut;
351 
354 
356  std::set<std::string> myMissingDistricts;
357 
359  double myNumLoaded;
360 
362  double myNumWritten;
363 
366 
367 
373  public:
376 
377 
388  int operator()(ODCell* p1, ODCell* p2) const {
389  if (p1->begin == p2->begin) {
390  if (p1->origin == p2->origin) {
391  return p1->destination < p2->destination;
392  }
393  return p1->origin < p2->origin;
394  }
395  return p1->begin < p2->begin;
396  }
397 
398  };
399 
400 
409  public:
412 
413 
422  bool operator()(const ODVehicle& p1, const ODVehicle& p2) const {
423  if (p1.depart == p2.depart) {
424  return p1.id > p2.id;
425  }
426  return p1.depart > p2.depart;
427  }
428 
429  };
430 
431 private:
433  ODMatrix(const ODMatrix& s);
434 
436  ODMatrix& operator=(const ODMatrix& s);
437 
438 };
439 
440 
441 #endif
442 
443 /****************************************************************************/
444 
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, bool pedestrians, bool persontrips)
Writes the vehicles stored in the matrix assigning the sources and sinks.
Definition: ODMatrix.cpp:217
void writeDefaultAttrs(OutputDevice &dev, const bool noVtype, const ODCell *const cell)
Helper function for flow and trip output writing the depart and arrival attributes.
Definition: ODMatrix.cpp:188
Used for sorting the cells by the begin time they describe.
Definition: ODMatrix.h:372
const std::vector< ODCell * > & getCells()
Definition: ODMatrix.h:247
double getNumWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:520
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:58
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:353
An internal representation of a single vehicle.
Definition: ODMatrix.h:258
double getNumDiscarded() const
Returns the number of discarded vehicles.
Definition: ODMatrix.cpp:526
SAX-handler base for SUMO-files.
std::string from
The edge the vehicles shall start at.
Definition: ODMatrix.h:266
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:355
ODMatrix & operator=(const ODMatrix &s)
invalid assignment operator
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
Definition: ODMatrix.cpp:561
double computeDeparts(ODCell *cell, int &vehName, std::vector< ODVehicle > &into, const bool uniform, const bool differSourceSink, const std::string &prefix)
Computes the vehicle departs stored in the given cell and saves them in "into".
Definition: ODMatrix.cpp:149
~ODMatrix()
Destructor.
Definition: ODMatrix.cpp:62
double myNumDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:365
A single O/D-matrix cell.
Definition: ODCell.h:58
double myNumWritten
Number of written vehicles.
Definition: ODMatrix.h:362
std::string origin
Name of the origin district.
Definition: ODCell.h:69
cell_by_begin_comparator()
constructor
Definition: ODMatrix.h:375
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:76
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
Definition: ODMatrix.h:264
void loadRoutes(OptionsCont &oc, SUMOSAXHandler &handler)
read SUMO routes
Definition: ODMatrix.cpp:607
A container for districts.
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:408
double readFactor(LineReader &lr, double scale)
Definition: ODMatrix.cpp:384
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:350
void sortByBeginTime()
Definition: ODMatrix.cpp:649
std::vector< ODCell * > myContainer
The loaded cells.
Definition: ODMatrix.h:347
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:63
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:366
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:343
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:262
bool add(double vehicleNumber, SUMOTime begin, SUMOTime end, const std::string &origin, const std::string &destination, const std::string &vehicleType)
Builds a single cell from the given values, verifying them.
Definition: ODMatrix.cpp:71
int operator()(ODCell *p1, ODCell *p2) const
Comparing operator.
Definition: ODMatrix.h:388
A storage for options typed value containers)
Definition: OptionsCont.h:99
double getNumLoaded() const
Returns the number of loaded vehicles.
Definition: ODMatrix.cpp:514
void applyCurve(const Distribution_Points &ps)
Splits the stored cells dividing them on the given time line.
Definition: ODMatrix.cpp:548
void readV(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
Definition: ODMatrix.cpp:396
void readO(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
Definition: ODMatrix.cpp:464
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
long long int SUMOTime
Definition: TraCIDefs.h:52
std::string to
The edge the vehicles shall end at.
Definition: ODMatrix.h:268
ODMatrix(const ODDistrictCont &dc)
Constructor.
Definition: ODMatrix.cpp:58
void writeFlows(const SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool noVtype, const std::string &prefix, bool asProbability=false)
Writes the flows stored in the matrix.
Definition: ODMatrix.cpp:306
std::set< std::string > myMissingDistricts
The missing districts already warned about.
Definition: ODMatrix.h:356
std::string id
The id of the vehicle.
Definition: ODMatrix.h:260
bool operator()(const ODVehicle &p1, const ODVehicle &p2) const
Comparing operator.
Definition: ODMatrix.h:422
double myNumLoaded
Number of loaded vehicles.
Definition: ODMatrix.h:359
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:624