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-2015 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>
34 #include <microsim/MSNet.h>
35 #include <microsim/MSEdge.h>
36 #include <microsim/MSLane.h>
37 #include <microsim/MSJunction.h>
39 
40 
41 // ===========================================================================
42 // DEBUGGING HELPERS
43 // ===========================================================================
44 //
45 #define DEBUG1 "disabled"
46 #define DEBUG2 "disabled"
47 #define DEBUGCOND(PEDID) (PEDID == DEBUG1 || PEDID == DEBUG2)
48 
49 // ===========================================================================
50 // named (internal) constants
51 // ===========================================================================
52 
53 
54 // ===========================================================================
55 // static members
56 // ===========================================================================
57 
58 
59 // ===========================================================================
60 // MSPModel_NonInteracting method definitions
61 // ===========================================================================
62 
64  myNet(net) {
65  assert(myNet != 0);
66  UNUSED_PARAMETER(oc);
67 }
68 
69 
71 }
72 
73 
76  PState* state = new PState();
77  const SUMOTime firstEdgeDuration = state->computeWalkingTime(0, *stage, now);
78  myNet->getBeginOfTimestepEvents()->addEvent(new MoveToNextEdge(person, *stage),
79  now + firstEdgeDuration, MSEventControl::ADAPT_AFTER_EXECUTION);
80 
81  //if DEBUGCOND(person->getID()) std::cout << SIMTIME << " " << person->getID() << " inserted on " << stage->getEdge()->getID() << "\n";
82  return state;
83 }
84 
85 
86 bool
87 MSPModel_NonInteracting::blockedAtDist(const MSLane*, SUMOReal, std::vector<const MSPerson*>*) {
88  return false;
89 }
90 
91 
94  PState* state = dynamic_cast<PState*>(myParent.getPedestrianState());
95  const MSEdge* old = myParent.getEdge();
96  const bool arrived = myParent.moveToNextEdge(myPerson, currentTime);
97  if (arrived) {
98  // walk finished. clean up state
99  delete state;
100  //if DEBUGCOND(myPerson->getID()) std::cout << SIMTIME << " " << myPerson->getID() << " arrived on " << old->getID() << "\n";
101  return 0;
102  } else {
103  //if DEBUGCOND(myPerson->getID()) std::cout << SIMTIME << " " << myPerson->getID() << " moves to " << myParent.getEdge()->getID() << "\n";
104  return state->computeWalkingTime(old, myParent, currentTime);
105  }
106 }
107 
108 
109 SUMOTime
111  myLastEntryTime = currentTime;
112  const MSEdge* edge = stage.getEdge();
113  const MSEdge* next = stage.getNextRouteEdge();
114  int dir = UNDEFINED_DIRECTION;
115  if (prev == 0) {
116  myCurrentBeginPos = stage.getDepartPos();
117  } else {
118  // default to FORWARD if not connected
119  dir = (edge->getToJunction() == prev->getToJunction() || edge->getToJunction() == prev->getFromJunction()) ? BACKWARD : FORWARD;
120  myCurrentBeginPos = dir == FORWARD ? 0 : edge->getLength();
121  }
122  if (next == 0) {
123  myCurrentEndPos = stage.getArrivalPos();
124  } else {
125  if (dir == UNDEFINED_DIRECTION) {
126  // default to FORWARD if not connected
127  dir = (edge->getFromJunction() == next->getFromJunction() || edge->getFromJunction() == next->getToJunction()) ? BACKWARD : FORWARD;
128  }
129  myCurrentEndPos = dir == FORWARD ? edge->getLength() : 0;
130  }
131  // ensure that a result > 0 is returned even if the walk ends immediately
132  myCurrentDuration = MAX2((SUMOTime)1, TIME2STEPS(fabs(myCurrentEndPos - myCurrentBeginPos) / stage.getMaxSpeed()));
133  //std::cout << SIMTIME << " dir=" << dir << " curBeg=" << myCurrentBeginPos << " curEnd=" << myCurrentEndPos << " speed=" << stage.getMaxSpeed() << " dur=" << myCurrentDuration << "\n";
134  return myCurrentDuration;
135 }
136 
137 
138 SUMOReal
140  //std::cout << SIMTIME << " pos=" << (myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime)) << "\n";
141  return myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime);
142 }
143 
144 
145 Position
147  const MSLane* lane = getSidewalk(stage.getEdge());
148  const SUMOReal lateral_offset = lane->allowsVehicleClass(SVC_PEDESTRIAN) ? 0 : SIDEWALK_OFFSET;
149  return stage.getLanePosition(lane, getEdgePos(stage, now), lateral_offset);
150 }
151 
152 
153 SUMOReal
155  //std::cout << SIMTIME << " rawAngle=" << stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) << " angle=" << stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? 180 : 0) << "\n";
156  SUMOReal angle = stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? 180 : 0);
157  if (angle > 180) {
158  angle -= 360;
159  }
160  return angle;
161 }
162 
163 
164 SUMOTime
166  return 0;
167 }
168 
169 
170 SUMOReal
172  return stage.getMaxSpeed();
173 }
174 
175 /****************************************************************************/
bool blockedAtDist(const MSLane *lane, SUMOReal distToCrossing, std::vector< const MSPerson * > *collectBlockers)
whether a pedestrian is blocking the crossing of lane at offset distToCrossing
const MSEdge * getNextRouteEdge() const
Definition: MSPerson.h:268
is a pedestrian
Position getLanePosition(const MSLane *lane, SUMOReal at, SUMOReal offset) const
get position on lane at length at with orthogonal offset
Definition: MSPerson.cpp:102
SUMOTime computeWalkingTime(const MSEdge *prev, const MSPerson::MSPersonStage_Walking &stage, SUMOTime currentTime)
compute walking time on edge and update state members
MSPerson::MSPersonStage_Walking & myParent
static const int FORWARD
Definition: MSPModel.h:73
T MAX2(T a, T b)
Definition: StdDefs.h:74
static MSLane * getSidewalk(const MSEdge *edge)
return the appropriate lane to walk on
Definition: MSPModel.cpp:93
abstract base class for managing callbacks to retrieve various state information from the model ...
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
SUMOReal getEdgeAngle(const MSEdge *e, SUMOReal at) const
Definition: MSPerson.cpp:108
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
The simulated network and simulation perfomer.
Definition: MSNet.h:94
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSPerson.cpp:143
A road/street connecting two junctions.
Definition: MSEdge.h:81
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:78
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:535
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition: MSLane.h:571
bool moveToNextEdge(MSPerson *person, SUMOTime currentTime, MSEdge *nextInternal=0)
move forward and return whether the person arrived
Definition: MSPerson.cpp:256
PedestrianState * getPedestrianState() const
Definition: MSPerson.h:275
SUMOReal getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the direction in which the person faces in degrees
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
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the time the person spent standing
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:369
MSNet * myNet
the net to which to issue moveToNextEdge commands
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the network coordinate of the person
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
abstract base class for managing callbacks to retrieve various state information from the model ...
Definition: MSPModel.h:96
SUMOReal getArrivalPos() const
Definition: MSPerson.h:261
static const SUMOReal SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk ...
Definition: MSPModel.h:84
SUMOReal getDepartPos() const
Definition: MSPerson.h:258
A storage for options typed value containers)
Definition: OptionsCont.h:108
int SUMOTime
Definition: SUMOTime.h:43
static const int BACKWARD
Definition: MSPModel.h:77
Patch the time in a way that it is at least as high as the simulation begin time. ...
#define SUMOReal
Definition: config.h:218
const MSJunction * getFromJunction() const
Definition: MSEdge.h:345
SUMOReal getSpeed(const MSPerson::MSPersonStage_Walking &stage) const
return the current speed of the person
SUMOReal getMaxSpeed() const
accessors to be used by MSPModel
Definition: MSPerson.h:255
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOTime execute(SUMOTime currentTime)
Executes the command.
const MSJunction * getToJunction() const
Definition: MSEdge.h:349
SUMOReal getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
abstract methods inherited from PedestrianState