LCOV - code coverage report
Current view: top level - src/libsumo - MultiEntryExit.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 84 90 93.3 %
Date: 2024-04-27 15:34:54 Functions: 24 29 82.8 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2012-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    MultiEntryExit.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Mario Krumnow
      17             : /// @author  Jakob Erdmann
      18             : /// @author  Michael Behrisch
      19             : /// @date    30.05.2012
      20             : ///
      21             : // C++ TraCI client API implementation
      22             : /****************************************************************************/
      23             : #include <config.h>
      24             : 
      25             : #include <microsim/output/MSDetectorControl.h>
      26             : #include <microsim/output/MSE2Collector.h>
      27             : #include <microsim/MSNet.h>
      28             : #include <libsumo/Helper.h>
      29             : #include <libsumo/TraCIConstants.h>
      30             : #include "MultiEntryExit.h"
      31             : 
      32             : 
      33             : namespace libsumo {
      34             : // ===========================================================================
      35             : // static member initializations
      36             : // ===========================================================================
      37             : SubscriptionResults MultiEntryExit::mySubscriptionResults;
      38             : ContextSubscriptionResults MultiEntryExit::myContextSubscriptionResults;
      39             : 
      40             : 
      41             : // ===========================================================================
      42             : // static member definitions
      43             : // ===========================================================================
      44             : std::vector<std::string>
      45         377 : MultiEntryExit::getIDList() {
      46             :     std::vector<std::string> ids;
      47         377 :     MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids);
      48         375 :     return ids;
      49           2 : }
      50             : 
      51             : 
      52             : int
      53           9 : MultiEntryExit::getIDCount() {
      54           9 :     return (int)MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).size();
      55             : }
      56             : 
      57             : 
      58             : std::vector<std::string>
      59           6 : MultiEntryExit::getEntryLanes(const std::string& detID) {
      60             :     std::vector<std::string> ids;
      61          12 :     for (const MSCrossSection& cs : getDetector(detID)->getEntries()) {
      62           6 :         ids.push_back(cs.myLane->getID());
      63             :     }
      64           6 :     return ids;
      65           0 : }
      66             : 
      67             : 
      68             : std::vector<std::string>
      69           6 : MultiEntryExit::getExitLanes(const std::string& detID) {
      70             :     std::vector<std::string> ids;
      71          12 :     for (const MSCrossSection& cs : getDetector(detID)->getExits()) {
      72           6 :         ids.push_back(cs.myLane->getID());
      73             :     }
      74           6 :     return ids;
      75           0 : }
      76             : 
      77             : 
      78             : std::vector<double>
      79           6 : MultiEntryExit::getEntryPositions(const std::string& detID) {
      80             :     std::vector<double> pos;
      81          12 :     for (const MSCrossSection& cs : getDetector(detID)->getEntries()) {
      82           6 :         pos.push_back(cs.myPosition);
      83             :     }
      84           6 :     return pos;
      85             : }
      86             : 
      87             : 
      88             : std::vector<double>
      89           6 : MultiEntryExit::getExitPositions(const std::string& detID) {
      90             :     std::vector<double> pos;
      91          12 :     for (const MSCrossSection& cs : getDetector(detID)->getExits()) {
      92           6 :         pos.push_back(cs.myPosition);
      93             :     }
      94           6 :     return pos;
      95             : }
      96             : 
      97             : 
      98             : int
      99         727 : MultiEntryExit::getLastStepVehicleNumber(const std::string& detID) {
     100         727 :     return getDetector(detID)->getVehiclesWithin();
     101             : }
     102             : 
     103             : 
     104             : double
     105          48 : MultiEntryExit::getLastStepMeanSpeed(const std::string& detID) {
     106          48 :     return getDetector(detID)->getCurrentMeanSpeed();
     107             : }
     108             : 
     109             : 
     110             : std::vector<std::string>
     111         288 : MultiEntryExit::getLastStepVehicleIDs(const std::string& detID) {
     112         288 :     return getDetector(detID)->getCurrentVehicleIDs();
     113             : }
     114             : 
     115             : 
     116             : int
     117           6 : MultiEntryExit::getLastStepHaltingNumber(const std::string& detID) {
     118           6 :     return getDetector(detID)->getCurrentHaltingNumber();
     119             : }
     120             : 
     121             : 
     122             : double
     123          12 : MultiEntryExit::getLastIntervalMeanTravelTime(const std::string& detID) {
     124          12 :     return getDetector(detID)->getLastIntervalMeanTravelTime();
     125             : }
     126             : 
     127             : 
     128             : double
     129          12 : MultiEntryExit::getLastIntervalMeanHaltsPerVehicle(const std::string& detID) {
     130          12 :     return getDetector(detID)->getLastIntervalMeanHaltsPerVehicle();
     131             : }
     132             : 
     133             : 
     134             : double
     135          12 : MultiEntryExit::getLastIntervalMeanTimeLoss(const std::string& detID) {
     136          12 :     return getDetector(detID)->getLastIntervalMeanTimeLoss();
     137             : }
     138             : 
     139             : 
     140             : int
     141          12 : MultiEntryExit::getLastIntervalVehicleSum(const std::string& detID) {
     142          12 :     return getDetector(detID)->getLastIntervalVehicleSum();
     143             : }
     144             : 
     145             : 
     146             : std::string
     147          12 : MultiEntryExit::getParameter(const std::string& detID, const std::string& param) {
     148          24 :     return getDetector(detID)->getParameter(param, "");
     149             : }
     150             : 
     151             : 
     152           0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(MultiEntryExit)
     153             : 
     154             : 
     155             : void
     156           6 : MultiEntryExit::setParameter(const std::string& detID, const std::string& name, const std::string& value) {
     157           6 :     getDetector(detID)->setParameter(name, value);
     158           6 : }
     159             : 
     160             : 
     161         162 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(MultiEntryExit, MULTIENTRYEXIT)
     162             : 
     163             : 
     164             : MSE3Collector*
     165        1344 : MultiEntryExit::getDetector(const std::string& id) {
     166        2687 :     MSE3Collector* e3 = dynamic_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id));
     167        1344 :     if (e3 == nullptr) {
     168           2 :         throw TraCIException("Multi entry exit detector '" + id + "' is not known");
     169             :     }
     170        1343 :     return e3;
     171             : }
     172             : 
     173             : 
     174             : std::shared_ptr<VariableWrapper>
     175         267 : MultiEntryExit::makeWrapper() {
     176         267 :     return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
     177             : }
     178             : 
     179             : 
     180             : bool
     181        1208 : MultiEntryExit::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
     182        1208 :     switch (variable) {
     183         243 :         case TRACI_ID_LIST:
     184         243 :             return wrapper->wrapStringList(objID, variable, getIDList());
     185           7 :         case ID_COUNT:
     186           7 :             return wrapper->wrapInt(objID, variable, getIDCount());
     187         645 :         case LAST_STEP_VEHICLE_NUMBER:
     188         645 :             return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
     189          46 :         case LAST_STEP_MEAN_SPEED:
     190          46 :             return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
     191         206 :         case LAST_STEP_VEHICLE_ID_LIST:
     192         206 :             return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
     193           4 :         case LAST_STEP_VEHICLE_HALTING_NUMBER:
     194           4 :             return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
     195           8 :         case VAR_LAST_INTERVAL_TRAVELTIME:
     196           8 :             return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTravelTime(objID));
     197           8 :         case VAR_LAST_INTERVAL_MEAN_HALTING_NUMBER:
     198           8 :             return wrapper->wrapDouble(objID, variable, getLastIntervalMeanHaltsPerVehicle(objID));
     199           8 :         case VAR_TIMELOSS:
     200           8 :             return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTimeLoss(objID));
     201           8 :         case VAR_LAST_INTERVAL_VEHICLE_NUMBER:
     202           8 :             return wrapper->wrapInt(objID, variable, getLastIntervalVehicleSum(objID));
     203           4 :         case VAR_LANES:
     204           4 :             return wrapper->wrapStringList(objID, variable, getEntryLanes(objID));
     205           4 :         case VAR_EXIT_LANES:
     206           4 :             return wrapper->wrapStringList(objID, variable, getExitLanes(objID));
     207           4 :         case VAR_POSITION:
     208           8 :             return wrapper->wrapDoubleList(objID, variable, getEntryPositions(objID));
     209           4 :         case VAR_EXIT_POSITIONS:
     210           8 :             return wrapper->wrapDoubleList(objID, variable, getExitPositions(objID));
     211           8 :         case libsumo::VAR_PARAMETER:
     212           8 :             paramData->readUnsignedByte();
     213          16 :             return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
     214           0 :         case libsumo::VAR_PARAMETER_WITH_KEY:
     215           0 :             paramData->readUnsignedByte();
     216           0 :             return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
     217             :         default:
     218             :             return false;
     219             :     }
     220             : }
     221             : 
     222             : 
     223             : }
     224             : 
     225             : 
     226             : /****************************************************************************/

Generated by: LCOV version 1.14