SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSPerson.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // The class for modelling person-movements
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 #include "MSNet.h"
37 #include "MSEdge.h"
38 #include "MSLane.h"
39 #include "MSPerson.h"
40 #include "MSPersonControl.h"
41 #include "MSInsertionControl.h"
42 #include "MSVehicle.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 /* -------------------------------------------------------------------------
54  * MSPerson::MSPersonStage - methods
55  * ----------------------------------------------------------------------- */
57  : myDestination(destination), myDeparted(-1), myArrived(-1) {}
58 
59 
61 
62 
63 const MSEdge&
65  return myDestination;
66 }
67 
68 
69 void
71  if (myDeparted < 0) {
72  myDeparted = now;
73  }
74 }
75 
76 
77 void
79  myArrived = now;
80 }
81 
82 
83 bool
84 MSPerson::MSPersonStage::isWaitingFor(const std::string& /*line*/) const {
85  return false;
86 }
87 
88 /* -------------------------------------------------------------------------
89  * MSPerson::MSPersonStage_Walking - methods
90  * ----------------------------------------------------------------------- */
92  : MSPersonStage(*route.back()), myWalkingTime(walkingTime) {
93  if (speed > 0) {
94  SUMOReal time = 0;
95  for (MSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
96  time += ((*it)->getLanes())[0]->getLength() / speed;
97  }
98  myWalkingTime = MAX2(walkingTime, TIME2STEPS(time));
99  }
100 }
101 
102 
104 
105 
106 void
108  MSPerson* person, SUMOTime now,
109  const MSEdge& /*previousEdge*/) {
110  net->getPersonControl().setArrival(MAX2(now, now + myWalkingTime), person);
111 }
112 
113 
114 void
116  (os.openTag("walk") <<
117  " arrival=\"" << time2string(myArrived) <<
118  "\"").closeTag(true);
119 }
120 
121 
122 
123 /* -------------------------------------------------------------------------
124  * MSPerson::MSPersonStage_Driving - methods
125  * ----------------------------------------------------------------------- */
127  const std::vector<std::string> &lines)
128  : MSPersonStage(destination), myLines(lines.begin(), lines.end()) {}
129 
130 
132 
133 
134 void
136  MSPerson* person, SUMOTime /*now*/,
137  const MSEdge& previousEdge) {
138  SUMOVehicle* v = net->getVehicleControl().getWaitingVehicle(&previousEdge, myLines);
139  if (v != 0 && v->getParameter().departProcedure == DEPART_TRIGGERED) {
140  v->addPerson(person);
141  net->getInsertionControl().add(v);
142  net->getVehicleControl().removeWaiting(&previousEdge, v);
144  } else {
145  net->getPersonControl().addWaiting(&previousEdge, person);
146  }
147 }
148 
149 
150 bool
151 MSPerson::MSPersonStage_Driving::isWaitingFor(const std::string& line) const {
152  return myLines.count(line) > 0;
153 }
154 
155 
156 void
158  (os.openTag("ride") <<
159  " depart=\"" << time2string(myDeparted) <<
160  "\" arrival=\"" << time2string(myArrived) <<
161  "\"").closeTag(true);
162 }
163 
164 
165 /* -------------------------------------------------------------------------
166  * MSPerson::MSPersonStage_Waiting - methods
167  * ----------------------------------------------------------------------- */
169  SUMOTime duration, SUMOTime until)
170  : MSPersonStage(destination), myWaitingDuration(duration), myWaitingUntil(until) {}
171 
172 
174 
175 
176 void
178  MSPerson* person, SUMOTime now,
179  const MSEdge& /*previousEdge*/) {
180  const SUMOTime until = MAX3(now, now + myWaitingDuration, myWaitingUntil);
181  net->getPersonControl().setArrival(until, person);
182 }
183 
184 
185 void
187  (os.openTag("stop") <<
188  " arrival=\"" << time2string(myArrived) <<
189  "\"").closeTag(true);
190 }
191 
192 
193 /* -------------------------------------------------------------------------
194  * MSPerson - methods
195  * ----------------------------------------------------------------------- */
197  : myParameter(pars), myPlan(plan) {
198  myStep = myPlan->begin();
199 }
200 
201 
203  for (MSPersonPlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
204  delete *i;
205  }
206  delete myPlan;
207  delete myParameter;
208 }
209 
210 
211 const std::string&
213  return myParameter->id;
214 }
215 
216 
217 void
219  const MSEdge& arrivedAt = (*myStep)->getDestination();
220  (*myStep)->setArrived(time);
221  myStep++;
222  if (myStep != myPlan->end()) {
223  (*myStep)->proceed(net, this, time, arrivedAt);
224  } else {
225  net->getPersonControl().erase(this);
226  }
227 }
228 
229 
230 SUMOTime
232  return myParameter->depart;
233 }
234 
235 
236 void
238  (*myStep)->setDeparted(now);
239 }
240 
241 
242 const MSEdge&
244  return (*myStep)->getDestination();
245 }
246 
247 
248 void
250  for (MSPersonPlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
251  (*i)->tripInfoOutput(os);
252  }
253 }
254 
255 
256 bool
257 MSPerson::isWaitingFor(const std::string& line) const {
258  return (*myStep)->isWaitingFor(line);
259 }
260 
261 
262 /****************************************************************************/
263