LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSPModel_Interacting.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 88.2 % 34 30
Test Date: 2024-12-21 15:45:41 Functions: 80.0 % 10 8

            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.h
      15              : /// @author  Jakob Erdmann
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 13 Jan 2014
      18              : ///
      19              : // The abstract superclass for pedestrian models which actually interact with vehicles
      20              : /****************************************************************************/
      21              : #pragma once
      22              : #include <config.h>
      23              : 
      24              : #include "MSPModel.h"
      25              : 
      26              : 
      27              : // ===========================================================================
      28              : // class declarations
      29              : // ===========================================================================
      30              : class MSPModel_InteractingState;
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // class definitions
      35              : // ===========================================================================
      36              : /**
      37              :  * @class MSPModel_Interacting
      38              :  * @brief The abstract superclass for pedestrian models which actually interact with vehicles
      39              :  *
      40              :  */
      41         5163 : class MSPModel_Interacting : public MSPModel {
      42              : public:
      43              :     ~MSPModel_Interacting();
      44              : 
      45              :     /// @brief Resets pedestrians when quick-loading state
      46              :     virtual void clearState();
      47              : 
      48              :     /// @brief remove the specified person from the pedestrian simulation
      49              :     virtual void remove(MSTransportableStateAdapter* state);
      50              : 
      51              :     /** @brief whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries
      52              :      * @param[in] ego The object that inquires about blockage (and may electively ignore foes)
      53              :      * @param[in] lane The crossing to check
      54              :      * @param[in] vehside The offset to the vehicle side near the start of the crossing
      55              :      * @param[in] vehWidth The width of the vehicle
      56              :      * @param[in] oncomingGap The distance which the vehicle wants to keep from oncoming pedestrians
      57              :      * @param[in] collectBlockers The list of persons blocking the crossing
      58              :      * @return Whether the vehicle must wait
      59              :      */
      60              :     bool blockedAtDist(const SUMOTrafficObject* ego, const MSLane* lane, double vehCenter, double vehWidth,
      61              :                        double oncomingGap, std::vector<const MSPerson*>* collectBlockers);
      62              : 
      63              :     /** @brief returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or nullptr
      64              :      * @param[in] lane the lane to check
      65              :      * @param[in] minPos The minimum offset along the lane after which to check
      66              :      * @param[in] minRight The rightmost border of the vehicle (0 indicates driving on the right border)
      67              :      * @param[in] maxLeft The leftmost border of the vehicle
      68              :      * @param[in] stopTime The time it would take the vehicle to come to a stop
      69              :      * @param[in] bidi Whether the vehicle is driving against the flow
      70              :      * @return The closest person (or nullptr) and the distance to it
      71              :      */
      72              :     PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0, bool bidi = false);
      73              : 
      74              :     /// @brief whether the given lane has pedestrians on it
      75              :     bool hasPedestrians(const MSLane* lane);
      76              : 
      77              :     /// @brief whether movements on intersections are modelled
      78              :     //// @note function declared as member for sake of inheritance (delegates to static function)
      79              :     bool usingInternalLanes();
      80              : 
      81              :     static bool usingInternalLanesStatic();
      82              : 
      83              :     /// @brief return the number of active pedestrians
      84       526727 :     int getActiveNumber() {
      85       526727 :         return myNumActivePedestrians;
      86              :     }
      87              : 
      88              :     /// @brief increase the number of active pedestrians
      89              :     void registerActive() {
      90          290 :         myNumActivePedestrians++;
      91          290 :     }
      92              : 
      93              :     /// @brief unregister pedestrian approach with the junction model
      94              :     static void unregisterCrossingApproach(const MSPModel_InteractingState& ped, const MSLane* crossing);
      95              : 
      96              : protected:
      97              :     typedef std::vector<MSPModel_InteractingState*> Pedestrians;
      98              :     typedef std::map<const MSLane*, Pedestrians, ComparatorNumericalIdLess> ActiveLanes;
      99              : 
     100              :     /// @brief retrieves the pedestrian vector for the given lane (may be empty)
     101              :     Pedestrians& getPedestrians(const MSLane* lane);
     102              : 
     103              :     /// @brief the total number of active pedestrians
     104              :     int myNumActivePedestrians = 0;
     105              : 
     106              :     /// @brief store of all lanes which have pedestrians on them
     107              :     ActiveLanes myActiveLanes;
     108              : 
     109              :     /// @brief whether an event for pedestrian processing was added
     110              :     bool myAmActive = false;
     111              : 
     112              :     /// @brief all crossings being approached by pedestrians
     113              :     std::set<MSLink*> myApproachedCrossings;
     114              : 
     115              :     /// @brief empty pedestrian vector
     116              :     static Pedestrians noPedestrians;
     117              : 
     118              : };
     119              : 
     120              : 
     121              : /**
     122              :  * @class MSPModel_InteractingState
     123              :  * This contains trivial implementations and members for the most used access methods
     124              :  * @brief Container for pedestrian state and individual position update function
     125              :  */
     126              : class MSPModel_InteractingState : public MSTransportableStateAdapter {
     127              : public:
     128              :     /// @brief constructor
     129       681623 :     MSPModel_InteractingState(MSPerson* person, MSStageMoving* stage, const MSLane* lane) :
     130       681623 :         myPerson(person),
     131       681623 :         myStage(stage),
     132       681623 :         myLane(lane),
     133       243773 :         myEdgePos(stage != nullptr ? stage->getDepartPos() : 0.),
     134       243773 :         myPosLat(stage != nullptr ? stage->getDepartPosLat() : 0.),
     135       681623 :         myDir(MSPModel::UNDEFINED_DIRECTION),
     136       243773 :         myWaitingToEnter(person != nullptr) {}
     137              : 
     138              :     ~MSPModel_InteractingState() {};
     139              : 
     140              :     /// @brief abstract methods inherited from MSTransportableStateAdapter
     141              :     /// @{
     142              :     /// @brief return the offset from the start of the current edge measured in its natural direction
     143   8721049271 :     inline double getEdgePos(SUMOTime /* now */) const {
     144   8721049271 :         return myEdgePos;
     145              :     }
     146              : 
     147              :     /// @brief return the walking direction (FORWARD, BACKWARD, UNDEFINED_DIRECTION)
     148   1142040919 :     inline int getDirection() const {
     149   1142040919 :         return myDir;
     150              :     }
     151              : 
     152              :     /// @brief return the time the transportable spent standing
     153     11818269 :     inline SUMOTime getWaitingTime() const {
     154     11818269 :         return myWaitingTime;
     155              :     }
     156              : 
     157              :     /// @brief return the current speed of the transportable
     158    702959300 :     inline double getSpeed(const MSStageMoving& /* stage */) const {
     159    702959300 :         return mySpeed;
     160              :     }
     161              : 
     162              :     /// @brief whether the transportable is jammed
     163   2596304066 :     inline bool isJammed() const {
     164   2596304066 :         return myAmJammed;
     165              :     }
     166              : 
     167              :     /// @brief the current lane of the transportable
     168      3682894 :     inline const MSLane* getLane() const {
     169      3682894 :         return myLane;
     170              :     }
     171              :     /// @}
     172              : 
     173              :     /// @brief placeholder function for the accessing the next crossing
     174            0 :     virtual const MSLane* getNextCrossing() const {
     175            0 :         return nullptr;
     176              :     }
     177              : 
     178              :     /// @brief return the lateral offset to the lane center
     179            0 :     virtual double getLatOffset() const {
     180            0 :         return myPosLat;
     181              :     }
     182              : 
     183              :     /// @brief return the represented person
     184              :     inline MSPerson* getPerson() const {
     185  11074783753 :         return myPerson;
     186              :     }
     187              : 
     188              :     /// @brief return the current stage
     189              :     inline MSStageMoving* getStage() const {
     190    875402190 :         return myStage;
     191              :     }
     192              : 
     193              :     /// @brief whether the person still waits to entere the network
     194              :     inline bool isWaitingToEnter() const {
     195  13137793495 :         return myWaitingToEnter;
     196              :     }
     197              : 
     198              :     /// @brief return the remote position if being controlled by TraCI or JuPedSim
     199              :     inline const Position& getRemotePosition() const {
     200              :         return myRemoteXYPos;
     201              :     }
     202              : 
     203              :     /// @brief return ID of the person (or sometimes vehicle) being represented
     204   3729717271 :     virtual const std::string& getID() const {
     205   3729717271 :         return myPerson->getID();
     206              :     }
     207              : 
     208              :     /// @brief return the current orientation in degrees
     209              :     virtual double getAngle(const MSStageMoving&, SUMOTime) const {
     210              :         return myAngle;
     211              :     }
     212              : 
     213              : protected:
     214              :     /// @brief the person who is being represented
     215              :     MSPerson* myPerson = nullptr;
     216              :     /// @brief the current stage of this pedestrian
     217              :     MSStageMoving* myStage = nullptr;
     218              :     /// @brief the current lane of this pedestrian
     219              :     const MSLane* myLane = nullptr;
     220              :     /// @brief the advancement along the current lane
     221              :     double myEdgePos = 0.;
     222              :     /// @brief the orthogonal shift on the current lane
     223              :     double myPosLat = 0.;
     224              :     /// @brief the walking direction on the current lane (1 forward, -1 backward)
     225              :     int myDir = MSPModel::UNDEFINED_DIRECTION;
     226              :     /// @brief the current walking speed
     227              :     double mySpeed = 0.;
     228              :     /// @brief the current lateral walking speed
     229              :     double mySpeedLat = 0.;
     230              :     /// @brief whether the pedestrian is waiting to start its walk
     231              :     bool myWaitingToEnter = false;
     232              :     /// @brief the consecutive time spent at speed 0
     233              :     SUMOTime myWaitingTime = 0;
     234              :     /// @brief whether the person is jammed
     235              :     bool myAmJammed = false;
     236              :     /// @brief remote-controlled position
     237              :     Position myRemoteXYPos = Position::INVALID;
     238              :     /// @brief cached angle
     239              :     mutable double myAngle = std::numeric_limits<double>::max();
     240              : 
     241              : private:
     242              :     /// @brief Invalidated assignment operator.
     243              :     MSPModel_InteractingState& operator=(const MSPModel_InteractingState&) = delete;
     244              : };
        

Generated by: LCOV version 2.0-1