SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ODMatrix.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // An O/D (origin/destination) matrix
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
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 <string>
42 #include <utils/common/SUMOTime.h>
43 #include "ODCell.h"
44 #include "ODDistrictCont.h"
47 #include <utils/common/SUMOTime.h>
48 
49 // ===========================================================================
50 // class declarations
51 // ===========================================================================
52 class OutputDevice;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
73 class ODMatrix {
74 public:
79  ODMatrix(const ODDistrictCont& dc);
80 
81 
83  ~ODMatrix();
84 
85 
107  void add(SUMOReal vehicleNumber, SUMOTime begin,
108  SUMOTime end, const std::string& origin, const std::string& destination,
109  const std::string& vehicleType);
110 
118  void writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
119  const ODCell* const cell);
120 
145  void write(SUMOTime begin, const SUMOTime end,
146  OutputDevice& dev, const bool uniform, const bool noVtype,
147  const std::string& prefix, const bool stepLog);
148 
149 
158  void writeFlows(const SUMOTime begin, const SUMOTime end,
159  OutputDevice& dev, const bool noVtype,
160  const std::string& prefix);
161 
162 
169  SUMOReal getNoLoaded() const;
170 
171 
178  SUMOReal getNoWritten() const;
179 
180 
187  SUMOReal getNoDiscarded() const;
188 
189 
193  void applyCurve(const Distribution_Points& ps);
194 
195 
199  void readO(LineReader& lr, SUMOReal scale,
200  std::string vehType, bool matrixHasVehType);
201 
205  void readV(LineReader& lr, SUMOReal scale,
206  std::string vehType, bool matrixHasVehType);
207 
211  void loadMatrix(OptionsCont& oc);
212 
216  Distribution_Points parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours);
217 
218  const std::vector<ODCell*>& getCells() {
219  return myContainer;
220  }
221 
222 protected:
227  struct ODVehicle {
229  std::string id;
235  std::string from;
237  std::string to;
238 
239  };
240 
241 
267  size_t& vehName, std::vector<ODVehicle>& into, bool uniform,
268  const std::string& prefix);
269 
270 
286  void applyCurve(const Distribution_Points& ps, ODCell* cell,
287  std::vector<ODCell*>& newCells);
288 
289 
290 private:
294  std::string getNextNonCommentLine(LineReader& lr);
295 
299  SUMOTime parseSingleTime(const std::string& time);
300 
304  std::pair<SUMOTime, SUMOTime> readTime(LineReader& lr);
305 
310 
311 
312 protected:
314  std::vector<ODCell*> myContainer;
315 
318 
321 
324 
327 
328 
334  public:
336  explicit cell_by_begin_sorter() { }
337 
338 
349  int operator()(ODCell* p1, ODCell* p2) const {
350  if (p1->begin == p2->begin) {
351  if (p1->origin == p2->origin) {
352  return p1->destination < p2->destination;
353  }
354  return p1->origin < p2->origin;
355  }
356  return p1->begin < p2->begin;
357  }
358 
359  };
360 
361 
370  public:
373 
374 
383  bool operator()(const ODVehicle& p1, const ODVehicle& p2) const {
384  if (p1.depart == p2.depart) {
385  return p1.id > p2.id;
386  }
387  return p1.depart > p2.depart;
388  }
389 
390  };
391 
392 private:
394  ODMatrix(const ODMatrix& s);
395 
397  ODMatrix& operator=(const ODMatrix& s);
398 
399 };
400 
401 
402 #endif
403 
404 /****************************************************************************/
405 
SUMOReal getNoLoaded() const
Returns the number of loaded vehicles.
Definition: ODMatrix.cpp:427
SUMOReal myNoLoaded
Number of loaded vehicles.
Definition: ODMatrix.h:320
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:136
const std::vector< ODCell * > & getCells()
Definition: ODMatrix.h:218
Used for sorting the cells by the begin time they describe.
Definition: ODMatrix.h:333
void write(SUMOTime begin, const SUMOTime end, OutputDevice &dev, const bool uniform, 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:165
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:58
SUMOReal myNoWritten
Number of written vehicles.
Definition: ODMatrix.h:323
int operator()(ODCell *p1, ODCell *p2) const
Comparing operator.
Definition: ODMatrix.h:349
const ODDistrictCont & myDistricts
The districts to retrieve sources/sinks from.
Definition: ODMatrix.h:317
An internal representation of a single vehicle.
Definition: ODMatrix.h:227
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:71
std::string from
The edge the vehicles shall start at.
Definition: ODMatrix.h:235
SUMOTime parseSingleTime(const std::string &time)
Definition: ODMatrix.cpp:268
ODMatrix & operator=(const ODMatrix &s)
invalid assignment operator
void loadMatrix(OptionsCont &oc)
read a VISUM-matrix with the V Format
Definition: ODMatrix.cpp:472
SUMOReal getNoDiscarded() const
Returns the number of discarded vehicles.
Definition: ODMatrix.cpp:439
~ODMatrix()
Destructor.
Definition: ODMatrix.cpp:62
A single O/D-matrix cell.
Definition: ODCell.h:55
void readV(LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the V Format
Definition: ODMatrix.cpp:309
std::string origin
Name of the origin district.
Definition: ODCell.h:66
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:73
void readO(LineReader &lr, SUMOReal scale, std::string vehType, bool matrixHasVehType)
read a VISUM-matrix with the O Format
Definition: ODMatrix.cpp:377
ODCell * cell
The cell of the ODMatrix which generated the vehicle.
Definition: ODMatrix.h:233
cell_by_begin_sorter()
constructor
Definition: ODMatrix.h:336
A container for districts.
SUMOReal getNoWritten() const
Returns the number of written vehicles.
Definition: ODMatrix.cpp:433
Used for sorting vehicles by their departure (latest first)
Definition: ODMatrix.h:369
SUMOReal myNoDiscarded
Number of discarded vehicles.
Definition: ODMatrix.h:326
std::vector< ODCell * > myContainer
The loaded cells.
Definition: ODMatrix.h:314
SUMOTime begin
The begin time this cell describes.
Definition: ODCell.h:60
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:232
SUMOReal readFactor(LineReader &lr, SUMOReal scale)
Definition: ODMatrix.cpp:297
std::pair< SUMOTime, SUMOTime > readTime(LineReader &lr)
Definition: ODMatrix.cpp:279
std::string getNextNonCommentLine(LineReader &lr)
Definition: ODMatrix.cpp:255
SUMOTime depart
The departure time of the vehicle.
Definition: ODMatrix.h:231
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:460
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:69
#define SUMOReal
Definition: config.h:215
std::string to
The edge the vehicles shall end at.
Definition: ODMatrix.h:237
ODMatrix(const ODDistrictCont &dc)
Constructor.
Definition: ODMatrix.cpp:58
SUMOReal computeDeparts(ODCell *cell, size_t &vehName, std::vector< ODVehicle > &into, bool uniform, const std::string &prefix)
Computes the vehicle departs stored in the given cell and saves them in &quot;into&quot;.
Definition: ODMatrix.cpp:105
std::string id
The id of the vehicle.
Definition: ODMatrix.h:229
bool operator()(const ODVehicle &p1, const ODVehicle &p2) const
Comparing operator.
Definition: ODMatrix.h:383
Distribution_Points parseTimeLine(const std::vector< std::string > &def, bool timelineDayInHours)
split the given timeline
Definition: ODMatrix.cpp:510