LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSPModel.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 10 26 38.5 %
Date: 2024-05-06 15:32:35 Functions: 5 12 41.7 %

          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.h
      15             : /// @author  Jakob Erdmann
      16             : /// @date    Mon, 13 Jan 2014
      17             : ///
      18             : // The pedestrian following model (prototype)
      19             : /****************************************************************************/
      20             : #pragma once
      21             : #include <config.h>
      22             : 
      23             : #include <string>
      24             : #include <limits>
      25             : #include <utils/common/SUMOTime.h>
      26             : #include <utils/common/Command.h>
      27             : #include <utils/common/MsgHandler.h>
      28             : #include <utils/geom/GeomHelper.h>
      29             : #include <microsim/transportables/MSPerson.h>
      30             : #ifdef HAVE_FOX
      31             : #include <utils/foxtools/fxheader.h>
      32             : #endif
      33             : 
      34             : // ===========================================================================
      35             : // class declarations
      36             : // ===========================================================================
      37             : class MSNet;
      38             : class MSLane;
      39             : class MSJunction;
      40             : 
      41             : typedef std::pair<const MSPerson*, double> PersonDist;
      42             : 
      43             : // ===========================================================================
      44             : // class definitions
      45             : // ===========================================================================
      46             : /**
      47             :  * @class MSPModel
      48             :  * @brief The pedestrian (and also sometimes container) movement model
      49             :  *
      50             :  */
      51             : class MSPModel {
      52             : public:
      53             : 
      54             :     virtual ~MSPModel() {};
      55             : 
      56             :     /// @brief register the given person as a pedestrian
      57             :     virtual MSTransportableStateAdapter* add(MSTransportable* transportable, MSStageMoving* stage, SUMOTime now) = 0;
      58             : 
      59             :     /// @brief load the state of the given transportable
      60           0 :     virtual MSTransportableStateAdapter* loadState(MSTransportable* transportable, MSStageMoving* stage, std::istringstream& state) {
      61             :         UNUSED_PARAMETER(transportable);
      62             :         UNUSED_PARAMETER(stage);
      63             :         UNUSED_PARAMETER(state);
      64           0 :         return nullptr;
      65             :     }
      66             : 
      67             :     /// @brief Resets pedestrians when quick-loading state
      68             :     virtual void clearState() = 0;
      69             : 
      70             :     /// @brief remove the specified person from the pedestrian simulation
      71             :     virtual void remove(MSTransportableStateAdapter* state) = 0;
      72             : 
      73             :     /** @brief whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries
      74             :      * @param[in] ego The object that inquires about blockage (and may electively ignore foes)
      75             :      * @param[in] lane The crossing to check
      76             :      * @param[in] vehSide The offset to the vehicle side near the start of the crossing
      77             :      * @param[in] vehWidth The width of the vehicle
      78             :      * @param[in] oncomingGap The distance which the vehicle wants to keep from oncoming pedestrians
      79             :      * @param[in] collectBlockers The list of persons blocking the crossing
      80             :      * @return Whether the vehicle must wait
      81             :      */
      82       50627 :     virtual bool blockedAtDist(const SUMOTrafficObject* ego, const MSLane* lane, double vehSide, double vehWidth,
      83             :                                double oncomingGap, std::vector<const MSPerson*>* collectBlockers) {
      84             :         UNUSED_PARAMETER(ego);
      85             :         UNUSED_PARAMETER(lane);
      86             :         UNUSED_PARAMETER(vehSide);
      87             :         UNUSED_PARAMETER(vehWidth);
      88             :         UNUSED_PARAMETER(oncomingGap);
      89             :         UNUSED_PARAMETER(collectBlockers);
      90       50627 :         return false;
      91             :     }
      92             : 
      93             :     /// @brief whether the given lane has pedestrians on it
      94       78491 :     virtual bool hasPedestrians(const MSLane* lane) {
      95             :         UNUSED_PARAMETER(lane);
      96       78491 :         return false;
      97             :     }
      98             : 
      99             :     /** @brief returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or 0
     100             :      * @param[in] lane the lane to check
     101             :      * @param[in] minPos The minimum offset along the lane after which to check
     102             :      * @param[in] minRight The rightmost border of the vehicle (0 indicates driving on the right border)
     103             :      * @param[in] maxLeft The leftmost border of the vehicle
     104             :      * @param[in] stopTime The time it would take the vehicle to come to a stop
     105             :      * @param[in] bidi Whether the vehicle is driving against the flow
     106             :      * @return The closest person and the distance to it
     107             :      */
     108           0 :     virtual PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0, bool bidi = false) {
     109             :         UNUSED_PARAMETER(lane);
     110             :         UNUSED_PARAMETER(minPos);
     111             :         UNUSED_PARAMETER(minRight);
     112             :         UNUSED_PARAMETER(maxLeft);
     113             :         UNUSED_PARAMETER(stopTime);
     114             :         UNUSED_PARAMETER(bidi);
     115           0 :         return PersonDist(nullptr, -1);
     116             :     }
     117             : 
     118             :     // @brief walking directions
     119             :     static const int FORWARD;
     120             :     static const int BACKWARD;
     121             :     static const int UNDEFINED_DIRECTION;
     122             : 
     123             :     // @brief the safety gap to keep between the car and the pedestrian in all directions
     124             :     static const double SAFETY_GAP;
     125             : 
     126             :     /// @brief the offset for computing person positions when walking on edges without a sidewalk
     127             :     static const double SIDEWALK_OFFSET;
     128             : 
     129             :     /// @brief the default lateral offset for persons when starting a walk
     130             :     static const double UNSPECIFIED_POS_LAT;
     131             : 
     132             :     /// @brief magic value to encode randomized lateral offset for persons when starting a walk
     133             :     static const double RANDOM_POS_LAT;
     134             : 
     135             :     /* @brief return the arrival direction if the route may be traversed with the given starting direction.
     136             :      * param[out] passedEdges: the number of edges that were successfully traversed
     137             :      * returns UNDEFINED_DIRECTION if the route cannot be traversed
     138             :      */
     139             :     static int canTraverse(int dir, const ConstMSEdgeVector& route, int& passedEdges);
     140             : 
     141             :     /// @brief whether movements on intersections are modelled
     142             :     virtual bool usingInternalLanes() = 0;
     143             : 
     144             :     /// @brief whether travel times and distances can reliably be calculated from the network alone
     145       47926 :     virtual bool usingShortcuts() {
     146       47926 :         return false;
     147             :     }
     148             : 
     149             :     /// @brief return the number of active objects
     150             :     virtual int getActiveNumber() = 0;
     151             : 
     152             : };
     153             : 
     154             : 
     155             : /// @brief abstract base class for managing callbacks to retrieve various state information from the model
     156             : class MSTransportableStateAdapter {
     157             : public:
     158             :     virtual ~MSTransportableStateAdapter() {};
     159             : 
     160             :     /// @brief return the offset from the start of the current edge measured in its natural direction
     161             :     virtual double getEdgePos(const MSStageMoving& stage, SUMOTime now) const = 0;
     162             : 
     163             :     /// @brief return the walking direction (FORWARD, BACKWARD)
     164             :     virtual int getDirection(const MSStageMoving& stage, SUMOTime now) const = 0;
     165             : 
     166             :     /// @brief return the network coordinate of the transportable
     167             :     virtual Position getPosition(const MSStageMoving& stage, SUMOTime now) const = 0;
     168             : 
     169             :     /// @brief return the direction in which the transportable faces in degrees
     170             :     virtual double getAngle(const MSStageMoving& stage, SUMOTime now) const = 0;
     171             : 
     172             :     /// @brief return the time the transportable spent standing
     173             :     virtual SUMOTime getWaitingTime(const MSStageMoving& stage, SUMOTime now) const = 0;
     174             : 
     175             :     /// @brief return the current speed of the transportable
     176             :     virtual double getSpeed(const MSStageMoving& stage) const = 0;
     177             : 
     178             :     /// @brief return the list of internal edges if the transportable is on an intersection
     179             :     virtual const MSEdge* getNextEdge(const MSStageMoving& stage) const = 0;
     180             : 
     181             :     /// @brief try to move transportable to the given position
     182           0 :     virtual void moveTo(MSPerson* p, MSLane* lane, double lanePos, double lanePosLat, SUMOTime t) {
     183             :         UNUSED_PARAMETER(p);
     184             :         UNUSED_PARAMETER(lane);
     185             :         UNUSED_PARAMETER(lanePos);
     186             :         UNUSED_PARAMETER(lanePosLat);
     187             :         UNUSED_PARAMETER(t);
     188           0 :         WRITE_WARNING(TL("moveTo is ignored by the current movement model"));
     189           0 :     }
     190             : 
     191             :     /// @brief try to move transportable to the given position
     192           0 :     virtual void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
     193             :                           double lanePosLat, double angle, int routeOffset,
     194             :                           const ConstMSEdgeVector& edges, SUMOTime t) {
     195             :         UNUSED_PARAMETER(p);
     196             :         UNUSED_PARAMETER(pos);
     197             :         UNUSED_PARAMETER(lane);
     198             :         UNUSED_PARAMETER(lanePos);
     199             :         UNUSED_PARAMETER(lanePosLat);
     200             :         UNUSED_PARAMETER(angle);
     201             :         UNUSED_PARAMETER(routeOffset);
     202             :         UNUSED_PARAMETER(edges);
     203             :         UNUSED_PARAMETER(t);
     204           0 :         WRITE_WARNING(TL("moveToXY is ignored by the current movement model"));
     205           0 :     }
     206             : 
     207             :     /// @brief whether the transportable is jammed
     208           0 :     virtual bool isJammed() const {
     209           0 :         return false;
     210             :     }
     211             : 
     212             :     /// @brief whether the transportable has finished walking
     213      402123 :     virtual bool isFinished() const {
     214      402123 :         return true;
     215             :     }
     216             : 
     217             :     /// @brief the current lane of the transportable
     218       78015 :     virtual const MSLane* getLane() const {
     219       78015 :         return nullptr;
     220             :     }
     221             : 
     222             :     /// @brief return the total length of the current lane (in particular for on a walkingarea)
     223           0 :     virtual double getPathLength() const {
     224           0 :         return 0;
     225             :     }
     226             : 
     227             :     /** @brief Saves the current state into the given stream
     228             :      */
     229           0 :     virtual void saveState(std::ostringstream& out) {
     230             :         UNUSED_PARAMETER(out);
     231           0 :     }
     232             : 
     233             : };

Generated by: LCOV version 1.14