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-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 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 <set>
39 #include <utils/common/SUMOTime.h>
41 #include <utils/common/Named.h>
42 #include "RODFRouteCont.h"
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class RODFRouteCont;
49 class RODFDetectorFlows;
50 class ROEdge;
51 class RODFEdge;
52 class RODFDetectorCon;
53 class RODFNet;
54 struct RODFRouteDesc;
55 class OutputDevice;
56 
57 
58 // ===========================================================================
59 // enumerations
60 // ===========================================================================
68 
71 
74 
78 };
79 
80 
81 // ===========================================================================
82 // class definitions
83 // ===========================================================================
88 class RODFDetector : public Named {
89 public:
100  RODFDetector(const std::string& id, const std::string& laneID,
101  SUMOReal pos, const RODFDetectorType type);
102 
103 
111  RODFDetector(const std::string& id, const RODFDetector& f);
112 
113 
115  ~RODFDetector();
116 
117 
118 
121 
125  const std::string& getLaneID() const {
126  return myLaneID;
127  };
128 
129 
133  std::string getEdgeID() const {
134  return myLaneID.substr(0, myLaneID.rfind('_'));
135  }
136 
137 
141  SUMOReal getPos() const {
142  return myPosition;
143  };
144 
145 
151  return myType;
152  };
154 
155 
156  void setType(RODFDetectorType type);
157  void addRoute(RODFRouteDesc& nrd);
158  void addRoutes(RODFRouteCont* routes);
159  bool hasRoutes() const;
160  const std::vector<RODFRouteDesc>& getRouteVector() const;
161  void addPriorDetector(const RODFDetector* det);
162  void addFollowingDetector(const RODFDetector* det);
163  const std::set<const RODFDetector*>& getPriorDetectors() const;
164  const std::set<const RODFDetector*>& getFollowerDetectors() const;
165 
166 
169 
170  bool writeEmitterDefinition(const std::string& file,
171  const std::map<size_t, RandomDistributor<size_t>* >& dists,
172  const RODFDetectorFlows& flows,
173  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
174  bool includeUnusedRoutes, SUMOReal scale,
175  bool insertionsOnly, SUMOReal defaultSpeed) const;
176  bool writeRoutes(std::vector<std::string>& saved,
177  OutputDevice& out);
178  void writeSingleSpeedTrigger(const std::string& file,
179  const RODFDetectorFlows& flows,
180  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
181  SUMOReal defaultSpeed);
182  void writeEndRerouterDetectors(const std::string& file);
184 
185  void buildDestinationDistribution(const RODFDetectorCon& detectors,
186  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
187  const RODFNet& net,
188  std::map<size_t, RandomDistributor<size_t>* >& into) const;
189 
190  void computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors,
191  const RODFDetectorFlows& flows,
192  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
193 
194  const std::vector<std::map<RODFEdge*, SUMOReal> >& getSplitProbabilities() const {
195  return mySplitProbabilities;
196  }
197 
198 protected:
199  int getFlowFor(const ROEdge* edge, SUMOTime time) const;
201 
202 
203 protected:
204  std::string myLaneID;
208  std::set<const RODFDetector*> myPriorDetectors, myFollowingDetectors;
209  std::vector<std::map<RODFEdge*, SUMOReal> > mySplitProbabilities;
210  std::map<std::string, RODFEdge*> myRoute2Edge;
211 
212 
213 private:
215  RODFDetector(const RODFDetector& src);
216 
218  RODFDetector& operator=(const RODFDetector& src);
219 
220 };
221 
222 
228 public:
229  RODFDetectorCon();
231  bool addDetector(RODFDetector* dfd);
232  void removeDetector(const std::string& id);
233  bool detectorsHaveCompleteTypes() const;
234  bool detectorsHaveRoutes() const;
235  const std::vector<RODFDetector*>& getDetectors() const;
236  void save(const std::string& file) const;
237  void saveAsPOIs(const std::string& file) const;
238  void saveRoutes(const std::string& file) const;
239 
240  const RODFDetector& getDetector(const std::string& id) const;
241  RODFDetector& getModifiableDetector(const std::string& id) const;
242  const RODFDetector& getAnyDetectorForEdge(const RODFEdge* const edge) const;
243 
244  bool knows(const std::string& id) const;
245  void writeEmitters(const std::string& file,
246  const RODFDetectorFlows& flows,
247  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
248  const RODFNet& net,
249  bool writeCalibrators, bool includeUnusedRoutes,
250  SUMOReal scale,
251  bool insertionsOnly);
252 
253  void writeEmitterPOIs(const std::string& file,
254  const RODFDetectorFlows& flows);
255 
256  void writeSpeedTrigger(const RODFNet* const net, const std::string& file,
257  const RODFDetectorFlows& flows,
258  SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
259 
260  void writeValidationDetectors(const std::string& file,
261  bool includeSources, bool singleFile, bool friendly);
262  void writeEndRerouterDetectors(const std::string& file);
263 
264  int getAggFlowFor(const ROEdge* edge, SUMOTime time, SUMOTime period,
265  const RODFDetectorFlows& flows) const;
266 
267  void guessEmptyFlows(RODFDetectorFlows& flows);
268 
269  void mesoJoin(const std::string& nid, const std::vector<std::string>& oldids);
270 
271 
272 protected:
276  void clearDists(std::map<size_t, RandomDistributor<size_t>* >& dists) const;
277 
278 
279 protected:
280  std::vector<RODFDetector*> myDetectors;
281  std::map<std::string, RODFDetector*> myDetectorMap;
282  std::map<std::string, std::vector<RODFDetector*> > myDetectorEdgeMap;
283 
284 private:
286  RODFDetectorCon(const RODFDetectorCon& src);
287 
290 
291 };
292 
293 
294 #endif
295 
296 /****************************************************************************/
297