SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_Person.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A device which is used to keep track of Persons riding with a vehicle
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 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "MSDevice_Person.h"
34 #include <microsim/MSNet.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSPerson.h>
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // static initialisation methods
50 // ---------------------------------------------------------------------------
52 MSDevice_Person::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*> &into) {
53  MSDevice_Person* device = new MSDevice_Person(v, "person_" + v.getID());
54  into.push_back(device);
55  return device;
56 }
57 
58 
59 // ---------------------------------------------------------------------------
60 // MSDevice_Person-methods
61 // ---------------------------------------------------------------------------
62 MSDevice_Person::MSDevice_Person(SUMOVehicle& holder, const std::string& id)
63  : MSDevice(holder, id), myPersons(), myStopped(holder.isStopped()) {
64 }
65 
66 
68 }
69 
70 
71 bool
72 MSDevice_Person::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) {
73  if (myStopped) {
74  if (!veh.isStopped()) {
75  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
76  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
77  }
78  myStopped = false;
79  }
80  } else {
81  if (veh.isStopped()) {
82  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end();) {
83  if (&(*i)->getDestination() == veh.getEdge()) {
84  (*i)->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep());
85  i = myPersons.erase(i);
86  } else {
87  ++i;
88  }
89  }
90  myStopped = true;
91  }
92  }
93  return true;
94 }
95 
96 
97 bool
100  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
101  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
102  }
103  }
104  return true;
105 }
106 
107 
108 bool
111  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
112  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
113  if (&(*i)->getDestination() != veh.getEdge()) {
114  WRITE_WARNING("Teleporting person '" + (*i)->getID() +
115  "' from vehicle destination '" + veh.getEdge()->getID() +
116  "' to intended destination '" + (*i)->getDestination().getID() + "'");
117  }
118  (*i)->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep());
119  }
120  }
121  return true;
122 }
123 
124 
125 void
127  myPersons.push_back(person);
128 }
129 
130 
131 /****************************************************************************/
132