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_NonInteracting.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 "MSPerson.h" 28 : #include "MSPModel.h" 29 : 30 : // =========================================================================== 31 : // class declarations 32 : // =========================================================================== 33 : class MSNet; 34 : class MSLink; 35 : class MSLane; 36 : class MSJunction; 37 : 38 : 39 : // =========================================================================== 40 : // class definitions 41 : // =========================================================================== 42 : /** 43 : * @class MSPModel_NonInteracting 44 : * @brief The pedestrian following model 45 : * 46 : */ 47 : class MSPModel_NonInteracting : public MSPModel { 48 : public: 49 : 50 : /// @brief Constructor (it should not be necessary to construct more than one instance) 51 : MSPModel_NonInteracting(const OptionsCont& oc, MSNet* net); 52 : 53 : ~MSPModel_NonInteracting(); 54 : 55 : /// @brief register the given transportable 56 : MSTransportableStateAdapter* add(MSTransportable* transportable, MSStageMoving* stage, SUMOTime now); 57 : 58 : /// @brief load the state of the given transportable 59 : MSTransportableStateAdapter* loadState(MSTransportable* transportable, MSStageMoving* stage, std::istringstream& in); 60 : 61 : /// @brief Resets pedestrians when quick-loading state 62 : void clearState(); 63 : 64 : /// @brief remove the specified person from the pedestrian simulation 65 : void remove(MSTransportableStateAdapter* state); 66 : 67 : /// @brief whether movements on intersections are modelled 68 15939 : bool usingInternalLanes() { 69 15939 : return false; 70 : } 71 : 72 : /// @brief return the number of active objects 73 311086 : int getActiveNumber() { 74 311086 : return myNumActivePedestrians; 75 : } 76 : 77 : void registerArrived() { 78 131961 : myNumActivePedestrians--; 79 : } 80 : 81 : private: 82 : class MoveToNextEdge : public Command { 83 : public: 84 132634 : MoveToNextEdge(MSTransportable* transportable, MSStageMoving& walk, MSPModel_NonInteracting* model) : 85 132634 : myParent(walk), myTransportable(transportable), myModel(model) {} 86 : SUMOTime execute(SUMOTime currentTime); 87 : void abortWalk() { 88 429 : myTransportable = nullptr; 89 : } 90 : const MSTransportable* getTransportable() const { 91 219246 : return myTransportable; 92 : } 93 : 94 : private: 95 : MSStageMoving& myParent; 96 : MSTransportable* myTransportable; 97 : MSPModel_NonInteracting* myModel; 98 : 99 : private: 100 : /// @brief Invalidated assignment operator. 101 : MoveToNextEdge& operator=(const MoveToNextEdge&); 102 : }; 103 : 104 : 105 : /// @brief implementation of callbacks to retrieve various state information from the model 106 : class PState : public MSTransportableStateAdapter { 107 : public: 108 : PState(MoveToNextEdge* cmd, std::istringstream* in = nullptr); 109 : 110 : /// @brief abstract methods inherited from PedestrianState 111 : /// @{ 112 : /// @brief return the offset from the start of the current edge measured in its natural direction 113 : double getEdgePos(const MSStageMoving& stage, SUMOTime now) const; 114 : int getDirection(const MSStageMoving& stage, SUMOTime now) const; 115 : virtual Position getPosition(const MSStageMoving& stage, SUMOTime now) const; 116 : virtual double getAngle(const MSStageMoving& stage, SUMOTime now) const; 117 : SUMOTime getWaitingTime(const MSStageMoving& stage, SUMOTime now) const; 118 : double getSpeed(const MSStageMoving& stage) const; 119 : const MSEdge* getNextEdge(const MSStageMoving& stage) const; 120 : /// @} 121 : 122 : /// @brief compute walking time on edge and update state members 123 : virtual SUMOTime computeDuration(const MSEdge* prev, const MSStageMoving& stage, SUMOTime currentTime); 124 : MoveToNextEdge* getCommand() const { 125 429 : return myCommand; 126 : } 127 : 128 : SUMOTime getEventTime() const { 129 13 : return myLastEntryTime + myCurrentDuration; 130 : } 131 : 132 : /** @brief Saves the current state into the given stream 133 : */ 134 : void saveState(std::ostringstream& out); 135 : 136 : protected: 137 : SUMOTime myLastEntryTime; 138 : SUMOTime myCurrentDuration; 139 : double myCurrentBeginPos; 140 : double myCurrentEndPos; 141 : MoveToNextEdge* myCommand; 142 : }; 143 : 144 : 145 : class CState : public PState { 146 : public: 147 : CState(MoveToNextEdge* cmd, std::istringstream* in = nullptr); 148 : 149 : /// @brief the offset for computing container positions when being transhiped 150 : static const double LATERAL_OFFSET; 151 : 152 : /// @brief return the network coordinate of the container 153 : Position getPosition(const MSStageMoving& stage, SUMOTime now) const; 154 : /// @brief return the direction in which the container heading to 155 : double getAngle(const MSStageMoving& stage, SUMOTime now) const; 156 : /// @brief compute tranship time on edge and update state members 157 : SUMOTime computeDuration(const MSEdge* prev, const MSStageMoving& stage, SUMOTime currentTime); 158 : 159 : private: 160 : Position myCurrentBeginPosition; //the position the container is moving from during its tranship stage 161 : Position myCurrentEndPosition; //the position the container is moving to during its tranship stage 162 : }; 163 : 164 : private: 165 : /// @brief the net to which to issue moveToNextEdge commands 166 : MSNet* myNet; 167 : 168 : /// @brief the total number of active pedestrians 169 : int myNumActivePedestrians; 170 : 171 : };