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 /****************************************************************************/
9 // An O/D (origin/destination) matrix
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2006-2014 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 
55 
56 // ===========================================================================
57 // class definitions
58 // ===========================================================================
74 class ODMatrix {
75 public:
80  ODMatrix(const ODDistrictCont& dc);
81 
82 
84  ~ODMatrix();
85 
86 
108  void add(SUMOReal vehicleNumber, SUMOTime begin,
109  SUMOTime end, const std::string& origin, const std::string& destination,
110  const std::string& vehicleType);
111 
119  void writeDefaultAttrs(OutputDevice& dev, const bool noVtype,
120  const ODCell* const cell);
121 
146  void write(SUMOTime begin, const SUMOTime end,
147  OutputDevice& dev, const bool uniform, const bool noVtype,
148  const std::string& prefix, const bool stepLog);
149 
150 
159  void writeFlows(const SUMOTime begin, const SUMOTime end,
160  OutputDevice& dev, const bool noVtype,
161  const std::string& prefix);
162 
163 
170  SUMOReal getNoLoaded() const;
171 
172 
179  SUMOReal getNoWritten() const;
180 
181 
188  SUMOReal getNoDiscarded() const;
189 
190 
194  void applyCurve(const Distribution_Points& ps);
195 
196 
200  void readO(LineReader& lr, SUMOReal scale,
201  std::string vehType, bool matrixHasVehType);
202 
206  void readV(LineReader& lr, SUMOReal scale,
207  std::string vehType, bool matrixHasVehType);
208 
212  void loadMatrix(OptionsCont& oc);
213 
217  Distribution_Points parseTimeLine(const std::vector<std::string>& def, bool timelineDayInHours);
218 
219  const std::vector<ODCell*>& getCells() {
220  return myContainer;
221  }
222 
223 protected:
228  struct ODVehicle {
230  std::string id;
236  std::string from;
238  std::string to;
239 
240  };
241 
242 
268  size_t& vehName, std::vector<ODVehicle>& into, bool uniform,
269  const std::string& prefix);
270 
271 
287  void applyCurve(const Distribution_Points& ps, ODCell* cell,
288  std::vector<ODCell*>& newCells);
289 
290 
291 private:
295  std::string getNextNonCommentLine(LineReader& lr);
296 
300  SUMOTime parseSingleTime(const std::string& time);
301 
305  std::pair<SUMOTime, SUMOTime> readTime(LineReader& lr);
306 
311 
312 
313 protected:
315  std::vector<ODCell*> myContainer;
316 
319 
322 
325 
328 
329 
335  public:
337  explicit cell_by_begin_sorter() { }
338 
339 
350  int operator()(ODCell* p1, ODCell* p2) const {
351  if (p1->begin == p2->begin) {
352  if (p1->origin == p2->origin) {
353  return p1->destination < p2->destination;
354  }
355  return p1->origin < p2->origin;
356  }
357  return p1->begin < p2->begin;
358  }
359 
360  };
361 
362 
371  public:
374 
375 
384  bool operator()(const ODVehicle& p1, const ODVehicle& p2) const {
385  if (p1.depart == p2.depart) {
386  return p1.id > p2.id;
387  }
388  return p1.depart > p2.depart;
389  }
390 
391  };
392 
393 private:
395  ODMatrix(const ODMatrix& s);
396 
398  ODMatrix& operator=(const ODMatrix& s);
399 
400 };
401 
402 
403 #endif
404 
405 /****************************************************************************/
406