LCOV - code coverage report
Current view: top level - src/microsim/output - MSDetectorFileOutput.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 35 41 85.4 %
Date: 2024-05-06 15:32:35 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-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    MSDetectorFileOutput.cpp
      15             : /// @author  Christian Roessel
      16             : /// @author  Daniel Krajzewicz
      17             : /// @author  Sascha Krieg
      18             : /// @author  Michael Behrisch
      19             : /// @author  Jakob Erdmann
      20             : /// @date    2004-11-23
      21             : ///
      22             : // Base of value-generating classes (detectors)
      23             : /****************************************************************************/
      24             : #include <config.h>
      25             : 
      26             : #include <utils/common/StringTokenizer.h>
      27             : #include <microsim/MSVehicleType.h>
      28             : #include <microsim/MSEdge.h>
      29             : #include <microsim/MSRoute.h>
      30             : #include <microsim/MSVehicleControl.h>
      31             : #include <microsim/transportables/MSTransportable.h>
      32             : #include <utils/vehicle/SUMOTrafficObject.h>
      33             : #include <utils/vehicle/SUMOVehicle.h>
      34             : #include "MSDetectorFileOutput.h"
      35             : 
      36             : // ===========================================================================
      37             : // method definitions
      38             : // ===========================================================================
      39             : 
      40       25136 : MSDetectorFileOutput::MSDetectorFileOutput(const std::string& id,
      41             :         const std::string& vTypes,
      42             :         const std::string& nextEdges,
      43       25136 :         const int detectPersons) :
      44             :     Named(id),
      45       25136 :     myDetectPersons(detectPersons) {
      46       50402 :     const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
      47             :     myVehicleTypes.insert(vt.begin(), vt.end());
      48       25393 :     for (const std::string& edgeID : StringTokenizer(nextEdges).getVector()) {
      49         263 :         const MSEdge* e = MSEdge::dictionary(edgeID);
      50         263 :         if (e) {
      51         257 :             myNextEdges.push_back(e);
      52             :         } else {
      53          12 :             throw ProcessError("Unknown edge '" + edgeID + "' given as nextEdges in detector '" + id + "'");
      54             :         }
      55       25136 :     }
      56       25142 : }
      57             : 
      58             : 
      59             : bool
      60   606844958 : MSDetectorFileOutput::vehicleApplies(const SUMOTrafficObject& veh) const {
      61   606844958 :     if (veh.isVehicle() == detectPersons()) {
      62             :         return false;
      63             :     }
      64   606842857 :     if (!myVehicleTypes.empty() && myVehicleTypes.count(veh.getVehicleType().getOriginalID()) == 0) {
      65      295528 :         std::set<std::string> vTypeDists = MSNet::getInstance()->getVehicleControl().getVTypeDistributionMembership(veh.getVehicleType().getOriginalID());
      66             :         bool typeMatches = false;
      67      236204 :         for (auto vTypeDist : vTypeDists) {
      68             :             if (myVehicleTypes.count(vTypeDist) > 0) {
      69             :                 typeMatches = true;
      70             :                 break;
      71             :             }
      72             :         }
      73             :         if (!typeMatches) {
      74             :             return false;
      75             :         }
      76             :     }
      77   606695101 :     if (!myNextEdges.empty()) {
      78             :         MSRouteIterator it;
      79             :         MSRouteIterator end;
      80             :         ConstMSEdgeVector route;
      81      202178 :         if (veh.isVehicle()) {
      82        4868 :             const SUMOVehicle& v = dynamic_cast<const SUMOVehicle&>(veh);
      83        4868 :             it = v.getCurrentRouteEdge();
      84        4868 :             end = v.getRoute().end();
      85      197310 :         } else if (veh.isPerson()) {
      86      197310 :             const MSTransportable& p = dynamic_cast<const MSTransportable&>(veh);
      87      197310 :             route = p.getCurrentStage()->getEdges();
      88      197310 :             it = route.begin() + p.getRoutePosition();
      89             :             end = route.end();
      90             :         }
      91      262499 :         for (const MSEdge* e : myNextEdges) {
      92      202178 :             it = std::find(it, end, e);
      93      202178 :             if (it == end) {
      94      167634 :                 if (e != veh.getNextEdgePtr()) {
      95             :                     //std::cout << SIMTIME << " det=" << getID() << " veh=" << veh.getID() << " e=" << e->getID() << " vehNext=" << Named::getIDSecure(veh.getNextEdgePtr()) << "\n";
      96      141857 :                     return false;
      97             :                 }
      98             :             }
      99             :         }
     100             :     }
     101             :     return true;
     102             : }
     103             : 
     104             : bool
     105      355587 : MSDetectorFileOutput::personApplies(const MSTransportable& p, int dir) const {
     106             :     //std::cout << getID() << " p=" << p.getID() << " veh=" << Named::getIDSecure(p.getVehicle()) << "\n";
     107      355587 :     if (p.getVehicle() == nullptr) {
     108      355587 :         const int dirCode = dir < 0 ? 2 : dir;
     109             :         //std::cout << "   dir=" << dir << " dirCode=" << dirCode << " myDetectPersons=" << myDetectPersons << "\n";
     110      355587 :         if ((dirCode & myDetectPersons) == 0) {
     111             :             // person walking in wrong direction or not walking at all
     112      101660 :             return false;
     113             :         }
     114             :     } else {
     115           0 :         const SUMOVehicleClass svc = p.getVehicle()->getVClass();
     116             :         int vClassCode;
     117           0 :         if ((svc & SVC_PUBLIC_CLASSES) != 0) {
     118             :             vClassCode = (int)PersonMode::PUBLIC;
     119           0 :         } else if ((svc & SVC_BICYCLE) != 0) {
     120             :             vClassCode = (int)PersonMode::BICYCLE;
     121           0 :         } else if ((svc & SVC_TAXI) != 0) {
     122             :             vClassCode = (int)PersonMode::TAXI;
     123             :         } else {
     124             :             vClassCode = (int)PersonMode::CAR;
     125             :         }
     126           0 :         if ((vClassCode & myDetectPersons) == 0) {
     127             :             // person riding in the wrong vehicle
     128           0 :             return false;
     129             :         }
     130             :     }
     131             :     return true;
     132             : }
     133             : 
     134             : 
     135             : 
     136             : /****************************************************************************/

Generated by: LCOV version 1.14