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