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