1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MSPModel.h
11 /// @author  Jakob Erdmann
12 /// @date    Mon, 13 Jan 2014
13 /// @version $Id$
14 ///
15 // The pedestrian following model (prototype)
16 /****************************************************************************/
17 #ifndef MSPModel_h
18 #define MSPModel_h
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <limits>
27 #include <utils/common/SUMOTime.h>
28 #include <utils/common/Command.h>
29 #include <utils/common/MsgHandler.h>
30 #include <utils/geom/GeomHelper.h>
31 #include <microsim/pedestrians/MSPerson.h>
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 class MSNet;
37 class MSLane;
38 class MSJunction;
39 
40 typedef std::pair<const MSPerson*, double> PersonDist;
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
45 /**
46  * @class MSPModel
47  * @brief The pedestrian following model
48  *
49  */
50 class MSPModel {
51 public:
52 
53     static MSPModel* getModel();
54 
55     /// @brief remove state at simulation end
56     static void cleanup();
57 
~MSPModel()58     virtual ~MSPModel() {};
59 
60     /// @brief register the given person as a pedestrian
61     virtual PedestrianState* add(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, SUMOTime now) = 0;
62 
63     /// @brief remove the specified person from the pedestrian simulation
64     virtual void remove(PedestrianState* state) = 0;
65 
66     /** @brief whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries
67      * @param[in] lane The crossing to check
68      * @param[in] vehSide The offset to the vehicle side near the start of the crossing
69      * @param[in] vehWidth The width of the vehicle
70      * @param[in] oncomingGap The distance which the vehicle wants to keep from oncoming pedestrians
71      * @param[in] collectBlockers The list of persons blocking the crossing
72      * @return Whether the vehicle must wait
73      */
blockedAtDist(const MSLane * lane,double vehSide,double vehWidth,double oncomingGap,std::vector<const MSPerson * > * collectBlockers)74     virtual bool blockedAtDist(const MSLane* lane, double vehSide, double vehWidth,
75                                double oncomingGap, std::vector<const MSPerson*>* collectBlockers) {
76         UNUSED_PARAMETER(lane);
77         UNUSED_PARAMETER(vehSide);
78         UNUSED_PARAMETER(vehWidth);
79         UNUSED_PARAMETER(oncomingGap);
80         UNUSED_PARAMETER(collectBlockers);
81         return false;
82     }
83 
84     /// @brief whether the given lane has pedestrians on it
hasPedestrians(const MSLane * lane)85     virtual bool hasPedestrians(const MSLane* lane) {
86         UNUSED_PARAMETER(lane);
87         return false;
88     }
89 
90     /// @brief returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or 0
91     virtual PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0) {
92         UNUSED_PARAMETER(lane);
93         UNUSED_PARAMETER(minPos);
94         UNUSED_PARAMETER(minRight);
95         UNUSED_PARAMETER(maxLeft);
96         UNUSED_PARAMETER(stopTime);
97         return PersonDist((const MSPerson*)0, -1);
98     }
99 
cleanupHelper()100     virtual void cleanupHelper() {};
101 
102     // @brief walking directions
103     static const int FORWARD;
104     static const int BACKWARD;
105     static const int UNDEFINED_DIRECTION;
106 
107     // @brief the safety gap to keep between the car and the pedestrian in all directions
108     static const double SAFETY_GAP;
109 
110     /// @brief the offset for computing person positions when walking on edges without a sidewalk
111     static const double SIDEWALK_OFFSET;
112 
113     /* @brief return the arrival direction if the route may be traversed with the given starting direction.
114      * returns UNDEFINED_DIRECTION if the route cannot be traversed
115      */
116     static int canTraverse(int dir, const ConstMSEdgeVector& route);
117 
118     /// @brief whether movements on intersections are modelled
119     virtual bool usingInternalLanes() = 0;
120 
121 private:
122     static MSPModel* myModel;
123 
124 };
125 
126 
127 /// @brief abstract base class for managing callbacks to retrieve various state information from the model
128 class PedestrianState {
129 public:
~PedestrianState()130     virtual ~PedestrianState() {};
131 
132     /// @brief return the offset from the start of the current edge measured in its natural direction
133     virtual double getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
134 
135     /// @brief return the network coordinate of the person
136     virtual Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
137 
138     /// @brief return the direction in which the person faces in degrees
139     virtual double getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
140 
141     /// @brief return the time the person spent standing
142     virtual SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
143 
144     /// @brief return the current speed of the person
145     virtual double getSpeed(const MSPerson::MSPersonStage_Walking& stage) const = 0;
146 
147     /// @brief return the list of internal edges if the pedestrian is on an intersection
148     virtual const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const = 0;
149 
150     /// @brief try to move person to the given position
moveToXY(MSPerson * p,Position pos,MSLane * lane,double lanePos,double lanePosLat,double angle,int routeOffset,const ConstMSEdgeVector & edges,SUMOTime t)151     virtual void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
152                           double lanePosLat, double angle, int routeOffset,
153                           const ConstMSEdgeVector& edges, SUMOTime t) {
154         UNUSED_PARAMETER(p);
155         UNUSED_PARAMETER(pos);
156         UNUSED_PARAMETER(lane);
157         UNUSED_PARAMETER(lanePos);
158         UNUSED_PARAMETER(lanePosLat);
159         UNUSED_PARAMETER(angle);
160         UNUSED_PARAMETER(routeOffset);
161         UNUSED_PARAMETER(edges);
162         UNUSED_PARAMETER(t);
163         WRITE_WARNING("moveToXY is ignored by the current pedestrian model");
164     }
165 
166 };
167 
168 
169 class DummyState : public PedestrianState {
170 
171 public:
getEdgePos(const MSPerson::MSPersonStage_Walking &,SUMOTime)172     double getEdgePos(const MSPerson::MSPersonStage_Walking&, SUMOTime) const {
173         return 0.;
174     }
getPosition(const MSPerson::MSPersonStage_Walking &,SUMOTime)175     Position getPosition(const MSPerson::MSPersonStage_Walking&, SUMOTime) const {
176         return Position::INVALID;
177     }
getAngle(const MSPerson::MSPersonStage_Walking &,SUMOTime)178     double getAngle(const MSPerson::MSPersonStage_Walking&, SUMOTime) const {
179         return 0.;
180     }
getWaitingTime(const MSPerson::MSPersonStage_Walking &,SUMOTime)181     SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking&, SUMOTime) const {
182         return 0;
183     }
getSpeed(const MSPerson::MSPersonStage_Walking &)184     double getSpeed(const MSPerson::MSPersonStage_Walking&) const {
185         return 0.;
186     }
getNextEdge(const MSPerson::MSPersonStage_Walking &)187     const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking&) const {
188         return nullptr;
189     }
190 };
191 
192 
193 #endif /* MSPModel_h */
194 
195