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-2015 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 <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 
109  void add(SUMOReal vehicleNumber, SUMOTime begin,
110  SUMOTime end, const std::string& origin, const std::string& destination,
111  const std::string& vehicleType);
112 
124  void add(const std::string& id, const SUMOTime depart,
125  const std::string& origin, const std::string& destination,
126  const std::string& vehicleType);
127 
135  void writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
136  const ODCell* const cell);
137 
163  void write(SUMOTime begin, const SUMOTime end,
164  OutputDevice& dev, const bool uniform,
165  const bool differSourceSink, const bool noVtype,
166  const std::string& prefix, const bool stepLog);
167 
168 
177  void writeFlows(const SUMOTime begin, const SUMOTime end,
178  OutputDevice& dev, const bool noVtype,
179  const std::string& prefix);
180 
181 
188  SUMOReal getNoLoaded() const;
189 
190 
197  SUMOReal getNoWritten() const;
198 
199 
206  SUMOReal getNoDiscarded() const;
207 
208 
212  void applyCurve(const Distribution_Points& ps);
213 
214 
218  void readO(LineReader& lr, SUMOReal scale,
219  std::string vehType, bool matrixHasVehType);
220 
224  void readV(LineReader& lr, SUMOReal scale,
225  std::string vehType, bool matrixHasVehType);
226 
230  void loadMatrix(OptionsCont& oc);
231 
235  void loadRoutes(OptionsCont& oc, SUMOSAXHandler& handler);
236 
240  Distribution_Points parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours);
241 
242  const std::vector<ODCell*>& getCells() {
243  return myContainer;
244  }
245 
246  void sortByBeginTime();
247 
248 protected:
253  struct ODVehicle {
255  std::string id;
261  std::string from;
263  std::string to;
264 
265  };
266 
267 
294  size_t& vehName, std::vector<ODVehicle>& into,
295  const bool uniform, const bool differSourceSink,
296  const std::string& prefix);
297 
298 
314  void applyCurve(const Distribution_Points& ps, ODCell* cell,
315  std::vector<ODCell*>& newCells);
316 
317 
318 private:
322  std::string getNextNonCommentLine(LineReader& lr);
323 
327  SUMOTime parseSingleTime(const std::string& time);
328 
332  std::pair<SUMOTime, SUMOTime> readTime(LineReader& lr);
333 
338 
339 
344  public:
346  explicit by_begin_sorter() { }
347 
349  int operator()(const ODCell* const c1, const ODCell* const c2) const {
350  return c1->begin < c2->begin;
351  }
352 
353  };
354 
355 protected:
357  std::vector<ODCell*> myContainer;
358 
361 
364 
367 
370 
371 
377  public:
379  explicit cell_by_begin_sorter() { }
380 
381 
392  int operator()(ODCell* p1, ODCell* p2) const {
393  if (p1->begin == p2->begin) {
394  if (p1->origin == p2->origin) {
395  return p1->destination < p2->destination;
396  }
397  return p1->origin < p2->origin;
398  }
399  return p1->begin < p2->begin;
400  }
401 
402  };
403 
404 
413  public:
416 
417 
426  bool operator()(const ODVehicle& p1, const ODVehicle& p2) const {
427  if (p1.depart == p2.depart) {
428  return p1.id > p2.id;
429  }
430  return p1.depart > p2.depart;
431  }
432 
433  };
434 
435 private:
437  ODMatrix(const ODMatrix& s);
438 
440  ODMatrix& operator=(const ODMatrix& s);
441 
442 };
443 
444 
445 #endif
446 
447 /****************************************************************************/
448 
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
const std::vector< ODCell * > & getCells()
Definition: ODMatrix.h:242
Used for sorting the cells by the begin time they describe.
Definition: ODMatrix.h:376
long long int SUMOTime
Definition: SUMOTime.h:43
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
int operator()(const ODCell *const c1, const ODCell *const c2) const
comparing operator
Definition: ODMatrix.h:349
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:58
SUMOReal myNoWritten
Number of written vehicles.
Definition: ODMatrix.h:366
int operator()(ODCell *p1, ODCell *p2) const
Comparing operator.
Definition: ODMatrix.h:392
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:360
An internal representation of a single vehicle.
Definition: ODMatrix.h:253
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
SAX-handler base for SUMO-files.
std::string from
The edge the vehicles shall start at.
Definition: ODMatrix.h:261
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:308
Sorts cells by their start time.
Definition: ODMatrix.h:343
ODMatrix & operator=(const ODMatrix &s)
invalid assignment operator
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
Definition: ODMatrix.cpp:513
by_begin_sorter()
constructor
Definition: ODMatrix.h:346
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
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:75
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
cell_by_begin_sorter()
constructor
Definition: ODMatrix.h:379
A container for districts.
SUMOReal getNoWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:473
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:412
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
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:63
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
SUMOReal readFactor(LineReader &lr, SUMOReal scale)
Definition: ODMatrix.cpp:337
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:319
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:295
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:257
A storage for options typed value containers)
Definition: OptionsCont.h:108
void applyCurve(const Distribution_Points &ps)
Splits the stored cells dividing them on the given time line.
Definition: ODMatrix.cpp:500
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
#define SUMOReal
Definition: config.h:214
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 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
bool operator()(const ODVehicle &p1, const ODVehicle &p2) const
Comparing operator.
Definition: ODMatrix.h:426
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:576