LCOV - code coverage report
Current view: top level - src/microsim/traffic_lights - MSSOTLE2Sensors.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 101 215 47.0 %
Date: 2024-05-19 15:37:39 Functions: 16 29 55.2 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2010-2024 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    MSSOTLE2Sensors.cpp
      15             : /// @author  Gianfilippo Slager
      16             : /// @author  Alessio Bonfietti
      17             : /// @author  Federico Caselli
      18             : /// @date    2010-02-25
      19             : ///
      20             : // The class for SOTL sensors of "E2" type
      21             : /****************************************************************************/
      22             : 
      23             : #include <utils/common/StringUtils.h>
      24             : #include <microsim/output/MSDetectorControl.h>
      25             : #include <microsim/MSEdge.h>
      26             : #include <microsim/MSVehicleType.h>
      27             : #include "MSSOTLE2Sensors.h"
      28             : 
      29             : #define INVALID_POSITION std::numeric_limits<double>::max()
      30             : 
      31         384 : MSSOTLE2Sensors::MSSOTLE2Sensors(std::string tlLogicID,
      32         384 :                                  const MSTrafficLightLogic::Phases* phases) :
      33         768 :     MSSOTLSensors(tlLogicID, phases) {
      34         384 : }
      35             : 
      36         384 : MSSOTLE2Sensors::~MSSOTLE2Sensors(void) {
      37             :     //Deleting sensors takes place in the detector control
      38         384 : }
      39             : 
      40           0 : void MSSOTLE2Sensors::buildSensors(
      41             :     MSTrafficLightLogic::LaneVectorVector controlledLanes,
      42             :     NLDetectorBuilder& nb) {
      43           0 :     buildSensors(controlledLanes, nb, INPUT_SENSOR_LENGTH);
      44           0 : }
      45             : 
      46         192 : void MSSOTLE2Sensors::buildSensors(
      47             :     MSTrafficLightLogic::LaneVectorVector controlledLanes,
      48             :     NLDetectorBuilder& nb, double sensorLength) {
      49             :     //for each lane build an appropriate sensor on it
      50             :     MSLane* currentLane = nullptr;
      51             : 
      52             :     //input and ouput lanes
      53         192 :     for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
      54         960 :                 controlledLanes.begin(); laneVector != controlledLanes.end();
      55             :             laneVector++) {
      56         768 :         for (MSTrafficLightLogic::LaneVector::const_iterator lane =
      57        1536 :                     laneVector->begin(); lane != laneVector->end(); lane++) {
      58         768 :             currentLane = (*lane);
      59         768 :             buildSensorForLane(currentLane, nb, sensorLength);
      60             :         }
      61             :     }
      62         192 : }
      63             : /****************************************************************************/
      64             : /*
      65             :  * Count Sensors. Should be refactor to make a new class.
      66             :  */
      67         192 : void MSSOTLE2Sensors::buildCountSensors(
      68             :     MSTrafficLightLogic::LaneVectorVector controlledLanes,
      69             :     NLDetectorBuilder& nb) {
      70             :     //for each lane build an appropriate sensor on it
      71             :     MSLane* currentLane = nullptr;
      72             :     //input and ouput lanes
      73         192 :     for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
      74         960 :                 controlledLanes.begin(); laneVector != controlledLanes.end();
      75             :             laneVector++) {
      76         768 :         for (MSTrafficLightLogic::LaneVector::const_iterator lane =
      77        1536 :                     laneVector->begin(); lane != laneVector->end(); lane++) {
      78         768 :             currentLane = (*lane);
      79         768 :             buildCountSensorForLane(currentLane, nb);
      80             :         }
      81             :     }
      82         192 : }
      83             : 
      84         192 : void MSSOTLE2Sensors::buildCountOutSensors(
      85             :     MSTrafficLightLogic::LaneVectorVector controlledLanes,
      86             :     NLDetectorBuilder& nb) {
      87             :     //for each lane build an appropriate sensor on it
      88             :     MSLane* currentLane = nullptr;
      89             : 
      90             :     //input and ouput lanes
      91         192 :     for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
      92         384 :                 controlledLanes.begin(); laneVector != controlledLanes.end();
      93             :             laneVector++) {
      94         192 :         for (MSTrafficLightLogic::LaneVector::const_iterator lane =
      95         960 :                     laneVector->begin(); lane != laneVector->end(); lane++) {
      96         768 :             currentLane = (*lane);
      97         768 :             buildCountSensorForOutLane(currentLane, nb);
      98             :         }
      99             :     }
     100         192 : }
     101             : 
     102           0 : void MSSOTLE2Sensors::buildOutSensors(
     103             :     MSTrafficLightLogic::LaneVectorVector controlledLanes,
     104             :     NLDetectorBuilder& nb) {
     105           0 :     buildOutSensors(controlledLanes, nb, OUTPUT_SENSOR_LENGTH);
     106           0 : }
     107         192 : void MSSOTLE2Sensors::buildOutSensors(
     108             :     MSTrafficLightLogic::LaneVectorVector controlledLanes,
     109             :     NLDetectorBuilder& nb, double sensorLength) {
     110             :     //for each lane build an appropriate sensor on it
     111             :     MSLane* currentLane = nullptr;
     112             : 
     113             :     //input and ouput lanes
     114         192 :     for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
     115         384 :                 controlledLanes.begin(); laneVector != controlledLanes.end();
     116             :             laneVector++) {
     117         192 :         for (MSTrafficLightLogic::LaneVector::const_iterator lane =
     118         960 :                     laneVector->begin(); lane != laneVector->end(); lane++) {
     119         768 :             currentLane = (*lane);
     120         768 :             buildSensorForOutLane(currentLane, nb, sensorLength);
     121             :         }
     122             :     }
     123         192 : }
     124             : 
     125         768 : void MSSOTLE2Sensors::buildCountSensorForLane(MSLane* lane, NLDetectorBuilder& nb) {
     126             :     double sensorPos;
     127             :     double lensorLength;
     128             :     MSE2Collector* newSensor = nullptr;
     129             :     //Check not to have more than a sensor for lane
     130         768 :     if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
     131             : 
     132             :         //Check and set zero if the lane is not long enough for the specified sensor start
     133         768 :         sensorPos = COUNT_SENSOR_START <= lane->getLength() ? COUNT_SENSOR_START : 0;
     134             : 
     135             :         //Original:
     136             :         double sensorLength = INPUT_COUNT_SENSOR_LENGTH;
     137             : 
     138             :         //Check and trim if the lane is not long enough for the specified sensor length
     139         768 :         lensorLength = sensorLength <= (lane->getLength() - sensorPos) ? sensorLength : (lane->getLength() - sensorPos);
     140             : 
     141             :         //TODO check this lengths
     142             : //        DBG(
     143             : //            std::ostringstream phero_str;
     144             : //            phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
     145             : //            << " ,SENSOR_START  " << SENSOR_START << "; lane->getLength = "
     146             : //            << lane->getLength() << " ,lensorLength= " << lensorLength
     147             : //            << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
     148             : //            WRITE_MESSAGE(
     149             : //                "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
     150             : //        )
     151             : 
     152             :         //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
     153        2304 :         newSensor = nb.createE2Detector(
     154        1536 :                         "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
     155             :                         DU_TL_CONTROL, lane,
     156         768 :                         (lane->getLength() - sensorPos - lensorLength), INVALID_POSITION, lensorLength,
     157             :                         HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS, "", "", "", (int)PersonMode::NONE, true);
     158             : 
     159         768 :         MSNet::getInstance()->getDetectorControl().add(
     160             :             SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
     161             : 
     162         768 :         m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
     163         768 :         m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
     164             :     }
     165         768 : }
     166             : 
     167         768 : void MSSOTLE2Sensors::buildCountSensorForOutLane(MSLane* lane, NLDetectorBuilder& nb) {
     168             :     double sensorPos;
     169             :     double lensorLength;
     170             :     MSE2Collector* newSensor = nullptr;
     171             :     //Check not to have more than a sensor for lane
     172         768 :     if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
     173             : 
     174             :         //Original:
     175             :         double sensorLength = OUTPUT_COUNT_SENSOR_LENGTH;
     176             :         //Check and set zero if the lane is not long enough for the specified sensor start
     177         768 :         sensorPos = (lane->getLength() - sensorLength)
     178             :                     - (SENSOR_START <= lane->getLength() ? SENSOR_START : 0);
     179             : 
     180             :         //Check and trim if the lane is not long enough for the specified sensor length
     181             :         lensorLength =
     182         768 :             sensorLength <= (lane->getLength() - sensorPos) ?
     183             :             sensorLength : (lane->getLength() - sensorPos);
     184             : 
     185             :         //TODO check this lengths
     186             : //        DBG(
     187             : //            std::ostringstream phero_str;
     188             : //            phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
     189             : //            << " ,SENSOR_START  " << SENSOR_START << "; lane->getLength = "
     190             : //            << lane->getLength() << " ,lensorLength= " << lensorLength
     191             : //            << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
     192             : //            WRITE_MESSAGE(
     193             : //                "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
     194             : //        )
     195             : 
     196             :         //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
     197        2304 :         newSensor = nb.createE2Detector(
     198        1536 :                         "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
     199             :                         DU_TL_CONTROL, lane,
     200         768 :                         (lane->getLength() - sensorPos - lensorLength), INVALID_POSITION, lensorLength,
     201             :                         HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS, "", "", "", (int)PersonMode::NONE, true);
     202             : 
     203         768 :         MSNet::getInstance()->getDetectorControl().add(
     204             :             SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
     205             : 
     206         768 :         m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
     207         768 :         m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
     208             :     }
     209         768 : }
     210             : 
     211           0 : int MSSOTLE2Sensors::getPassedVeh(std::string laneId, bool /* out */) {
     212             :     MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
     213             :     sensorsIterator = m_sensorMap.find(laneId);
     214           0 :     if (sensorsIterator == m_sensorMap.end()) {
     215             :         assert(0);
     216             :         return 0;
     217             :     } else {
     218             :         int additional = 0;
     219           0 :         if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end())
     220           0 :             for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
     221           0 :                 int tmp = 0;
     222           0 :                 if (getVelueFromSensor(*it, &MSE2Collector::getPassedVeh, tmp)) {
     223           0 :                     additional += tmp;
     224             :                 }
     225             :             }
     226           0 :         return sensorsIterator->second->getPassedVeh() + additional;
     227             :     }
     228             : }
     229             : 
     230             : void
     231           0 : MSSOTLE2Sensors::subtractPassedVeh(std::string laneId, int passed) {
     232             :     //TODO Ivan: ciclare tutti i sensori di count e resettare passedVeh
     233             :     MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
     234             : 
     235             :     sensorsIterator = m_sensorMap.find(laneId);
     236           0 :     if (sensorsIterator != m_sensorMap.end()) {
     237           0 :         sensorsIterator->second->subtractPassedVeh(passed);
     238             :     }
     239           0 : }
     240             : 
     241             : /*******************************************************************************/
     242             : 
     243           0 : void MSSOTLE2Sensors::buildSensorForLane(MSLane* lane, NLDetectorBuilder& nb) {
     244           0 :     buildSensorForLane(lane, nb, INPUT_SENSOR_LENGTH);
     245           0 : }
     246             : 
     247             : 
     248             : 
     249         768 : void MSSOTLE2Sensors::buildSensorForLane(MSLane* lane, NLDetectorBuilder& nb, double sensorLength) {
     250             :     const MSEdge* edge = &lane->getEdge();
     251         768 :     if (edge->isInternal() || edge->isWalkingArea() || edge->isCrossing()) {
     252             :         return;
     253             :     }
     254             :     double sensorPos;
     255             :     double lensorLength;
     256             :     MSE2Collector* newSensor = nullptr;
     257             :     //Check not to have more than a sensor for lane
     258         768 :     if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
     259             : 
     260             :         //Check and set zero if the lane is not long enough for the specified sensor start
     261             :         sensorPos = SENSOR_START <= lane->getLength() ? SENSOR_START : 0;
     262             :         //Check and trim if the lane is not long enough for the specified sensor length
     263         768 :         lensorLength = sensorLength <= (lane->getLength() - sensorPos) ? sensorLength : (lane->getLength() - sensorPos);
     264             :         //TODO check this lengths
     265             : //        DBG(
     266             : //            std::ostringstream phero_str;
     267             : //            phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
     268             : //            << " ,SENSOR_START  " << SENSOR_START << "; lane->getLength = "
     269             : //            << lane->getLength() << " ,lensorLength= " << lensorLength
     270             : //            << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
     271             : //            WRITE_MESSAGE(
     272             : //                "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
     273             : //        )
     274             : 
     275             :         //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
     276        2304 :         newSensor = nb.createE2Detector(
     277        1536 :                         "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
     278             :                         DU_TL_CONTROL, lane,
     279             :                         (lane->getLength() - sensorPos - lensorLength), INVALID_POSITION, lensorLength,
     280             :                         HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS, "", "", "", (int)PersonMode::NONE, true);
     281             : 
     282         768 :         MSNet::getInstance()->getDetectorControl().add(SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
     283             : 
     284         768 :         m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
     285         768 :         m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
     286             :         //Avoid creating really small sensors. Only add a further sensors if the one created is less than 90% the requested length
     287         768 :         if (lensorLength < sensorLength * 0.9) {
     288           0 :             std::ostringstream oss;
     289           0 :             oss << "Sensor on lane " << lane->getID() << " is long " << lensorLength << ", while it should be " << sensorLength << ". Continuing it on the other lanes if possible";
     290           0 :             WRITE_MESSAGE(oss.str())
     291           0 :             for (const MSLane::IncomingLaneInfo& it : lane->getIncomingLanes()) {
     292           0 :                 const MSEdge& inEdge = it.lane->getEdge();
     293           0 :                 if (!inEdge.isInternal() && !inEdge.isWalkingArea() && !inEdge.isCrossing()) {
     294           0 :                     buildContinueSensior(lane, nb, sensorLength, it.lane, lensorLength);
     295             :                 }
     296             :             }
     297           0 :         }
     298             :     }
     299             : }
     300             : 
     301           0 : void MSSOTLE2Sensors::buildContinueSensior(MSLane* lane, NLDetectorBuilder& nb, double sensorLength, MSLane* continueOnLane, double usedLength) {
     302           0 :     double availableLength = sensorLength - usedLength;
     303           0 :     if (m_sensorMap.find(continueOnLane->getID()) == m_sensorMap.end()) {
     304           0 :         double length = availableLength <= continueOnLane->getLength() ? availableLength : continueOnLane->getLength();
     305           0 :         MSE2Collector* newSensor = nb.createE2Detector(
     306           0 :                                        "SOTL_E2_lane:" + continueOnLane->getID() + "_tl:" + tlLogicID,
     307             :                                        DU_TL_CONTROL, continueOnLane,
     308             :                                        (continueOnLane->getLength() - length), INVALID_POSITION, length,
     309             :                                        HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS, "", "", "", (int)PersonMode::NONE, true);
     310           0 :         MSNet::getInstance()->getDetectorControl().add(SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
     311           0 :         m_sensorMap.insert(MSLaneID_MSE2Collector(continueOnLane->getID(), newSensor));
     312           0 :         m_continueSensorOnLanes[lane->getID()].push_back(continueOnLane->getID());
     313           0 :         std::ostringstream oss;
     314           0 :         oss << "Continue sensor on lane " << continueOnLane->getID() << ". Current length " << (length + usedLength);
     315           0 :         WRITE_MESSAGE(oss.str())
     316             :         //Continue other line if needed.
     317           0 :         if (length + usedLength < sensorLength * 0.9) {
     318           0 :             for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = continueOnLane->getIncomingLanes().begin(); it != continueOnLane->getIncomingLanes().end(); ++it) {
     319           0 :                 const MSEdge* edge = &it->lane->getEdge();
     320           0 :                 if (!edge->isInternal() && !edge->isWalkingArea() && !edge->isCrossing()) {
     321           0 :                     buildContinueSensior(lane, nb, sensorLength, it->lane, length + usedLength);
     322             :                 }
     323             :             }
     324             :         }
     325           0 :     }
     326           0 : }
     327             : 
     328           0 : void MSSOTLE2Sensors::buildSensorForOutLane(MSLane* lane,
     329             :         NLDetectorBuilder& nb) {
     330           0 :     buildSensorForOutLane(lane, nb, OUTPUT_SENSOR_LENGTH);
     331           0 : }
     332             : 
     333         768 : void MSSOTLE2Sensors::buildSensorForOutLane(MSLane* lane,
     334             :         NLDetectorBuilder& nb, double sensorLength) {
     335             :     double sensorPos;
     336             :     double lensorLength;
     337             :     MSE2Collector* newSensor = nullptr;
     338             :     //Check not to have more than a sensor for lane
     339         768 :     if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
     340             : 
     341             :         //Original:
     342             :         //double sensorLength = OUTPUT_SENSOR_LENGTH;
     343             :         //Check and set zero if the lane is not long enough for the specified sensor start
     344         768 :         sensorPos = (lane->getLength() - sensorLength)
     345             :                     - (SENSOR_START <= lane->getLength() ? SENSOR_START : 0);
     346             : 
     347             :         //Check and trim if the lane is not long enough for the specified sensor length
     348             :         lensorLength =
     349         768 :             sensorLength <= (lane->getLength() - sensorPos) ?
     350             :             sensorLength : (lane->getLength() - sensorPos);
     351             : 
     352             :         //TODO check this lengths
     353             : //        DBG(
     354             : //            std::ostringstream phero_str;
     355             : //            phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
     356             : //            << " ,SENSOR_START  " << SENSOR_START << "; lane->getLength = "
     357             : //            << lane->getLength() << " ,lensorLength= " << lensorLength
     358             : //            << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
     359             : //            WRITE_MESSAGE(
     360             : //                "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
     361             : //        )
     362             : 
     363             :         //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
     364        2304 :         newSensor = nb.createE2Detector(
     365        1536 :                         "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
     366             :                         DU_TL_CONTROL, lane,
     367         768 :                         (lane->getLength() - sensorPos - lensorLength), INVALID_POSITION, lensorLength,
     368             :                         HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS, "", "", "", (int)PersonMode::NONE, true);
     369             : 
     370         768 :         MSNet::getInstance()->getDetectorControl().add(
     371             :             SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
     372             : 
     373         768 :         m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
     374         768 :         m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
     375             :     }
     376         768 : }
     377             : 
     378        7256 : int MSSOTLE2Sensors::countVehicles(MSLane* lane) {
     379       14512 :     return countVehicles(lane->getID());
     380             : }
     381             : 
     382             : /*
     383             :  * Estimate queue length according to the distance of the last vehicles
     384             :  */
     385             : 
     386           0 : double MSSOTLE2Sensors::getEstimateQueueLength(std::string laneId) {
     387             :     MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator = m_sensorMap.find(laneId);
     388           0 :     if (sensorsIterator == m_sensorMap.end()) {
     389             :         assert(0);
     390             :         return 0;
     391             :     } else {
     392           0 :         double estQL = sensorsIterator->second->getEstimateQueueLength();
     393           0 :         if (estQL == -1) {
     394             :             return 0;
     395             :         } else
     396             : //            DBG(
     397             : //                std::ostringstream str;
     398             : //                str << "MSSOTLE2Sensors::getEstimateQueueLength lane " << sensorsIterator->second->getLane()->getID()
     399             : //                << " laneLength " << sensorsIterator->second->getLane()->getLength() << " estimateQueueLength " <<  estQL;
     400             : //                WRITE_MESSAGE(str.str());
     401             : //            )
     402             :         {
     403           0 :             return estQL;
     404             :         }
     405             :     }
     406             : }
     407             : 
     408             : /*
     409             :  * Estimate queue length according to the distance of the last vehicles that exceed a threshold
     410             :  */
     411             : 
     412           0 : int MSSOTLE2Sensors::estimateVehicles(std::string laneId) {
     413             :     MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator = m_sensorMap.find(laneId);
     414           0 :     if (sensorsIterator == m_sensorMap.end()) {
     415             :         assert(0);
     416             :         return 0;
     417             :     }
     418             :     int additional = 0;
     419           0 :     if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end())
     420           0 :         for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
     421           0 :             if (m_sensorMap.find(*it) != m_sensorMap.end()) {
     422           0 :                 additional += m_sensorMap[*it]->getEstimatedCurrentVehicleNumber(speedThresholdParam);
     423             :             }
     424             :         }
     425           0 :     return sensorsIterator->second->getEstimatedCurrentVehicleNumber(speedThresholdParam) + additional;
     426             : }
     427             : 
     428      709960 : int MSSOTLE2Sensors::countVehicles(std::string laneId) {
     429             :     MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator = m_sensorMap.find(laneId);
     430      709960 :     if (sensorsIterator == m_sensorMap.end()) {
     431             :         assert(0);
     432             :         return 0;
     433             :     }
     434             :     int additional = 0;
     435      709960 :     if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end()) {
     436           0 :         for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
     437           0 :             if (m_sensorMap.find(*it) != m_sensorMap.end()) {
     438           0 :                 additional += count(m_sensorMap[*it]);
     439             :             }
     440             :         }
     441             :     }
     442      709960 :     return count(sensorsIterator->second) + additional;
     443             : }
     444             : 
     445      255616 : double MSSOTLE2Sensors::getMaxSpeed(std::string laneId) {
     446             :     MSLaneID_MaxSpeedMap::const_iterator sensorsIteratorIn = m_maxSpeedMap.find(laneId);
     447      255616 :     if (sensorsIteratorIn == m_maxSpeedMap.end()) {
     448             :         assert(0);
     449           0 :         WRITE_ERROR("MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
     450           0 :         return 0;
     451             :     }
     452      255616 :     return sensorsIteratorIn->second;
     453             : }
     454             : 
     455           0 : double MSSOTLE2Sensors::meanVehiclesSpeed(MSLane* lane) {
     456           0 :     return meanVehiclesSpeed(lane->getID());
     457             : }
     458             : 
     459      255616 : double MSSOTLE2Sensors::meanVehiclesSpeed(std::string laneId) {
     460             :     MSLaneID_MSE2CollectorMap::const_iterator sensorsIteratorOut = m_sensorMap.find(laneId);
     461      255616 :     if (sensorsIteratorOut == m_sensorMap.end()) {
     462             :         assert(0);
     463           0 :         WRITE_ERROR("MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
     464           0 :         return 0;
     465             :     }
     466             :     double meanSpeedAcc = 0;
     467             :     int totalCarNumer = 0;
     468      255616 :     if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end())
     469           0 :         for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
     470           0 :             int number = 0;
     471           0 :             double mean = -1;
     472           0 :             if (!getVelueFromSensor(*it, &MSE2Collector::getCurrentVehicleNumber, number)) {
     473           0 :                 continue;
     474             :             }
     475           0 :             totalCarNumer += number;
     476           0 :             getVelueFromSensor(*it, &MSE2Collector::getCurrentMeanSpeed, mean);
     477           0 :             meanSpeedAcc += mean * (double) number;
     478             :         }
     479      255616 :     int number = sensorsIteratorOut->second->getCurrentVehicleNumber();
     480      255616 :     totalCarNumer += number;
     481      255616 :     double mean = sensorsIteratorOut->second->getCurrentMeanSpeed();
     482      255616 :     meanSpeedAcc += mean * (double) number;
     483      255616 :     return totalCarNumer == 0 ? -1 : meanSpeedAcc / (double) totalCarNumer;
     484             : }
     485             : 
     486           0 : std::string trim(std::string& str) {
     487           0 :     int first = (int)str.find_first_not_of(' ');
     488           0 :     int last = (int)str.find_last_not_of(' ');
     489           0 :     return str.substr(first, (last - first + 1));
     490             : }
     491             : 
     492           0 : std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems) {
     493           0 :     std::stringstream ss(s);
     494             :     std::string item;
     495           0 :     while (std::getline(ss, item, delim)) {
     496           0 :         if (!item.empty()) {
     497           0 :             elems.push_back(item);
     498             :         }
     499             :     }
     500           0 :     return elems;
     501           0 : }
     502             : 
     503           0 : void MSSOTLE2Sensors::setVehicleWeigths(const std::string& weightString) {
     504             :     std::vector<std::string> types;
     505           0 :     split(weightString, ';', types);
     506           0 :     std::ostringstream logstr;
     507           0 :     logstr << "[MSSOTLE2Sensors::setVehicleWeigths] ";
     508           0 :     for (std::vector<std::string>::iterator typesIt = types.begin(); typesIt != types.end(); ++typesIt) {
     509             :         std::vector<std::string> typeWeight;
     510           0 :         split(*typesIt, '=', typeWeight);
     511           0 :         if (typeWeight.size() == 2) {
     512           0 :             std::string type = trim(typeWeight[0]);
     513           0 :             int value = StringUtils::toInt(typeWeight[1]);
     514           0 :             logstr << type << "=" << value << " ";
     515           0 :             m_typeWeightMap[type] = value;
     516             :         }
     517           0 :     }
     518           0 :     WRITE_MESSAGE(logstr.str());
     519           0 : }
     520             : 
     521      709960 : int MSSOTLE2Sensors::count(MSE2Collector* sensor) {
     522      709960 :     int totCars = sensor->getCurrentVehicleNumber();
     523      709960 :     if (m_typeWeightMap.size() == 0) {
     524             :         return totCars;
     525             :     }
     526             :     int number = 0;
     527           0 :     const std::vector<MSE2Collector::VehicleInfo*> vehicles = sensor->getCurrentVehicles();
     528           0 :     std::ostringstream logstr;
     529           0 :     logstr << "[MSSOTLE2Sensors::count]";
     530           0 :     for (std::vector<MSE2Collector::VehicleInfo*>::const_iterator vit = vehicles.begin(); vit != vehicles.end(); ++vit) {
     531           0 :         if ((*vit)->onDetector) {
     532             :             const std::string vtype = (*vit)->type;
     533           0 :             if (m_typeWeightMap.find(vtype) != m_typeWeightMap.end()) {
     534           0 :                 number += m_typeWeightMap[vtype];
     535             : //                DBG(logstr << " Added " << m_typeWeightMap[vtype] << " for vtype " << vtype;)
     536             :             } else {
     537           0 :                 ++number;
     538             :             }
     539             :         }
     540             :     }
     541             : //    DBG(if (totCars != number) {
     542             : //    logstr << ". Real number " << totCars << "; weighted " << number;
     543             : //    WRITE_MESSAGE(logstr.str());
     544             : //    })
     545             :     return number;
     546           0 : }

Generated by: LCOV version 1.14