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  PState* state = new PState();
78  const SUMOTime firstEdgeDuration = state->computeWalkingTime(0, *stage, now);
79  myNet->getBeginOfTimestepEvents()->addEvent(new MoveToNextEdge(person, *stage),
80  now + firstEdgeDuration, MSEventControl::ADAPT_AFTER_EXECUTION);
81 
82  //if DEBUGCOND(person->getID()) std::cout << SIMTIME << " " << person->getID() << " inserted on " << stage->getEdge()->getID() << "\n";
83  return state;
84 }
85 
86 
87 bool
88 MSPModel_NonInteracting::blockedAtDist(const MSLane*, SUMOReal, std::vector<const MSPerson*>*) {
89  return false;
90 }
91 
92 
95  PState* state = dynamic_cast<PState*>(myParent.getPedestrianState());
96  const MSEdge* old = myParent.getEdge();
97  const bool arrived = myParent.moveToNextEdge(myPerson, currentTime);
98  if (arrived) {
99  // walk finished. clean up state
100  delete state;
101  //if DEBUGCOND(myPerson->getID()) std::cout << SIMTIME << " " << myPerson->getID() << " arrived on " << old->getID() << "\n";
102  return 0;
103  } else {
104  //if DEBUGCOND(myPerson->getID()) std::cout << SIMTIME << " " << myPerson->getID() << " moves to " << myParent.getEdge()->getID() << "\n";
105  return state->computeWalkingTime(old, myParent, currentTime);
106  }
107 }
108 
109 
110 SUMOTime
112  myLastEntryTime = currentTime;
113  const MSEdge* edge = stage.getEdge();
114  const MSEdge* next = stage.getNextRouteEdge();
115  int dir = UNDEFINED_DIRECTION;
116  if (prev == 0) {
117  myCurrentBeginPos = stage.getDepartPos();
118  } else {
119  // default to FORWARD if not connected
120  dir = (edge->getToJunction() == prev->getToJunction() || edge->getToJunction() == prev->getFromJunction()) ? BACKWARD : FORWARD;
121  myCurrentBeginPos = dir == FORWARD ? 0 : edge->getLength();
122  }
123  if (next == 0) {
124  myCurrentEndPos = stage.getArrivalPos();
125  } else {
126  if (dir == UNDEFINED_DIRECTION) {
127  // default to FORWARD if not connected
128  dir = (edge->getFromJunction() == next->getFromJunction() || edge->getFromJunction() == next->getToJunction()) ? BACKWARD : FORWARD;
129  }
130  myCurrentEndPos = dir == FORWARD ? edge->getLength() : 0;
131  }
132  // ensure that a result > 0 is returned even if the walk ends immediately
133  myCurrentDuration = MAX2((SUMOTime)1, TIME2STEPS(fabs(myCurrentEndPos - myCurrentBeginPos) / stage.getMaxSpeed()));
134  //std::cout << SIMTIME << " dir=" << dir << " curBeg=" << myCurrentBeginPos << " curEnd=" << myCurrentEndPos << " speed=" << stage.getMaxSpeed() << " dur=" << myCurrentDuration << "\n";
135  return myCurrentDuration;
136 }
137 
138 
139 SUMOReal
141  //std::cout << SIMTIME << " pos=" << (myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime)) << "\n";
142  return myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime);
143 }
144 
145 
146 Position
148  const MSLane* lane = getSidewalk<MSEdge, MSLane>(stage.getEdge());
149  const SUMOReal lateral_offset = lane->allowsVehicleClass(SVC_PEDESTRIAN) ? 0 : SIDEWALK_OFFSET;
150  return stage.getLanePosition(lane, getEdgePos(stage, now), lateral_offset);
151 }
152 
153 
154 SUMOReal
156  //std::cout << SIMTIME << " rawAngle=" << stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) << " angle=" << stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? 180 : 0) << "\n";
157  SUMOReal angle = stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? M_PI : 0);
158  if (angle > M_PI) {
159  angle -= 2 * M_PI;
160  }
161  return angle;
162 }
163 
164 
165 SUMOTime
167  return 0;
168 }
169 
170 
171 SUMOReal
173  return stage.getMaxSpeed();
174 }
175 
176 
177 const MSEdge*
179  return stage.getNextRouteEdge();
180 }
181 
182 /****************************************************************************/
const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const
return the list of internal edges if the pedestrian is on an intersection
SUMOReal getDepartPos() const
Definition: MSPerson.h:142
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getEdgeAngle(const MSEdge *e, SUMOReal at) const
get angle of the edge at a certain position
is a pedestrian
SUMOReal getSpeed(const MSPerson::MSPersonStage_Walking &stage) const
return the current speed of the person
#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:83
static const int FORWARD
Definition: MSPModel.h:70
T MAX2(T a, T b)
Definition: StdDefs.h:75
abstract base class for managing callbacks to retrieve various state information from the model ...
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
const MSJunction * getToJunction() const
Definition: MSEdge.h:387
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)
register the given person as a pedestrian
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
Position getLanePosition(const MSLane *lane, SUMOReal at, SUMOReal offset) const
get position on lane at length at with orthogonal offset
The simulated network and simulation perfomer.
Definition: MSNet.h:93
A road/street connecting two junctions.
Definition: MSEdge.h:80
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:75
SUMOReal getMaxSpeed() const
accessors to be used by MSPModel
Definition: MSPerson.h:139
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
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:400
MSNet * myNet
the net to which to issue moveToNextEdge commands
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
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:93
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the network coordinate of the person
static const SUMOReal SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk ...
Definition: MSPModel.h:81
SUMOReal getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the direction in which the person faces in degrees
const MSJunction * getFromJunction() const
Definition: MSEdge.h:383
SUMOReal getArrivalPos() const
Definition: MSPerson.h:145
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:591
A storage for options typed value containers)
Definition: OptionsCont.h:99
SUMOReal getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
abstract methods inherited from PedestrianState
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition: MSLane.h:695
static const int BACKWARD
Definition: MSPModel.h:74
Patch the time in a way that it is at least as high as the simulation begin time. ...
#define SUMOReal
Definition: config.h:213
const MSEdge * getNextRouteEdge() const
Definition: MSPerson.h:152
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
bool blockedAtDist(const MSLane *lane, SUMOReal distToCrossing, std::vector< const MSPerson *> *collectBlockers)
whether a pedestrian is blocking the crossing of lane at offset distToCrossing
SUMOTime execute(SUMOTime currentTime)
Executes the command.