SUMO - Simulation of Urban MObility
ODMatrix.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2006-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // An O/D (origin/destination) matrix
20 /****************************************************************************/
21 #ifndef ODMatrix_h
22 #define ODMatrix_h
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 <sstream>
36 #include <fstream>
37 #include <vector>
38 #include <cstdlib>
39 #include <ctime>
40 #include <algorithm>
41 #include <set>
42 #include <string>
43 #include <utils/common/SUMOTime.h>
44 #include "ODCell.h"
45 #include "ODDistrictCont.h"
48 #include <utils/common/SUMOTime.h>
49 
50 // ===========================================================================
51 // class declarations
52 // ===========================================================================
53 class OutputDevice;
54 class SUMOSAXHandler;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
75 class ODMatrix {
76 public:
81  ODMatrix(const ODDistrictCont& dc);
82 
83 
85  ~ODMatrix();
86 
87 
110  bool add(double vehicleNumber, SUMOTime begin,
111  SUMOTime end, const std::string& origin, const std::string& destination,
112  const std::string& vehicleType);
113 
125  bool add(const std::string& id, const SUMOTime depart,
126  const std::pair<const std::string, const std::string>& od,
127  const std::string& vehicleType);
128 
136  void writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
137  const ODCell* const cell);
138 
164  void write(SUMOTime begin, const SUMOTime end,
165  OutputDevice& dev, const bool uniform,
166  const bool differSourceSink, const bool noVtype,
167  const std::string& prefix, const bool stepLog,
168  bool pedestrians, bool persontrips);
169 
170 
180  void writeFlows(const SUMOTime begin, const SUMOTime end,
181  OutputDevice& dev, const bool noVtype,
182  const std::string& prefix,
183  bool asProbability = false);
184 
185 
192  double getNumLoaded() const;
193 
194 
201  double getNumWritten() const;
202 
203 
210  double getNumDiscarded() const;
211 
212 
216  void applyCurve(const Distribution_Points& ps);
217 
218 
222  void readO(LineReader& lr, double scale,
223  std::string vehType, bool matrixHasVehType);
224 
228  void readV(LineReader& lr, double scale,
229  std::string vehType, bool matrixHasVehType);
230 
234  void loadMatrix(OptionsCont& oc);
235 
239  void loadRoutes(OptionsCont& oc, SUMOSAXHandler& handler);
240 
244  Distribution_Points parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours);
245 
246  const std::vector<ODCell*>& getCells() {
247  return myContainer;
248  }
249 
250  void sortByBeginTime();
251 
252 protected:
257  struct ODVehicle {
259  std::string id;
265  std::string from;
267  std::string to;
268 
269  };
270 
271 
297  double computeDeparts(ODCell* cell,
298  int& vehName, std::vector<ODVehicle>& into,
299  const bool uniform, const bool differSourceSink,
300  const std::string& prefix);
301 
302 
318  void applyCurve(const Distribution_Points& ps, ODCell* cell,
319  std::vector<ODCell*>& newCells);
320 
321 
322 private:
326  std::string getNextNonCommentLine(LineReader& lr);
327 
331  SUMOTime parseSingleTime(const std::string& time);
332 
336  std::pair<SUMOTime, SUMOTime> readTime(LineReader& lr);
337 
341  double readFactor(LineReader& lr, double scale);
342 
343 
344 private:
346  std::vector<ODCell*> myContainer;
347 
349  std::map<const std::pair<const std::string, const std::string>, std::vector<ODCell*> > myShortCut;
350 
353 
355  std::set<std::string> myMissingDistricts;
356 
358  double myNumLoaded;
359 
361  double myNumWritten;
362 
365 
366 
372  public:
375 
376 
387  int operator()(ODCell* p1, ODCell* p2) const {
388  if (p1->begin == p2->begin) {
389  if (p1->origin == p2->origin) {
390  return p1->destination < p2->destination;
391  }
392  return p1->origin < p2->origin;
393  }
394  return p1->begin < p2->begin;
395  }
396 
397  };
398 
399 
408  public:
411 
412 
421  bool operator()(const ODVehicle& p1, const ODVehicle& p2) const {
422  if (p1.depart == p2.depart) {
423  return p1.id > p2.id;
424  }
425  return p1.depart > p2.depart;
426  }
427 
428  };
429 
430 private:
432  ODMatrix(const ODMatrix& s);
433 
435  ODMatrix& operator=(const ODMatrix& s);
436 
437 };
438 
439 
440 #endif
441 
442 /****************************************************************************/
443 
int operator()(ODCell *p1, ODCell *p2) const
Comparing operator.
Definition: ODMatrix.h:387
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:216
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:187
Used for sorting the cells by the begin time they describe.
Definition: ODMatrix.h:371
const std::vector< ODCell * > & getCells()
Definition: ODMatrix.h:246
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:57
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:352
An internal representation of a single vehicle.
Definition: ODMatrix.h:257
SAX-handler base for SUMO-files.
std::string from
The edge the vehicles shall start at.
Definition: ODMatrix.h:265
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:354
ODMatrix & operator=(const ODMatrix &s)
invalid assignment operator
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
Definition: ODMatrix.cpp:560
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:148
~ODMatrix()
Destructor.
Definition: ODMatrix.cpp:61
double myNumDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:364
A single O/D-matrix cell.
Definition: ODCell.h:57
double myNumWritten
Number of written vehicles.
Definition: ODMatrix.h:361
std::string origin
Name of the origin district.
Definition: ODCell.h:68
cell_by_begin_comparator()
constructor
Definition: ODMatrix.h:374
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:75
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
Definition: ODMatrix.h:263
void loadRoutes(OptionsCont &oc, SUMOSAXHandler &handler)
read SUMO routes
Definition: ODMatrix.cpp:606
A container for districts.
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:407
double readFactor(LineReader &lr, double scale)
Definition: ODMatrix.cpp:383
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:349
void sortByBeginTime()
Definition: ODMatrix.cpp:648
std::vector< ODCell * > myContainer
The loaded cells.
Definition: ODMatrix.h:346
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:62
double getNumLoaded() const
Returns the number of loaded vehicles.
Definition: ODMatrix.cpp:513
double getNumWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:519
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:365
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:342
bool operator()(const ODVehicle &p1, const ODVehicle &p2) const
Comparing operator.
Definition: ODMatrix.h:421
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:261
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:70
A storage for options typed value containers)
Definition: OptionsCont.h:98
void applyCurve(const Distribution_Points &ps)
Splits the stored cells dividing them on the given time line.
Definition: ODMatrix.cpp:547
void readV(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
Definition: ODMatrix.cpp:395
void readO(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
Definition: ODMatrix.cpp:463
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
std::string destination
Name of the destination district.
Definition: ODCell.h:71
long long int SUMOTime
Definition: TraCIDefs.h:51
double getNumDiscarded() const
Returns the number of discarded vehicles.
Definition: ODMatrix.cpp:525
std::string to
The edge the vehicles shall end at.
Definition: ODMatrix.h:267
ODMatrix(const ODDistrictCont &dc)
Constructor.
Definition: ODMatrix.cpp:57
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:305
std::set< std::string > myMissingDistricts
The missing districts already warned about.
Definition: ODMatrix.h:355
std::string id
The id of the vehicle.
Definition: ODMatrix.h:259
double myNumLoaded
Number of loaded vehicles.
Definition: ODMatrix.h:358
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:623