SUMO - Simulation of Urban MObility
MSPModel_NonInteracting.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The pedestrian following model (prototype)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2014-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <math.h>
31 #include <algorithm>
33 #include <utils/geom/GeomHelper.h>
35 #include <microsim/MSNet.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSLane.h>
38 #include <microsim/MSJunction.h>
40 
41 
42 // ===========================================================================
43 // DEBUGGING HELPERS
44 // ===========================================================================
45 //
46 #define DEBUG1 "disabled"
47 #define DEBUG2 "disabled"
48 #define DEBUGCOND(PEDID) (PEDID == DEBUG1 || PEDID == DEBUG2)
49 
50 // ===========================================================================
51 // named (internal) constants
52 // ===========================================================================
53 
54 
55 // ===========================================================================
56 // static members
57 // ===========================================================================
58 
59 
60 // ===========================================================================
61 // MSPModel_NonInteracting method definitions
62 // ===========================================================================
63 
65  myNet(net) {
66  assert(myNet != 0);
67  UNUSED_PARAMETER(oc);
68 }
69 
70 
72 }
73 
74 
77  MoveToNextEdge* cmd = new MoveToNextEdge(person, *stage);
78  PState* state = new PState(cmd);
79  const SUMOTime firstEdgeDuration = state->computeWalkingTime(0, *stage, now);
80  myNet->getBeginOfTimestepEvents()->addEvent(cmd, now + firstEdgeDuration);
81 
82  //if DEBUGCOND(person->getID()) std::cout << SIMTIME << " " << person->getID() << " inserted on " << stage->getEdge()->getID() << "\n";
83  return state;
84 }
85 
86 
87 void
89  dynamic_cast<PState*>(state)->getCommand()->abortWalk();
90 }
91 
92 
93 bool
94 MSPModel_NonInteracting::blockedAtDist(const MSLane*, double, std::vector<const MSPerson*>*) {
95  return false;
96 }
97 
98 
101  if (myPerson == 0) {
102  return 0; // descheduled
103  }
104  PState* state = dynamic_cast<PState*>(myParent.getPedestrianState());
105  const MSEdge* old = myParent.getEdge();
106  const bool arrived = myParent.moveToNextEdge(myPerson, currentTime);
107  if (arrived) {
108  // walk finished. clean up state
109  delete state;
110  //if DEBUGCOND(myPerson->getID()) std::cout << SIMTIME << " " << myPerson->getID() << " arrived on " << old->getID() << "\n";
111  return 0;
112  } else {
113  //if DEBUGCOND(myPerson->getID()) std::cout << SIMTIME << " " << myPerson->getID() << " moves to " << myParent.getEdge()->getID() << "\n";
114  return state->computeWalkingTime(old, myParent, currentTime);
115  }
116 }
117 
118 
119 SUMOTime
121  myLastEntryTime = currentTime;
122  const MSEdge* edge = stage.getEdge();
123  const MSEdge* next = stage.getNextRouteEdge();
124  int dir = UNDEFINED_DIRECTION;
125  if (prev == 0) {
126  myCurrentBeginPos = stage.getDepartPos();
127  } else {
128  // default to FORWARD if not connected
129  dir = (edge->getToJunction() == prev->getToJunction() || edge->getToJunction() == prev->getFromJunction()) ? BACKWARD : FORWARD;
130  myCurrentBeginPos = dir == FORWARD ? 0 : edge->getLength();
131  }
132  if (next == 0) {
133  myCurrentEndPos = stage.getArrivalPos();
134  } else {
135  if (dir == UNDEFINED_DIRECTION) {
136  // default to FORWARD if not connected
137  dir = (edge->getFromJunction() == next->getFromJunction() || edge->getFromJunction() == next->getToJunction()) ? BACKWARD : FORWARD;
138  }
139  myCurrentEndPos = dir == FORWARD ? edge->getLength() : 0;
140  }
141  // ensure that a result > 0 is returned even if the walk ends immediately
142  myCurrentDuration = MAX2((SUMOTime)1, TIME2STEPS(fabs(myCurrentEndPos - myCurrentBeginPos) / stage.getMaxSpeed()));
143  //std::cout << SIMTIME << " dir=" << dir << " curBeg=" << myCurrentBeginPos << " curEnd=" << myCurrentEndPos << " speed=" << stage.getMaxSpeed() << " dur=" << myCurrentDuration << "\n";
144  return myCurrentDuration;
145 }
146 
147 
148 double
150  //std::cout << SIMTIME << " pos=" << (myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime)) << "\n";
151  return myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime);
152 }
153 
154 
155 Position
157  const MSLane* lane = getSidewalk<MSEdge, MSLane>(stage.getEdge());
158  const double lateral_offset = lane->allowsVehicleClass(SVC_PEDESTRIAN) ? 0 : SIDEWALK_OFFSET;
159  return stage.getLanePosition(lane, getEdgePos(stage, now), lateral_offset);
160 }
161 
162 
163 double
165  //std::cout << SIMTIME << " rawAngle=" << stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) << " angle=" << stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? 180 : 0) << "\n";
166  double angle = stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? M_PI : 0);
167  if (angle > M_PI) {
168  angle -= 2 * M_PI;
169  }
170  return angle;
171 }
172 
173 
174 SUMOTime
176  return 0;
177 }
178 
179 
180 double
182  return stage.getMaxSpeed();
183 }
184 
185 
186 const MSEdge*
188  return stage.getNextRouteEdge();
189 }
190 
191 /****************************************************************************/
const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const
return the list of internal edges if the pedestrian is on an intersection
is a pedestrian
#define M_PI
Definition: angles.h:37
SUMOTime computeWalkingTime(const MSEdge *prev, const MSPerson::MSPersonStage_Walking &stage, SUMOTime currentTime)
compute walking time on edge and update state members
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSPerson.cpp:80
static const int FORWARD
Definition: MSPModel.h:73
double getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
abstract methods inherited from PedestrianState
T MAX2(T a, T b)
Definition: StdDefs.h:70
abstract base class for managing callbacks to retrieve various state information from the model ...
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk ...
Definition: MSPModel.h:84
double getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the direction in which the person faces in degrees
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
double getLength() const
return the length of the edge
Definition: MSEdge.h:586
const MSJunction * getToJunction() const
Definition: MSEdge.h:372
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)
register the given person as a pedestrian
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
void remove(PedestrianState *state)
remove the specified person from the pedestrian simulation
The simulated network and simulation perfomer.
Definition: MSNet.h:94
A road/street connecting two junctions.
Definition: MSEdge.h:80
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:78
MSPModel_NonInteracting(const OptionsCont &oc, MSNet *net)
Constructor (it should not be necessary to construct more than one instance)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
double getSpeed(const MSPerson::MSPersonStage_Walking &stage) const
return the current speed of the person
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:403
MSNet * myNet
the net to which to issue moveToNextEdge commands
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
double getArrivalPos() const
Definition: MSPerson.h:160
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the time the person spent standing
abstract base class for managing callbacks to retrieve various state information from the model ...
Definition: MSPModel.h:96
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the network coordinate of the person
const MSJunction * getFromJunction() const
Definition: MSEdge.h:368
A storage for options typed value containers)
Definition: OptionsCont.h:99
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition: MSLane.h:706
static const int BACKWARD
Definition: MSPModel.h:77
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
long long int SUMOTime
Definition: TraCIDefs.h:52
const MSEdge * getNextRouteEdge() const
Definition: MSPerson.h:167
bool blockedAtDist(const MSLane *lane, double distToCrossing, std::vector< const MSPerson *> *collectBlockers)
whether a pedestrian is blocking the crossing of lane at offset distToCrossing
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
double getMaxSpeed() const
accessors to be used by MSPModel
Definition: MSPerson.h:149
SUMOTime execute(SUMOTime currentTime)
Executes the command.