Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netload/NLDetectorBuilder.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 NLDetectorBuilder.h
15
/// @author Daniel Krajzewicz
16
/// @author Clemens Honomichl
17
/// @author Christian Roessel
18
/// @author Michael Behrisch
19
/// @date Mon, 15 Apr 2002
20
///
21
// Builds detectors for microsim
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
26
#include <string>
27
#include <microsim/output/MSCrossSection.h>
28
#include <microsim/traffic_lights/MSTLLogicControl.h>
29
#include <microsim/output/MSE2Collector.h>
30
// #include <microsim/output/MSMultiLaneE2Collector.h>
31
32
// ===========================================================================
33
// class declarations
34
// ===========================================================================
35
class MSDetectorFileOutput;
36
class MSLane;
37
class MSEdge;
38
39
class MEInductLoop;
40
class MESegment;
41
42
43
// ===========================================================================
44
// class definitions
45
// ===========================================================================
46
/**
47
* @class NLDetectorBuilder
48
* @brief Builds detectors for microsim
49
*
50
* The building methods may be overridden, to build guisim-instances of the triggers,
51
* for example.
52
*/
53
class NLDetectorBuilder {
54
public:
55
/** @brief Constructor
56
*
57
* @param[in] net The network to which's detector control built detector shall be added
58
*/
59
NLDetectorBuilder(MSNet& net);
60
61
62
/// @brief Destructor
63
virtual ~NLDetectorBuilder();
64
65
66
/// @name Value parsing and detector building methods
67
/// @{
68
69
/** @brief Builds an e1 detector and adds it to the net
70
*
71
* Checks the given values, first. If one of the values is invalid
72
* (lane is not known, sampling frequency<=0, position is larger
73
* than lane's length, the id is already in use), an InvalidArgument is thrown.
74
*
75
* Otherwise the e1 detector is built by calling "createInductLoop".
76
*
77
* Internally, there is also a distinction whether a mesosim e1 detector
78
* shall be built.
79
*
80
* @param[in] id The id the detector shall have
81
* @param[in] lane The name of the lane the detector is placed at
82
* @param[in] pos The definition of the position on the lane the detector shall be placed at
83
* @param[in] length The optional length of the detector
84
* @param[in] splInterval The aggregation time span the detector shall use
85
* @param[in] device The output device the detector shall write into
86
* @param[in] friendlyPos Whether the position information shall be used "friendly" (see user docs)
87
* @param[in] vTypes which vehicle types are considered
88
* @exception InvalidArgument If one of the values is invalid
89
* @return The created detector
90
*/
91
Parameterised* buildInductLoop(const std::string& id,
92
const std::string& lane, double pos, double length, SUMOTime splInterval,
93
const std::string& device, bool friendlyPos,
94
const std::string name, const std::string& vTypes, const std::string& nextEdges, int detectPersons);
95
96
97
/** @brief Builds an instantenous induction and adds it to the net
98
*
99
* Checks the given values, first. If one of the values is invalid
100
* (lane is not known, sampling frequency<=0, position is larger
101
* than lane's length, the id is already in use), an InvalidArgument is thrown.
102
*
103
* Otherwise the e1 detector is built by calling "createInductLoop".
104
*
105
* @param[in] id The id the detector shall have
106
* @param[in] lane The name of the lane the detector is placed at
107
* @param[in] pos The definition of the position on the lane the detector shall be placed at
108
* @param[in] device The output device the detector shall write into
109
* @param[in] friendlyPos Whether the position information shall be used "friendly" (see user docs)
110
* @exception InvalidArgument If one of the values is invalid
111
* @return The created detector
112
*/
113
Parameterised* buildInstantInductLoop(const std::string& id,
114
const std::string& lane, double pos,
115
const std::string& device, bool friendlyPos,
116
const std::string name, const std::string& vTypes,
117
const std::string& nextEdges);
118
119
120
/** @brief Builds a new E2 detector and adds it to the net's detector control. Also performs some
121
* consistency checks for the detector positioning and applies "friendly positioning"
122
*
123
* @param[in] tlls Traffic light logic associated to the detector
124
* @param[in] toLane Lane associated to the detector (only for tlls != 0)
125
* @param[in] friendlyPos Whether automatic adjustments of the detector position shall be applied in case of erroneous specification
126
* @see For the other parameters see the MSE2Collector constructors
127
*
128
* @todo Add parameter showDetector to indicate whether the detector should be visible in the GUI
129
*
130
*/
131
Parameterised* buildE2Detector(const std::string& id, MSLane* lane, double pos, double endPos, double length,
132
const std::string& device, SUMOTime frequency,
133
SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
134
const std::string name, const std::string& vTypes,
135
const std::string& nextEdges,
136
int detectPersons, bool friendlyPos, bool showDetector,
137
MSTLLogicControl::TLSLogicVariants* tlls = 0, MSLane* toLane = 0);
138
139
Parameterised* buildE2Detector(const std::string& id, std::vector<MSLane*> lanes, double pos, double endPos,
140
const std::string& device, SUMOTime frequency,
141
SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
142
const std::string name, const std::string& vTypes,
143
const std::string& nextEdges,
144
int detectPersons, bool friendlyPos, bool showDetector,
145
MSTLLogicControl::TLSLogicVariants* tlls = 0, MSLane* toLane = 0);
146
147
148
/** @brief Stores temporary the initial information about an e3 detector to build
149
*
150
* If the given sample interval is < 0, an InvalidArgument is thrown. Otherwise,
151
* the values are stored in a new instance of E3DetectorDefinition within
152
* "myE3Definition".
153
*
154
* @param[in] id The id the detector shall have
155
* @param[in] device The output device the detector shall write into
156
* @param[in] splInterval The aggregation time span the detector shall use
157
* @param[in] haltingTimeThreshold Detector parameter: the time a vehicle's speed must be below haltingSpeedThreshold to be assigned as jammed
158
* @param[in] haltingSpeedThreshold Detector parameter: the speed a vehicle's speed must be below to be assigned as jammed
159
* @exception InvalidArgument If one of the values is invalid
160
*/
161
Parameterised* beginE3Detector(const std::string& id, const std::string& device, SUMOTime splInterval,
162
double haltingSpeedThreshold, SUMOTime haltingTimeThreshold,
163
const std::string name, const std::string& vTypes,
164
const std::string& nextEdges,
165
int detectPersons, bool openEntry, bool expectArrival);
166
167
168
/** @brief Builds an entry point of an e3 detector
169
*
170
* If the lane is not known or the position information is not within the lane,
171
* an InvalidArgument is thrown. Otherwise a MSCrossSection is built
172
* using the obtained values and added to the list of entries of the e3 definition
173
* stored in "myE3Definition".
174
*
175
* @param[in] lane The id of the lane the entry shall be placed at
176
* @param[in] pos The position on the lane the entry shall be placed at
177
* @param[in] friendlyPos Whether the position information shall be used "friendly" (see user docs)
178
* @exception InvalidArgument If one of the values is invalid
179
*/
180
void addE3Entry(const std::string& lane, double pos, bool friendlyPos);
181
182
183
/** @brief Builds an exit point of an e3 detector
184
*
185
* If the lane is not known or the position information is not within the lane,
186
* an InvalidArgument is thrown. Otherwise a MSCrossSection is built
187
* using the obtained values and added to the list of exits of the e3 definition
188
* stored in "myE3Definition".
189
*
190
* @param[in] lane The id of the lane the exit shall be placed at
191
* @param[in] pos The position on the lane the exit shall be placed at
192
* @param[in] friendlyPos Whether the position information shall be used "friendly" (see user docs)
193
* @exception InvalidArgument If one of the values is invalid
194
*/
195
void addE3Exit(const std::string& lane, double pos, bool friendlyPos);
196
197
198
/** @brief Builds of an e3 detector using collected values
199
*
200
* The parameter collected are used to build an e3 detector using
201
* "createE3Detector". The resulting detector is added to the net.
202
*
203
* @param[in] lane The id of the lane the exit shall be placed at
204
* @param[in] pos The position on the lane the exit shall be placed at
205
* @exception InvalidArgument If one of the values is invalid
206
*/
207
void endE3Detector();
208
209
210
/** @brief Returns the id of the currently built e3 detector
211
*
212
* This is used for error-message generation only. If no id is known,
213
* "<unknown>" is returned.
214
*
215
* @return The id of the currently processed e3 detector
216
*/
217
std::string getCurrentE3ID() const;
218
219
220
/** @brief Builds a vTypeProbe and adds it to the net
221
*
222
* Checks the given values, first. If one of the values is invalid
223
* (sampling frequency<=0), an InvalidArgument is thrown.
224
*
225
* Otherwise the vTypeProbe is built (directly).
226
*
227
* @param[in] id The id the detector shall have
228
* @param[in] vtype The name of the vehicle type the detector shall observe
229
* @param[in] frequency The reporting frequency
230
* @param[in] device The output device the detector shall write into
231
* @exception InvalidArgument If one of the values is invalid
232
*/
233
void buildVTypeProbe(const std::string& id,
234
const std::string& vtype, SUMOTime frequency,
235
const std::string& device);
236
237
238
/** @brief Builds a routeProbe and adds it to the net
239
*
240
* Checks the given values, first. If one of the values is invalid
241
* (sampling frequency<=0), an InvalidArgument is thrown.
242
*
243
* Otherwise the routeProbe is built (directly).
244
*
245
* @param[in] id The id the detector shall have
246
* @param[in] edge The name of the edge the detector shall observe
247
* @param[in] frequency The reporting frequency
248
* @param[in] begin The start of the first reporting interval
249
* @param[in] device The output device the detector shall write into
250
* @exception InvalidArgument If one of the values is invalid
251
*/
252
void buildRouteProbe(const std::string& id, const std::string& edge,
253
SUMOTime frequency, SUMOTime begin,
254
const std::string& device,
255
const std::string& vTypes);
256
/// @}
257
258
259
260
/// @name Detector creating methods
261
///
262
/// Virtual, so they may be overwritten, for generating gui-versions of the detectors, for example.
263
/// @{
264
265
/** @brief Creates an instance of an e1 detector using the given values
266
*
267
* Simply calls the MSInductLoop constructor
268
*
269
* @param[in] id The id the detector shall have
270
* @param[in] lane The lane the detector is placed at
271
* @param[in] pos The position on the lane the detector is placed at
272
* @param[in] length The optional length of the detector
273
* @param[in] vTypes which vehicle types are considered
274
* @param[in] show Whether to show the detector in the gui if available
275
*/
276
virtual MSDetectorFileOutput* createInductLoop(const std::string& id,
277
MSLane* lane, double pos,
278
double length,
279
const std::string name, const std::string& vTypes,
280
const std::string& nextEdges,
281
int detectPersons,
282
bool show);
283
284
285
/** @brief Creates an instance of an e1 detector using the given values
286
*
287
* Simply calls the MSInductLoop constructor
288
*
289
* @param[in] id The id the detector shall have
290
* @param[in] lane The lane the detector is placed at
291
* @param[in] pos The position on the lane the detector is placed at
292
* @param[in] od The output device the loop shall use
293
*/
294
virtual MSDetectorFileOutput* createInstantInductLoop(const std::string& id,
295
MSLane* lane, double pos, const std::string& od,
296
const std::string name, const std::string& vTypes,
297
const std::string& nextEdges);
298
299
300
/** @brief Creates a MSE2Collector instance, overridden by GUIE2Collector::createE2Detector()
301
*
302
* Simply calls the MSE2Collector constructor
303
*
304
* @see MSE2Collector Constructor documentation
305
*/
306
virtual MSE2Collector* createE2Detector(const std::string& id,
307
DetectorUsage usage, MSLane* lane, double pos, double endPos, double length,
308
SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
309
const std::string name, const std::string& vTypes,
310
const std::string& nextEdges,
311
int detectPersons, bool showDetector);
312
313
virtual MSE2Collector* createE2Detector(const std::string& id,
314
DetectorUsage usage, std::vector<MSLane*> lanes, double pos, double endPos,
315
SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
316
const std::string name, const std::string& vTypes,
317
const std::string& nextEdges,
318
int detectPersons, bool showDetector);
319
320
/** @brief Creates an instance of an e3 detector using the given values
321
*
322
* Simply calls the MSE3Collector constructor.
323
*
324
* @param[in] id The id the detector shall have
325
* @param[in] entries The list of this detector's entries
326
* @param[in] exits The list of this detector's exits
327
* @param[in] haltingSpeedThreshold Detector parameter: the speed a vehicle's speed must be below to be assigned as jammed
328
* @param[in] haltingTimeThreshold Detector parameter: the time a vehicle's speed must be below haltingSpeedThreshold to be assigned as jammed
329
*/
330
virtual MSDetectorFileOutput* createE3Detector(const std::string& id,
331
const CrossSectionVector& entries, const CrossSectionVector& exits,
332
double haltingSpeedThreshold, SUMOTime haltingTimeThreshold,
333
const std::string name, const std::string& vTypes,
334
const std::string& nextEdges,
335
int detectPersons, bool openEntry, bool expectArrival);
336
337
338
/** @brief Creates edge based mean data collector using the given specification
339
*
340
* @param[in] id The id the detector shall have
341
* @param[in] frequency The aggregation interval the detector shall use
342
* @param[in] begin dump begin time
343
* @param[in] end dump end time
344
* @param[in] type The type of values to be generated
345
* @param[in] useLanes Information whether lane-based or edge-based dump shall be generated
346
* @param[in] withEmpty Information whether empty lanes/edges shall be written
347
* @param[in] withInternal Information whether internal lanes/edges shall be written
348
* @param[in] trackVehicles Information whether information shall be collected per vehicle
349
* @param[in] detectPersons Whether pedestrians shall be detected instead of vehicles
350
* @param[in] maxTravelTime the maximum travel time to output
351
* @param[in] minSamples the minimum number of sample seconds before the values are valid
352
* @param[in] haltSpeed the maximum speed to consider a vehicle waiting
353
* @param[in] vTypes the set of vehicle types to consider
354
* @exception InvalidArgument If one of the values is invalid
355
*/
356
void createEdgeLaneMeanData(const std::string& id, SUMOTime frequency,
357
SUMOTime begin, SUMOTime end, const std::string& type,
358
const bool useLanes, const bool withEmpty, const bool printDefaults,
359
const bool withInternal, const bool trackVehicles, const int detectPersons,
360
const double maxTravelTime, const double minSamples,
361
const double haltSpeed, const std::string& vTypes,
362
const std::string& writeAttributes,
363
std::vector<MSEdge*> edges,
364
bool aggregate,
365
const std::string& device);
366
/// @}
367
368
369
protected:
370
/**
371
* @class E3DetectorDefinition
372
* @brief Holds the incoming definitions of an e3 detector unless the detector is build.
373
*/
374
class E3DetectorDefinition : public Parameterised {
375
public:
376
/** @brief Constructor
377
* @param[in] id The id the detector shall have
378
* @param[in] device The output device the detector shall write into
379
* @param[in] haltingSpeedThreshold Detector parameter: the speed a vehicle's speed must be below to be assigned as jammed
380
* @param[in] haltingTimeThreshold Detector parameter: the time a vehicle's speed must be below haltingSpeedThreshold to be assigned as jammed
381
* @param[in] splInterval The aggregation time span the detector shall use
382
*/
383
E3DetectorDefinition(const std::string& id,
384
const std::string& device, double haltingSpeedThreshold,
385
SUMOTime haltingTimeThreshold, SUMOTime splInterval,
386
const std::string name, const std::string& vTypes,
387
const std::string& nextEdges,
388
int detectPersons, bool openEntry, bool expectArrival);
389
390
/// @brief Destructor
391
virtual ~E3DetectorDefinition();
392
393
/// @brief The id of the detector
394
const std::string myID;
395
/// @brief The device the detector shall use
396
const std::string myDevice;
397
/// @brief The speed a vehicle's speed must be below to be assigned as jammed
398
double myHaltingSpeedThreshold;
399
/// @brief The time a vehicle's speed must be below haltingSpeedThreshold to be assigned as jammed
400
SUMOTime myHaltingTimeThreshold;
401
/// @brief List of detector's entries
402
CrossSectionVector myEntries;
403
/// @brief List of detector's exits
404
CrossSectionVector myExits;
405
/// @brief The aggregation interval
406
SUMOTime mySampleInterval;
407
/// @brief name
408
std::string myName;
409
/// @brief The types to filter
410
const std::string myVehicleTypes;
411
/// @brief The route edges to filter by
412
const std::string myNextEdges;
413
/// @brief person detection mode
414
int myDetectPersons;
415
/// @brief Whether the detector is declared as having incomplete entry detectors
416
bool myOpenEntry;
417
/// @brief Whether the detector expects vehicles to arrive inside (and doesn't issue a warning in this case)
418
bool myExpectArrival;
419
//@}
420
421
private:
422
/// @brief Invalidated copy constructor.
423
E3DetectorDefinition(const E3DetectorDefinition&);
424
425
/// @brief Invalidated assignment operator.
426
E3DetectorDefinition& operator=(const E3DetectorDefinition&);
427
428
};
429
430
431
protected:
432
/** @brief Computes the position to use
433
*
434
* At first, it is checked whether the given position is negative. If so, the
435
* position is added to the lane's length to obtain the position counted
436
* backwards.
437
*
438
* If the resulting position is beyond or in front (<0) of the lane, it is either
439
* set to the according lane's boundary (.1 or length-.1) if friendlyPos
440
* is set, or, if friendlyPos is not set, an InvalidArgument is thrown.
441
*
442
* @param[in] pos Definition of the position on the lane
443
* @param[in] lane The lane the position must be valid for
444
* @param[in] friendlyPos Whether false positions shall be made acceptable
445
* @param[in] detid The id of the currently built detector (for error message generation)
446
* @exception InvalidArgument If the defined position is invalid
447
*/
448
double getPositionChecking(double pos, MSLane* lane, bool friendlyPos,
449
SumoXMLTag tag,
450
const std::string& detid);
451
452
453
/// @name Value checking/adapting methods
454
/// @{
455
456
/** @brief Returns the named edge
457
* @param[in] edgeID The id of the lane
458
* @param[in] type The type of the detector (for error message generation)
459
* @param[in] detid The id of the currently built detector (for error message generation)
460
* @exception InvalidArgument If the named edge is not known
461
*/
462
MSEdge* getEdgeChecking(const std::string& edgeID, SumoXMLTag type,
463
const std::string& detid);
464
465
public:
466
/** @brief Returns the named lane
467
* @param[in] laneID The id of the lane
468
* @param[in] type The type of the detector (for error message generation)
469
* @param[in] detid The id of the currently built detector (for error message generation)
470
* @exception InvalidArgument If the named lane is not known
471
*/
472
MSLane* getLaneChecking(const std::string& laneID, SumoXMLTag type,
473
const std::string& detid);
474
475
protected:
476
/** @brief Checks whether the given frequency (sample interval) is valid
477
* @param[in] splInterval The sample interval
478
* @param[in] type The type of the detector (for error message generation)
479
* @param[in] id The id of the detector (for error message generation)
480
* @exception InvalidArgument If the given sample interval is invalid (<=0)
481
* @todo Why is splInterval an int???
482
*/
483
void checkSampleInterval(SUMOTime splInterval, SumoXMLTag type, const std::string& id);
484
/// @}
485
486
487
protected:
488
/// @brief The net to fill
489
MSNet& myNet;
490
491
492
private:
493
/// @brief definition of the currently parsed e3 detector
494
E3DetectorDefinition* myE3Definition;
495
496
497
private:
498
/// @brief Invalidated copy constructor.
499
NLDetectorBuilder(const NLDetectorBuilder&);
500
501
/// @brief Invalidated assignment operator.
502
NLDetectorBuilder& operator=(const NLDetectorBuilder&);
503
504
};
505
506