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