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-2020 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 
25 
26 #define SWARM_DEBUG
28 #include "MSSOTLSensors.h"
29 #include "MSSOTLDefinitions.h"
30 #include <cmath>
31 #include <map>
32 #include <utility>
34 
36 protected :
38  void buildSensorForLane(MSLane* lane, NLDetectorBuilder& nb, double sensorLength);
39  void buildContinueSensior(MSLane* lane, NLDetectorBuilder& nb, double sensorLength, MSLane* continueOnLane, double usedLength);
41  void buildSensorForOutLane(MSLane* lane, NLDetectorBuilder& nb, double sensorLength);
42 
45 
46 public:
47  /*
48  * @brief This sensor logic contructor
49  */
50  MSSOTLE2Sensors(std::string tlLogicID, const MSTrafficLightLogic::Phases* phases);
51 
52  /*
53  * @brief This sensor logic destructor
54  */
55  ~MSSOTLE2Sensors(void);
56 
58  void buildSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder& nb, double sensorLength);
60  void buildOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder& nb, double sensorLength);
63 
64  /*
65  * Returns the number of vehicles that have passed the sensor.
66  * Vehicles are effectively counted or guessed in the space from the sensor to the junction.
67  * @param[in] laneId The ID of the lane of which you want to count vehicles.
68  * @param[in] out boolean that indicate if the lane is an incoming or an outgoing one (@todo review)
69  */
70  int getPassedVeh(std::string laneId, bool out);
71 
72  /*
73  * Sets the number of vehicles that have passed the sensor.
74  * @param[in] laneId The ID of the lane of which you want to set vehicles.
75  * @param[in] passed int indicating the number of vehicles to subtract.
76  */
77  void subtractPassedVeh(std::string laneId, int passed);
78 
79  void setSpeedThresholdParam(double newThreshold) {
80  speedThresholdParam = newThreshold;
81  }
82 
83  /*
84  * Returns the number of vehicles currently approaching the
85  * junction for the given lane.
86  * Vehicles are effectively counted or guessed in the space from the sensor to the junction.
87  * @param[in] lane The lane to count vehicles
88  */
89  int countVehicles(MSLane* lane);
90 
91  /*
92  * Returns the number of vehicles currently approaching the
93  * junction for the given lane.
94  * Vehicles are effectively counted or guessed in the space from the sensor to the junction.
95  * @param[in] lane The lane to count vehicles given by ID
96  */
97  int countVehicles(std::string laneId);
98 
99  int estimateVehicles(std::string laneId);
100 
101  double getEstimateQueueLength(std::string laneId);
102  /*
103  * @param[in] The lane given by Id
104  * @return The maximum speed allowed for the given laneId
105  */
106  virtual double getMaxSpeed(std::string laneId);
107 
108  /*
109  * Returns the average speed of vehicles currently approaching or leaving the
110  * junction for the given lane.
111  * Vehicles speed is effectively sensed or guessed in the space from the sensor.
112  * @param[in] lane The lane to count vehicles
113  */
114  virtual double meanVehiclesSpeed(MSLane* lane);
115 
116  /*
117  * Returns the average speed of vehicles currently approaching or leaving the
118  * junction for the given lane.
119  * Vehicles speed is effectively sensed or guessed in the space from the sensor.
120  * @param[in] laneID The lane to count vehicles by ID
121  */
122  virtual double meanVehiclesSpeed(std::string laneId);
123 
124  /*
125  * Set the weight of the vehicle types to be used by countVehicles
126  * @param[in] the value of the param VEHICLE_TYPES_WEIGHTS. Format type1=value1; type2=value2 etc..
127  */
128  virtual void setVehicleWeigths(const std::string& weightString);
129 
130 protected:
131  int count(MSE2Collector* sensor);
132  template<typename Method, typename ValueType>
133  bool getVelueFromSensor(std::string laneId, Method function, ValueType& value) {
134  if (m_sensorMap.find(laneId) != m_sensorMap.end()) {
135  value = (m_sensorMap[laneId]->*function)();
136  return true;
137  }
138  return false;
139  }
140 
141 // MSLane_MSE2CollectorMap m_sensorMap;
144 
145 // MSLane_MSE2CollectorMap mySensorsMap_OutLanes;
146 // MSLaneID_MSE2CollectorMap mySensorsIDMap_OutLanes;
147 // MSLaneID_MaxSpeedMap myMaxSpeedMap_OutLanes;
148 
150  std::map<std::string, std::vector<std::string> > m_continueSensorOnLanes;
151  std::map<const std::string, int> m_typeWeightMap;
152 
153 };
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.