Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/dfrouter/RODFDetector.h
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file RODFDetector.h
15
/// @author Daniel Krajzewicz
16
/// @author Eric Nicolay
17
/// @author Michael Behrisch
18
/// @date Thu, 16.03.2006
19
///
20
// Class representing a detector within the DFROUTER
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <map>
26
#include <string>
27
#include <vector>
28
#include <set>
29
#include <utils/common/SUMOTime.h>
30
#include <utils/distribution/RandomDistributor.h>
31
#include <utils/common/Named.h>
32
#include "RODFRouteCont.h"
33
34
35
// ===========================================================================
36
// class declarations
37
// ===========================================================================
38
class RODFRouteCont;
39
class RODFDetectorFlows;
40
class ROEdge;
41
class RODFEdge;
42
class RODFDetectorCon;
43
class RODFNet;
44
struct RODFRouteDesc;
45
class OutputDevice;
46
class SUMOVTypeParameter;
47
48
49
// ===========================================================================
50
// enumerations
51
// ===========================================================================
52
/**
53
* @enum RODFDetectorType
54
* @brief Numerical representation of different detector types
55
*/
56
enum RODFDetectorType {
57
/// A not yet defined detector
58
TYPE_NOT_DEFINED = 0,
59
60
/// A detector which had to be discarded (!!!)
61
DISCARDED_DETECTOR,
62
63
/// An in-between detector
64
BETWEEN_DETECTOR,
65
66
/// A source detector
67
SOURCE_DETECTOR,
68
SINK_DETECTOR
69
};
70
71
72
// ===========================================================================
73
// class definitions
74
// ===========================================================================
75
/**
76
* @class RODFDetector
77
* @brief Class representing a detector within the DFROUTER
78
*/
79
class RODFDetector : public Named {
80
public:
81
/** @brief Constructor
82
*
83
* This constructor is used when detectors are read from a file
84
*
85
* @param[in] id The id of the detector
86
* @param[in] laneID The id of the lane the detector is placed at
87
* @param[in] pos The position of the detector at the lane
88
* @param[in] type The df-router type of the detector
89
* @see RODFDetectorType
90
*/
91
RODFDetector(const std::string& id, const std::string& laneID,
92
double pos, const RODFDetectorType type);
93
94
95
/** @brief Constructor
96
*
97
* This constructor is used when detectors shall be joined
98
*
99
* @param[in] id The id of the detector
100
* @param[in] f A detector from which routes shall be copied
101
*/
102
RODFDetector(const std::string& id, const RODFDetector& f);
103
104
105
/// @brief Destructor
106
~RODFDetector();
107
108
109
110
/// @name Atomar getter methods
111
/// @{
112
113
/** @brief Returns the id of the lane this detector is placed on
114
* @return The id of the lane this detector is placed on
115
*/
116
const std::string& getLaneID() const {
117
return myLaneID;
118
};
119
120
121
/** @brief Returns the id of the edge this detector is placed on
122
* @return The id of the edge this detector is placed on
123
*/
124
std::string getEdgeID() const;
125
126
127
/** @brief Returns the position at which the detector lies
128
* @return The position of the detector at the lane
129
*/
130
double getPos() const {
131
return myPosition;
132
};
133
134
135
/** @brief Returns the type of the detector
136
* @return This detector's type
137
* @see RODFDetectorType
138
*/
139
RODFDetectorType getType() const {
140
return myType;
141
};
142
/// @}
143
144
145
void setType(RODFDetectorType type);
146
void addRoute(RODFRouteDesc& nrd);
147
void addRoutes(RODFRouteCont* routes);
148
bool hasRoutes() const;
149
const std::vector<RODFRouteDesc>& getRouteVector() const;
150
void addPriorDetector(const RODFDetector* det);
151
void addFollowingDetector(const RODFDetector* det);
152
const std::set<const RODFDetector*>& getPriorDetectors() const;
153
const std::set<const RODFDetector*>& getFollowerDetectors() const;
154
155
156
/// @name Writing methods
157
/// @{
158
159
bool writeEmitterDefinition(const std::string& file,
160
const std::map<SUMOTime, RandomDistributor<int>* >& dists,
161
const RODFDetectorFlows& flows,
162
SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
163
bool includeUnusedRoutes, double scale,
164
bool insertionsOnly, double defaultSpeed) const;
165
bool writeRoutes(std::vector<std::string>& saved,
166
OutputDevice& out);
167
void writeSingleSpeedTrigger(const std::string& file,
168
const RODFDetectorFlows& flows,
169
SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
170
double defaultSpeed);
171
void writeEndRerouterDetectors(const std::string& file);
172
/// @}
173
174
void buildDestinationDistribution(const RODFDetectorCon& detectors,
175
SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
176
const RODFNet& net,
177
std::map<SUMOTime, RandomDistributor<int>* >& into) const;
178
179
void computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors,
180
const RODFDetectorFlows& flows,
181
SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
182
183
const std::vector<std::map<RODFEdge*, double> >& getSplitProbabilities() const {
184
return mySplitProbabilities;
185
}
186
187
protected:
188
int getFlowFor(const ROEdge* edge, SUMOTime time) const;
189
double computeDistanceFactor(const RODFRouteDesc& rd) const;
190
191
192
protected:
193
std::string myLaneID;
194
double myPosition;
195
RODFDetectorType myType;
196
RODFRouteCont* myRoutes;
197
std::set<const RODFDetector*> myPriorDetectors, myFollowingDetectors;
198
std::vector<std::map<RODFEdge*, double> > mySplitProbabilities;
199
std::map<std::string, RODFEdge*> myRoute2Edge;
200
201
202
private:
203
/// @brief Invalidated copy constructor
204
RODFDetector(const RODFDetector& src);
205
206
/// @brief Invalidated assignment operator
207
RODFDetector& operator=(const RODFDetector& src);
208
209
};
210
211
212
/**
213
* @class RODFDetectorCon
214
* @brief A container for RODFDetectors
215
*/
216
class RODFDetectorCon {
217
public:
218
RODFDetectorCon();
219
~RODFDetectorCon();
220
bool addDetector(RODFDetector* dfd);
221
void removeDetector(const std::string& id);
222
bool detectorsHaveCompleteTypes() const;
223
bool detectorsHaveRoutes() const;
224
const std::vector<RODFDetector*>& getDetectors() const;
225
void save(const std::string& file) const;
226
void saveAsPOIs(const std::string& file) const;
227
void saveRoutes(const std::string& file) const;
228
229
const RODFDetector& getDetector(const std::string& id) const;
230
RODFDetector& getModifiableDetector(const std::string& id) const;
231
const RODFDetector& getAnyDetectorForEdge(const RODFEdge* const edge) const;
232
233
bool knows(const std::string& id) const;
234
void writeEmitters(const std::string& file,
235
const RODFDetectorFlows& flows,
236
SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset,
237
const RODFNet& net,
238
bool writeCalibrators, bool includeUnusedRoutes,
239
double scale,
240
bool insertionsOnly);
241
242
void writeEmitterPOIs(const std::string& file,
243
const RODFDetectorFlows& flows);
244
245
void writeSpeedTrigger(const RODFNet* const net, const std::string& file,
246
const RODFDetectorFlows& flows,
247
SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
248
249
void writeValidationDetectors(const std::string& file,
250
bool includeSources, bool singleFile, bool friendly);
251
void writeEndRerouterDetectors(const std::string& file);
252
253
int getAggFlowFor(const ROEdge* edge, SUMOTime time, SUMOTime period,
254
const RODFDetectorFlows& flows) const;
255
256
void guessEmptyFlows(RODFDetectorFlows& flows);
257
258
void mesoJoin(const std::string& nid, const std::vector<std::string>& oldids);
259
260
void setSpeedFactorAndDev(SUMOVTypeParameter& type, double maxFactor, double avgFactor, double dev, bool forceDev);
261
262
protected:
263
/** @brief Clears the given distributions map, deleting the timed distributions
264
* @param[in] dists The distribution map to clear
265
*/
266
void clearDists(std::map<SUMOTime, RandomDistributor<int>* >& dists) const;
267
268
269
protected:
270
std::vector<RODFDetector*> myDetectors;
271
std::map<std::string, RODFDetector*> myDetectorMap;
272
std::map<std::string, std::vector<RODFDetector*> > myDetectorEdgeMap;
273
274
private:
275
/// @brief Invalidated copy constructor
276
RODFDetectorCon(const RODFDetectorCon& src);
277
278
/// @brief Invalidated assignment operator
279
RODFDetectorCon& operator=(const RODFDetectorCon& src);
280
281
};
282
283