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-sim.org/
12 // Copyright (C) 2001-2013 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 <utils/common/Named.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 : public Named {
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& getLaneID() const {
125  return myLaneID;
126  };
127 
128 
132  std::string getEdgeID() const {
133  return myLaneID.substr(0, myLaneID.rfind('_'));
134  }
135 
136 
140  SUMOReal getPos() const {
141  return myPosition;
142  };
143 
144 
150  return myType;
151  };
153 
154 
155  void setType(RODFDetectorType type);
156  void addRoute(RODFRouteDesc& nrd);
157  void addRoutes(RODFRouteCont* routes);
158  bool hasRoutes() const;
159  const std::vector<RODFRouteDesc>& getRouteVector() const;
160  void addPriorDetector(RODFDetector* det);
162  const std::vector<RODFDetector*>& getPriorDetectors() const;
163  const std::vector<RODFDetector*>& getFollowerDetectors() const;
164 
165 
168 
169  bool writeEmitterDefinition(const std::string& file,
170  const std::map<size_t, RandomDistributor<size_t>* >& dists,
171  const RODFDetectorFlows& flows,
172  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
173  bool includeUnusedRoutes, SUMOReal scale,
174  bool insertionsOnly, SUMOReal defaultSpeed) const;
175  bool writeRoutes(std::vector<std::string>& saved,
176  OutputDevice& out);
177  void writeSingleSpeedTrigger(const std::string& file,
178  const RODFDetectorFlows& flows,
179  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
180  SUMOReal defaultSpeed);
181  void writeEndRerouterDetectors(const std::string& file);
183 
184  void buildDestinationDistribution(const RODFDetectorCon& detectors,
185  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
186  const RODFNet& net,
187  std::map<size_t, RandomDistributor<size_t>* >& into) const;
188 
189  void computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors,
190  const RODFDetectorFlows& flows,
191  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
192 
193  const std::vector<std::map<RODFEdge*, SUMOReal> >& getSplitProbabilities() const {
194  return mySplitProbabilities;
195  }
196 
197 protected:
198  int getFlowFor(const ROEdge* edge, SUMOTime time) const;
200 
201 
202 protected:
203  std::string myLaneID;
207  std::vector<RODFDetector*> myPriorDetectors, myFollowingDetectors;
208  std::vector<std::map<RODFEdge*, SUMOReal> > mySplitProbabilities;
209  std::map<std::string, RODFEdge*> myRoute2Edge;
210 
211 
212 private:
214  RODFDetector(const RODFDetector& src);
215 
217  RODFDetector& operator=(const RODFDetector& src);
218 
219 };
220 
221 
227 public:
228  RODFDetectorCon();
230  bool addDetector(RODFDetector* dfd);
231  void removeDetector(const std::string& id);
232  bool detectorsHaveCompleteTypes() const;
233  bool detectorsHaveRoutes() const;
234  const std::vector<RODFDetector*>& getDetectors() const;
235  void save(const std::string& file) const;
236  void saveAsPOIs(const std::string& file) const;
237  void saveRoutes(const std::string& file) const;
238 
239  const RODFDetector& getDetector(const std::string& id) const;
240  const RODFDetector& getAnyDetectorForEdge(const RODFEdge* const edge) const;
241 
242  bool knows(const std::string& id) const;
243  void writeEmitters(const std::string& file,
244  const RODFDetectorFlows& flows,
245  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
246  const RODFNet& net,
247  bool writeCalibrators, bool includeUnusedRoutes,
248  SUMOReal scale,
249  bool insertionsOnly);
250 
251  void writeEmitterPOIs(const std::string& file,
252  const RODFDetectorFlows& flows);
253 
254  void writeSpeedTrigger(const RODFNet* const net, const std::string& file,
255  const RODFDetectorFlows& flows,
256  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
257 
258  void writeValidationDetectors(const std::string& file,
259  bool includeSources, bool singleFile, bool friendly);
260  void writeEndRerouterDetectors(const std::string& file);
261 
262  int getAggFlowFor(const ROEdge* edge, SUMOTime time, SUMOTime period,
263  const RODFDetectorFlows& flows) const;
264 
265  void guessEmptyFlows(RODFDetectorFlows& flows);
266 
267  void mesoJoin(const std::string& nid, const std::vector<std::string>& oldids);
268 
269 
270 protected:
274  void clearDists(std::map<size_t, RandomDistributor<size_t>* >& dists) const;
275 
276 
277 protected:
278  std::vector<RODFDetector*> myDetectors;
279  std::map<std::string, RODFDetector*> myDetectorMap;
280  std::map<std::string, std::vector<RODFDetector*> > myDetectorEdgeMap;
281 
282 private:
284  RODFDetectorCon(const RODFDetectorCon& src);
285 
288 
289 };
290 
291 
292 #endif
293 
294 /****************************************************************************/
295