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