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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // An O/D (origin/destination) matrix
18 /****************************************************************************/
19 #ifndef ODMatrix_h
20 #define ODMatrix_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <iostream>
29 #include <sstream>
30 #include <fstream>
31 #include <vector>
32 #include <cstdlib>
33 #include <ctime>
34 #include <algorithm>
35 #include <set>
36 #include <string>
37 #include <utils/common/SUMOTime.h>
38 #include "ODCell.h"
39 #include "ODDistrictCont.h"
42 #include <utils/common/SUMOTime.h>
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class OutputDevice;
48 class SUMOSAXHandler;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
69 class ODMatrix {
70 public:
75  ODMatrix(const ODDistrictCont& dc);
76 
77 
79  ~ODMatrix();
80 
81 
104  bool add(double vehicleNumber, SUMOTime begin,
105  SUMOTime end, const std::string& origin, const std::string& destination,
106  const std::string& vehicleType);
107 
119  bool add(const std::string& id, const SUMOTime depart,
120  const std::pair<const std::string, const std::string>& od,
121  const std::string& vehicleType);
122 
130  void writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
131  const ODCell* const cell);
132 
158  void write(SUMOTime begin, const SUMOTime end,
159  OutputDevice& dev, const bool uniform,
160  const bool differSourceSink, const bool noVtype,
161  const std::string& prefix, const bool stepLog,
162  bool pedestrians, bool persontrips);
163 
164 
174  void writeFlows(const SUMOTime begin, const SUMOTime end,
175  OutputDevice& dev, const bool noVtype,
176  const std::string& prefix,
177  bool asProbability = false);
178 
179 
186  double getNumLoaded() const;
187 
188 
195  double getNumWritten() const;
196 
197 
204  double getNumDiscarded() const;
205 
206 
210  void applyCurve(const Distribution_Points& ps);
211 
212 
216  void readO(LineReader& lr, double scale,
217  std::string vehType, bool matrixHasVehType);
218 
222  void readV(LineReader& lr, double scale,
223  std::string vehType, bool matrixHasVehType);
224 
228  void loadMatrix(OptionsCont& oc);
229 
233  void loadRoutes(OptionsCont& oc, SUMOSAXHandler& handler);
234 
238  Distribution_Points parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours);
239 
240  const std::vector<ODCell*>& getCells() {
241  return myContainer;
242  }
243 
244  void sortByBeginTime();
245 
246 protected:
251  struct ODVehicle {
253  std::string id;
259  std::string from;
261  std::string to;
262 
263  };
264 
265 
291  double computeDeparts(ODCell* cell,
292  int& vehName, std::vector<ODVehicle>& into,
293  const bool uniform, const bool differSourceSink,
294  const std::string& prefix);
295 
296 
312  void applyCurve(const Distribution_Points& ps, ODCell* cell,
313  std::vector<ODCell*>& newCells);
314 
315 
316 private:
320  std::string getNextNonCommentLine(LineReader& lr);
321 
325  SUMOTime parseSingleTime(const std::string& time);
326 
330  std::pair<SUMOTime, SUMOTime> readTime(LineReader& lr);
331 
335  double readFactor(LineReader& lr, double scale);
336 
337 
338 private:
340  std::vector<ODCell*> myContainer;
341 
343  std::map<const std::pair<const std::string, const std::string>, std::vector<ODCell*> > myShortCut;
344 
347 
349  std::set<std::string> myMissingDistricts;
350 
352  double myNumLoaded;
353 
355  double myNumWritten;
356 
359 
360 
366  public:
369 
370 
381  int operator()(ODCell* p1, ODCell* p2) const {
382  if (p1->begin == p2->begin) {
383  if (p1->origin == p2->origin) {
384  return p1->destination < p2->destination;
385  }
386  return p1->origin < p2->origin;
387  }
388  return p1->begin < p2->begin;
389  }
390 
391  };
392 
393 
402  public:
405 
406 
415  bool operator()(const ODVehicle& p1, const ODVehicle& p2) const {
416  if (p1.depart == p2.depart) {
417  return p1.id > p2.id;
418  }
419  return p1.depart > p2.depart;
420  }
421 
422  };
423 
424 private:
426  ODMatrix(const ODMatrix& s);
427 
429  ODMatrix& operator=(const ODMatrix& s);
430 
431 };
432 
433 
434 #endif
435 
436 /****************************************************************************/
437 
int operator()(ODCell *p1, ODCell *p2) const
Comparing operator.
Definition: ODMatrix.h:381
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:210
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:181
Used for sorting the cells by the begin time they describe.
Definition: ODMatrix.h:365
const std::vector< ODCell * > & getCells()
Definition: ODMatrix.h:240
long long int SUMOTime
Definition: SUMOTime.h:36
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:51
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:346
An internal representation of a single vehicle.
Definition: ODMatrix.h:251
SAX-handler base for SUMO-files.
std::string from
The edge the vehicles shall start at.
Definition: ODMatrix.h:259
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:351
ODMatrix & operator=(const ODMatrix &s)
invalid assignment operator
void loadMatrix(OptionsCont &oc)
read a matrix in one of several formats
Definition: ODMatrix.cpp:557
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:142
~ODMatrix()
Destructor.
Definition: ODMatrix.cpp:55
double myNumDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:358
A single O/D-matrix cell.
Definition: ODCell.h:51
double myNumWritten
Number of written vehicles.
Definition: ODMatrix.h:355
std::string origin
Name of the origin district.
Definition: ODCell.h:62
cell_by_begin_comparator()
constructor
Definition: ODMatrix.h:368
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:69
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:603
A container for districts.
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:401
double readFactor(LineReader &lr, double scale)
Definition: ODMatrix.cpp:380
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:343
void sortByBeginTime()
Definition: ODMatrix.cpp:645
std::vector< ODCell * > myContainer
The loaded cells.
Definition: ODMatrix.h:340
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:56
double getNumLoaded() const
Returns the number of loaded vehicles.
Definition: ODMatrix.cpp:510
double getNumWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:516
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:362
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:339
bool operator()(const ODVehicle &p1, const ODVehicle &p2) const
Comparing operator.
Definition: ODMatrix.h:415
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:255
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:64
A storage for options typed value containers)
Definition: OptionsCont.h:92
void applyCurve(const Distribution_Points &ps)
Splits the stored cells dividing them on the given time line.
Definition: ODMatrix.cpp:544
void readV(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
Definition: ODMatrix.cpp:392
void readO(LineReader &lr, double scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
Definition: ODMatrix.cpp:460
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
std::string destination
Name of the destination district.
Definition: ODCell.h:65
double getNumDiscarded() const
Returns the number of discarded vehicles.
Definition: ODMatrix.cpp:522
std::string to
The edge the vehicles shall end at.
Definition: ODMatrix.h:261
ODMatrix(const ODDistrictCont &dc)
Constructor.
Definition: ODMatrix.cpp:51
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:299
std::set< std::string > myMissingDistricts
The missing districts already warned about.
Definition: ODMatrix.h:349
std::string id
The id of the vehicle.
Definition: ODMatrix.h:253
double myNumLoaded
Number of loaded vehicles.
Definition: ODMatrix.h:352
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:620