SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
10 // Copyright (C) 2014-2014 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);
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 /****************************************************************************/