LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSPModel_Interacting.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 96.2 % 52 50
Test Date: 2024-10-24 15:46:30 Functions: 90.9 % 11 10

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2014-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    MSPModel_Interacting.cpp
      15              : /// @author  Jakob Erdmann
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 13 Jan 2014
      18              : ///
      19              : // The pedestrian following model (prototype)
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <microsim/MSGlobals.h>
      24              : #include <microsim/MSLane.h>
      25              : #include <microsim/MSLink.h>
      26              : #include <microsim/MSNet.h>
      27              : #include "MSPModel_Interacting.h"
      28              : 
      29              : // #define DEBUG_INTERACTING
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // static members
      34              : // ===========================================================================
      35              : MSPModel_Interacting::Pedestrians MSPModel_Interacting::noPedestrians;
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // MSPModel_Interacting method definitions
      40              : // ===========================================================================
      41         5080 : MSPModel_Interacting::~MSPModel_Interacting() {
      42         5080 :     clearState();
      43         5080 : }
      44              : 
      45              : 
      46              : void
      47        10185 : MSPModel_Interacting::clearState() {
      48              :     myActiveLanes.clear();
      49        10185 :     myNumActivePedestrians = 0;
      50        10185 :     myAmActive = false;
      51        10185 : }
      52              : 
      53              : 
      54              : void
      55         1472 : MSPModel_Interacting::remove(MSTransportableStateAdapter* state) {
      56         1472 :     Pedestrians& pedestrians = myActiveLanes[state->getLane()];
      57         1472 :     MSPModel_InteractingState* const p = static_cast<MSPModel_InteractingState*>(state);
      58         1472 :     const auto& it = std::find(pedestrians.begin(), pedestrians.end(), p);
      59         1472 :     if (it != pedestrians.end()) {
      60         1472 :         if (p->getNextCrossing() != nullptr) {
      61           26 :             unregisterCrossingApproach(*p, p->getNextCrossing());
      62              :         }
      63              :         pedestrians.erase(it);
      64         1472 :         myNumActivePedestrians--;
      65              :     }
      66         1472 : }
      67              : 
      68              : 
      69              : bool
      70      4048964 : MSPModel_Interacting::blockedAtDist(const SUMOTrafficObject* ego, const MSLane* lane, double vehSide, double vehWidth,
      71              :                                     double oncomingGap, std::vector<const MSPerson*>* collectBlockers) {
      72      4118752 :     for (const MSPModel_InteractingState* ped : getPedestrians(lane)) {
      73       662967 :         const double leaderFrontDist = (ped->getDirection() == FORWARD ? vehSide - ped->getEdgePos(0) : ped->getEdgePos(0) - vehSide);
      74       662967 :         const double leaderBackDist = leaderFrontDist + ped->getPerson()->getVehicleType().getLength();
      75              : #ifdef DEBUG_INTERACTING
      76              :         if DEBUGCOND(ped) {
      77              :             std::cout << SIMTIME << " lane=" << lane->getID() << " dir=" << ped->getDirection() << " pX=" << ped->getEdgePos(0) << " pL=" << ped.getLength()
      78              :                       << " vehSide=" << vehSide
      79              :                       << " vehWidth=" << vehWidth
      80              :                       << " lBD=" << leaderBackDist
      81              :                       << " lFD=" << leaderFrontDist
      82              :                       << "\n";
      83              :         }
      84              : #endif
      85       662967 :         if (leaderBackDist >= -vehWidth
      86       662967 :                 && (leaderFrontDist < 0
      87              :                     // give right of way to (close) approaching pedestrians unless they are standing
      88       288698 :                     || (leaderFrontDist <= oncomingGap && ped->getWaitingTime() < TIME2STEPS(2.0)))) {
      89       593209 :             if (MSLink::ignoreFoe(ego, ped->getPerson())) {
      90           30 :                 continue;
      91              :             }
      92              :             // found one pedestrian that is not completely past the crossing point
      93              :             //std::cout << SIMTIME << " blocking pedestrian foeLane=" << lane->getID() << " ped=" << ped->getPerson()->getID() << " dir=" << ped->getDirection() << " pX=" << ped->getEdgePos(0) << " pL=" << ped.getLength() << " fDTC=" << distToCrossing << " lBD=" << leaderBackDist << "\n";
      94       593179 :             if (collectBlockers == nullptr) {
      95              :                 return true;
      96              :             }
      97            0 :             collectBlockers->push_back(ped->getPerson());
      98              :         }
      99              :     }
     100      3455785 :     if (collectBlockers == nullptr) {
     101              :         return false;
     102              :     }
     103            0 :     return collectBlockers->size() > 0;
     104              : }
     105              : 
     106              : 
     107              : bool
     108      4791144 : MSPModel_Interacting::hasPedestrians(const MSLane* lane) {
     109      4791144 :     return getPedestrians(lane).size() > 0;
     110              : }
     111              : 
     112              : 
     113              : bool
     114       121748 : MSPModel_Interacting::usingInternalLanes() {
     115       121748 :     return usingInternalLanesStatic();
     116              : }
     117              : 
     118              : 
     119              : bool
     120       130009 : MSPModel_Interacting::usingInternalLanesStatic() {
     121       130009 :     return MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks() && MSNet::getInstance()->hasPedestrianNetwork();
     122              : }
     123              : 
     124              : 
     125              : PersonDist
     126       683353 : MSPModel_Interacting::nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime, bool bidi) {
     127              :     PersonDist result((const MSPerson*)nullptr, std::numeric_limits<double>::max());
     128      3902265 :     for (const MSPModel_InteractingState* ped : getPedestrians(lane)) {
     129              :         // account for distance covered by oncoming pedestrians
     130      3218912 :         double relX2 = ped->getEdgePos(0) - (ped->getDirection() == FORWARD ? 0 : stopTime * ped->getPerson()->getMaxSpeed());
     131      3218912 :         double dist = ((relX2 - minPos) * (bidi ? -1 : 1)
     132      3218912 :                        - (ped->getDirection() == FORWARD ? ped->getPerson()->getVehicleType().getLength() : 0));
     133      3218912 :         const bool aheadOfVehicle = bidi ? ped->getEdgePos(0) < minPos : ped->getEdgePos(0) > minPos;
     134      3218912 :         if (aheadOfVehicle && dist < result.second) {
     135      1381911 :             const double center = ped->getLatOffset() + 0.5 * lane->getWidth();
     136      1381911 :             const double halfWidth = 0.5 * ped->getPerson()->getVehicleType().getWidth();
     137      1381911 :             const bool overlap = (center + halfWidth > minRight && center - halfWidth < maxLeft);
     138              : #ifdef DEBUG_INTERACTING
     139              :             if DEBUGCOND(ped) {
     140              :                 std::cout << "  nextBlocking lane=" << lane->getID() << " bidi=" << bidi
     141              :                           << " minPos=" << minPos << " minRight=" << minRight << " maxLeft=" << maxLeft
     142              :                           << " stopTime=" << stopTime
     143              :                           << " pedY=" << ped->getPosLat()
     144              :                           << " pedX=" << ped->getEdgePos(0)
     145              :                           << " relX2=" << relX2
     146              :                           << " center=" << center
     147              :                           << " pedLeft=" << center + halfWidth
     148              :                           << " pedRight=" << center - halfWidth
     149              :                           << " overlap=" << overlap
     150              :                           << "\n";
     151              :             }
     152              : #endif
     153              :             if (overlap) {
     154              :                 result.first = ped->getPerson();
     155              :                 result.second = dist;
     156              :             }
     157              :         }
     158              :     }
     159       683353 :     return result;
     160              : }
     161              : 
     162              : 
     163              : MSPModel_Interacting::Pedestrians&
     164     11723355 : MSPModel_Interacting::getPedestrians(const MSLane* lane) {
     165              :     ActiveLanes::iterator it = myActiveLanes.find(lane);
     166     11723355 :     if (it != myActiveLanes.end()) {
     167              :         //std::cout << " found lane=" << lane->getID() << " n=" << it->second.size() << "\n";
     168      5255260 :         return (it->second);
     169              :     }
     170              :     return noPedestrians;
     171              : }
     172              : 
     173              : 
     174              : void
     175        30706 : MSPModel_Interacting::unregisterCrossingApproach(const MSPModel_InteractingState& ped, const MSLane* crossing) {
     176              :     // person has entered the crossing
     177        30706 :     crossing->getIncomingLanes()[0].viaLink->removeApproachingPerson(ped.getPerson());
     178              : #ifdef DEBUG_INTERACTING
     179              :     if DEBUGCOND(ped) {
     180              :         std::cout << SIMTIME << " unregister " << ped->getPerson()->getID() << " at crossing " << crossing->getID() << "\n";
     181              :     }
     182              : #endif
     183        30706 : }
     184              : 
     185              : 
     186              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1