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 <map>
39 #include <utils/common/SUMOTime.h>
41 #include "RODFRouteCont.h"
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class RODFRouteCont;
48 class RODFDetectorFlows;
49 class ROEdge;
50 class RODFEdge;
51 class RODFDetectorCon;
52 class RODFNet;
53 struct RODFRouteDesc;
54 class OutputDevice;
55 
56 
57 // ===========================================================================
58 // enumerations
59 // ===========================================================================
67 
70 
73 
77 };
78 
79 
80 // ===========================================================================
81 // class definitions
82 // ===========================================================================
87 class RODFDetector {
88 public:
99  RODFDetector(const std::string& id, const std::string& laneID,
100  SUMOReal pos, const RODFDetectorType type) ;
101 
102 
110  RODFDetector(const std::string& id, const RODFDetector& f) ;
111 
112 
114  ~RODFDetector() ;
115 
116 
117 
120 
124  const std::string& getID() const {
125  return myID;
126  };
127 
128 
132  const std::string& getLaneID() const {
133  return myLaneID;
134  };
135 
136 
140  std::string getEdgeID() const {
141  return myLaneID.substr(0, myLaneID.rfind('_'));
142  }
143 
144 
148  SUMOReal getPos() const {
149  return myPosition;
150  };
151 
152 
158  return myType;
159  };
161 
162 
163  void setType(RODFDetectorType type);
164  void addRoute(RODFRouteDesc& nrd);
165  void addRoutes(RODFRouteCont* routes);
166  bool hasRoutes() const;
167  const std::vector<RODFRouteDesc> &getRouteVector() const;
168  void addPriorDetector(RODFDetector* det);
170  const std::vector<RODFDetector*> &getPriorDetectors() const;
171  const std::vector<RODFDetector*> &getFollowerDetectors() const;
172 
173 
176 
177  bool writeEmitterDefinition(const std::string& file,
178  const std::map<size_t, RandomDistributor<size_t>* > &dists,
179  const RODFDetectorFlows& flows,
180  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
181  bool includeUnusedRoutes, SUMOReal scale,
182  bool insertionsOnly, SUMOReal defaultSpeed) const;
183  bool writeRoutes(std::vector<std::string> &saved,
184  OutputDevice& out);
185  void writeSingleSpeedTrigger(const std::string& file,
186  const RODFDetectorFlows& flows,
187  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
188  SUMOReal defaultSpeed);
189  void writeEndRerouterDetectors(const std::string& file);
191 
192  void buildDestinationDistribution(const RODFDetectorCon& detectors,
193  const RODFDetectorFlows& flows,
194  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
195  const RODFNet& net,
196  std::map<size_t, RandomDistributor<size_t>* > &into,
197  int maxFollower) const;
198 
199  void computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors,
200  const RODFDetectorFlows& flows,
201  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
202 
203  const std::vector<std::map<RODFEdge*, SUMOReal> > &getSplitProbabilities() const {
204  return mySplitProbabilities;
205  }
206 
207 protected:
208  int getFlowFor(const ROEdge* edge, SUMOTime time) const;
210 
211 
212 protected:
213  std::string myID;
214  std::string myLaneID;
218  std::vector<RODFDetector*> myPriorDetectors, myFollowingDetectors;
219  std::vector<std::map<RODFEdge*, SUMOReal> > mySplitProbabilities;
220  std::map<std::string, RODFEdge*> myRoute2Edge;
221 
222 
223 private:
225  RODFDetector(const RODFDetector& src);
226 
228  RODFDetector& operator=(const RODFDetector& src);
229 
230 };
231 
232 
238 public:
239  RODFDetectorCon();
241  bool addDetector(RODFDetector* dfd);
242  void removeDetector(const std::string& id);
243  bool detectorsHaveCompleteTypes() const;
244  bool detectorsHaveRoutes() const;
245  const std::vector<RODFDetector*> &getDetectors() const;
246  void save(const std::string& file) const;
247  void saveAsPOIs(const std::string& file) const;
248  void saveRoutes(const std::string& file) const;
249 
250  const RODFDetector& getDetector(const std::string& id) const;
251  const RODFDetector& getAnyDetectorForEdge(const RODFEdge* const edge) const;
252 
253  bool knows(const std::string& id) const;
254  void writeEmitters(const std::string& file,
255  const RODFDetectorFlows& flows,
256  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
257  const RODFNet& net,
258  bool writeCalibrators, bool includeUnusedRoutes,
259  SUMOReal scale, int maxFollower,
260  bool insertionsOnly);
261 
262  void writeEmitterPOIs(const std::string& file,
263  const RODFDetectorFlows& flows);
264 
265  void writeSpeedTrigger(const RODFNet* const net, const std::string& file,
266  const RODFDetectorFlows& flows,
267  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
268 
269  void writeValidationDetectors(const std::string& file,
270  bool includeSources, bool singleFile, bool friendly);
271  void writeEndRerouterDetectors(const std::string& file);
272 
273  int getAggFlowFor(const ROEdge* edge, SUMOTime time, SUMOTime period,
274  const RODFDetectorFlows& flows) const;
275 
276  void guessEmptyFlows(RODFDetectorFlows& flows);
277 
278  void mesoJoin(const std::string& nid, const std::vector<std::string> &oldids);
279 
280 
281 protected:
285  void clearDists(std::map<size_t, RandomDistributor<size_t>* > &dists) const ;
286 
287 
288 protected:
289  std::vector<RODFDetector*> myDetectors;
290  std::map<std::string, RODFDetector*> myDetectorMap;
291  std::map<std::string, std::vector<RODFDetector*> > myDetectorEdgeMap;
292 
293 private:
295  RODFDetectorCon(const RODFDetectorCon& src);
296 
299 
300 };
301 
302 
303 #endif
304 
305 /****************************************************************************/
306