SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RODFDetector.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Class representing a detector within the DFROUTER
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 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 RODFDetector_h
23 #define RODFDetector_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 <map>
36 #include <string>
37 #include <vector>
38 #include <utils/common/SUMOTime.h>
40 #include "RODFRouteCont.h"
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class RODFRouteCont;
47 class RODFDetectorFlows;
48 class ROEdge;
49 class RODFEdge;
50 class RODFDetectorCon;
51 class RODFNet;
52 struct RODFRouteDesc;
53 class OutputDevice;
54 
55 
56 // ===========================================================================
57 // enumerations
58 // ===========================================================================
66 
69 
72 
76 };
77 
78 
79 // ===========================================================================
80 // class definitions
81 // ===========================================================================
86 class RODFDetector {
87 public:
98  RODFDetector(const std::string& id, const std::string& laneID,
99  SUMOReal pos, const RODFDetectorType type);
100 
101 
109  RODFDetector(const std::string& id, const RODFDetector& f);
110 
111 
113  ~RODFDetector();
114 
115 
116 
119 
123  const std::string& getID() const {
124  return myID;
125  };
126 
127 
131  const std::string& getLaneID() const {
132  return myLaneID;
133  };
134 
135 
139  std::string getEdgeID() const {
140  return myLaneID.substr(0, myLaneID.rfind('_'));
141  }
142 
143 
147  SUMOReal getPos() const {
148  return myPosition;
149  };
150 
151 
157  return myType;
158  };
160 
161 
162  void setType(RODFDetectorType type);
163  void addRoute(RODFRouteDesc& nrd);
164  void addRoutes(RODFRouteCont* routes);
165  bool hasRoutes() const;
166  const std::vector<RODFRouteDesc>& getRouteVector() const;
167  void addPriorDetector(RODFDetector* det);
169  const std::vector<RODFDetector*>& getPriorDetectors() const;
170  const std::vector<RODFDetector*>& getFollowerDetectors() const;
171 
172 
175 
176  bool writeEmitterDefinition(const std::string& file,
177  const std::map<size_t, RandomDistributor<size_t>* >& dists,
178  const RODFDetectorFlows& flows,
179  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
180  bool includeUnusedRoutes, SUMOReal scale,
181  bool insertionsOnly, SUMOReal defaultSpeed) const;
182  bool writeRoutes(std::vector<std::string>& saved,
183  OutputDevice& out);
184  void writeSingleSpeedTrigger(const std::string& file,
185  const RODFDetectorFlows& flows,
186  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
187  SUMOReal defaultSpeed);
188  void writeEndRerouterDetectors(const std::string& file);
190 
191  void buildDestinationDistribution(const RODFDetectorCon& detectors,
192  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
193  const RODFNet& net,
194  std::map<size_t, RandomDistributor<size_t>* >& into) const;
195 
196  void computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors,
197  const RODFDetectorFlows& flows,
198  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
199 
200  const std::vector<std::map<RODFEdge*, SUMOReal> >& getSplitProbabilities() const {
201  return mySplitProbabilities;
202  }
203 
204 protected:
205  int getFlowFor(const ROEdge* edge, SUMOTime time) const;
207 
208 
209 protected:
210  std::string myID;
211  std::string myLaneID;
215  std::vector<RODFDetector*> myPriorDetectors, myFollowingDetectors;
216  std::vector<std::map<RODFEdge*, SUMOReal> > mySplitProbabilities;
217  std::map<std::string, RODFEdge*> myRoute2Edge;
218 
219 
220 private:
222  RODFDetector(const RODFDetector& src);
223 
225  RODFDetector& operator=(const RODFDetector& src);
226 
227 };
228 
229 
235 public:
236  RODFDetectorCon();
238  bool addDetector(RODFDetector* dfd);
239  void removeDetector(const std::string& id);
240  bool detectorsHaveCompleteTypes() const;
241  bool detectorsHaveRoutes() const;
242  const std::vector<RODFDetector*>& getDetectors() const;
243  void save(const std::string& file) const;
244  void saveAsPOIs(const std::string& file) const;
245  void saveRoutes(const std::string& file) const;
246 
247  const RODFDetector& getDetector(const std::string& id) const;
248  const RODFDetector& getAnyDetectorForEdge(const RODFEdge* const edge) const;
249 
250  bool knows(const std::string& id) const;
251  void writeEmitters(const std::string& file,
252  const RODFDetectorFlows& flows,
253  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
254  const RODFNet& net,
255  bool writeCalibrators, bool includeUnusedRoutes,
256  SUMOReal scale,
257  bool insertionsOnly);
258 
259  void writeEmitterPOIs(const std::string& file,
260  const RODFDetectorFlows& flows);
261 
262  void writeSpeedTrigger(const RODFNet* const net, const std::string& file,
263  const RODFDetectorFlows& flows,
264  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
265 
266  void writeValidationDetectors(const std::string& file,
267  bool includeSources, bool singleFile, bool friendly);
268  void writeEndRerouterDetectors(const std::string& file);
269 
270  int getAggFlowFor(const ROEdge* edge, SUMOTime time, SUMOTime period,
271  const RODFDetectorFlows& flows) const;
272 
273  void guessEmptyFlows(RODFDetectorFlows& flows);
274 
275  void mesoJoin(const std::string& nid, const std::vector<std::string>& oldids);
276 
277 
278 protected:
282  void clearDists(std::map<size_t, RandomDistributor<size_t>* >& dists) const;
283 
284 
285 protected:
286  std::vector<RODFDetector*> myDetectors;
287  std::map<std::string, RODFDetector*> myDetectorMap;
288  std::map<std::string, std::vector<RODFDetector*> > myDetectorEdgeMap;
289 
290 private:
292  RODFDetectorCon(const RODFDetectorCon& src);
293 
296 
297 };
298 
299 
300 #endif
301 
302 /****************************************************************************/
303