Eclipse SUMO - Simulation of Urban MObility
MSSOTLE2Sensors.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2010-2022 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 /****************************************************************************/
19 // The class for SOTL sensors of "E2" type
20 // XXX: Not tested with MSMultiLaneE2Collector (Generalization of MSE2Collector). If this is to be used in the future and you run into problems,
21 // start taking a look at the getEstimateQueueLength() method of the collector.
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 
27 #include <cmath>
28 #include <map>
29 #include <utility>
31 #include "MSSOTLSensors.h"
32 #include "MSSOTLDefinitions.h"
33 
35 protected :
37  void buildSensorForLane(MSLane* lane, NLDetectorBuilder& nb, double sensorLength);
38  void buildContinueSensior(MSLane* lane, NLDetectorBuilder& nb, double sensorLength, MSLane* continueOnLane, double usedLength);
40  void buildSensorForOutLane(MSLane* lane, NLDetectorBuilder& nb, double sensorLength);
41 
44 
45 public:
46  /*
47  * @brief This sensor logic contructor
48  */
49  MSSOTLE2Sensors(std::string tlLogicID, const MSTrafficLightLogic::Phases* phases);
50 
51  /*
52  * @brief This sensor logic destructor
53  */
54  ~MSSOTLE2Sensors(void);
55 
57  void buildSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder& nb, double sensorLength);
59  void buildOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder& nb, double sensorLength);
62 
63  /*
64  * Returns the number of vehicles that have passed the sensor.
65  * Vehicles are effectively counted or guessed in the space from the sensor to the junction.
66  * @param[in] laneId The ID of the lane of which you want to count vehicles.
67  * @param[in] out boolean that indicate if the lane is an incoming or an outgoing one (@todo review)
68  */
69  int getPassedVeh(std::string laneId, bool out);
70 
71  /*
72  * Sets the number of vehicles that have passed the sensor.
73  * @param[in] laneId The ID of the lane of which you want to set vehicles.
74  * @param[in] passed int indicating the number of vehicles to subtract.
75  */
76  void subtractPassedVeh(std::string laneId, int passed);
77 
78  void setSpeedThresholdParam(double newThreshold) {
79  speedThresholdParam = newThreshold;
80  }
81 
82  /*
83  * Returns the number of vehicles currently approaching the
84  * junction for the given lane.
85  * Vehicles are effectively counted or guessed in the space from the sensor to the junction.
86  * @param[in] lane The lane to count vehicles
87  */
88  int countVehicles(MSLane* lane);
89 
90  /*
91  * Returns the number of vehicles currently approaching the
92  * junction for the given lane.
93  * Vehicles are effectively counted or guessed in the space from the sensor to the junction.
94  * @param[in] lane The lane to count vehicles given by ID
95  */
96  int countVehicles(std::string laneId);
97 
98  int estimateVehicles(std::string laneId);
99 
100  double getEstimateQueueLength(std::string laneId);
101  /*
102  * @param[in] The lane given by Id
103  * @return The maximum speed allowed for the given laneId
104  */
105  virtual double getMaxSpeed(std::string laneId);
106 
107  /*
108  * Returns the average speed of vehicles currently approaching or leaving the
109  * junction for the given lane.
110  * Vehicles speed is effectively sensed or guessed in the space from the sensor.
111  * @param[in] lane The lane to count vehicles
112  */
113  virtual double meanVehiclesSpeed(MSLane* lane);
114 
115  /*
116  * Returns the average speed of vehicles currently approaching or leaving the
117  * junction for the given lane.
118  * Vehicles speed is effectively sensed or guessed in the space from the sensor.
119  * @param[in] laneID The lane to count vehicles by ID
120  */
121  virtual double meanVehiclesSpeed(std::string laneId);
122 
123  /*
124  * Set the weight of the vehicle types to be used by countVehicles
125  * @param[in] the value of the param VEHICLE_TYPES_WEIGHTS. Format type1=value1; type2=value2 etc..
126  */
127  virtual void setVehicleWeigths(const std::string& weightString);
128 
129 protected:
130  int count(MSE2Collector* sensor);
131  template<typename Method, typename ValueType>
132  bool getVelueFromSensor(std::string laneId, Method function, ValueType& value) {
133  if (m_sensorMap.find(laneId) != m_sensorMap.end()) {
134  value = (m_sensorMap[laneId]->*function)();
135  return true;
136  }
137  return false;
138  }
139 
140 // MSLane_MSE2CollectorMap m_sensorMap;
143 
144 // MSLane_MSE2CollectorMap mySensorsMap_OutLanes;
145 // MSLaneID_MSE2CollectorMap mySensorsIDMap_OutLanes;
146 // MSLaneID_MaxSpeedMap myMaxSpeedMap_OutLanes;
147 
149  std::map<std::string, std::vector<std::string> > m_continueSensorOnLanes;
150  std::map<const std::string, int> m_typeWeightMap;
151 
152 };
std::map< std::string, MSE2Collector * > MSLaneID_MSE2CollectorMap
std::map< std::string, double > MSLaneID_MaxSpeedMap
An areal detector corresponding to a sequence of consecutive lanes.
Definition: MSE2Collector.h:79
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
void buildSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
This function member has to be extended to properly build sensors for the input lanes Sensors has to ...
void buildSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
This function member has to be extended to properly build a sensor for a specific input lane Sensors ...
MSSOTLE2Sensors(std::string tlLogicID, const MSTrafficLightLogic::Phases *phases)
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
int estimateVehicles(std::string laneId)
virtual double meanVehiclesSpeed(MSLane *lane)
std::map< const std::string, int > m_typeWeightMap
int count(MSE2Collector *sensor)
void buildCountSensorForOutLane(MSLane *lane, NLDetectorBuilder &nb)
MSLaneID_MaxSpeedMap m_maxSpeedMap
void subtractPassedVeh(std::string laneId, int passed)
int countVehicles(MSLane *lane)
double speedThresholdParam
void buildOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
This function member has to be extended to properly build sensors for the output lanes Sensors has to...
void buildSensorForOutLane(MSLane *lane, NLDetectorBuilder &nb)
This function member has to be extended to properly build a sensor for a specific output lane Sensors...
MSLaneID_MSE2CollectorMap m_sensorMap
virtual void setVehicleWeigths(const std::string &weightString)
void setSpeedThresholdParam(double newThreshold)
virtual double getMaxSpeed(std::string laneId)
void buildCountSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
int getPassedVeh(std::string laneId, bool out)
double getEstimateQueueLength(std::string laneId)
void buildCountSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
bool getVelueFromSensor(std::string laneId, Method function, ValueType &value)
void buildContinueSensior(MSLane *lane, NLDetectorBuilder &nb, double sensorLength, MSLane *continueOnLane, double usedLength)
std::map< std::string, std::vector< std::string > > m_continueSensorOnLanes
std::string tlLogicID
Definition: MSSOTLSensors.h:34
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Builds detectors for microsim.