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-sim.org/
13 // Copyright (C) 2001-2014 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 
34 #include <microsim/MSNet.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSPerson.h>
39 #include "MSDevice_Person.h"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 // ---------------------------------------------------------------------------
50 // static initialisation methods
51 // ---------------------------------------------------------------------------
53 MSDevice_Person::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
54  MSDevice_Person* device = new MSDevice_Person(v, "person_" + v.getID());
55  into.push_back(device);
56  return device;
57 }
58 
59 
60 // ---------------------------------------------------------------------------
61 // MSDevice_Person-methods
62 // ---------------------------------------------------------------------------
63 MSDevice_Person::MSDevice_Person(SUMOVehicle& holder, const std::string& id)
64  : MSDevice(holder, id), myPersons(), myStopped(holder.isStopped()) {
65 }
66 
67 
69 }
70 
71 
72 bool
73 MSDevice_Person::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) {
74  if (myStopped) {
75  if (!veh.isStopped()) {
76  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
77  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
78  }
79  myStopped = false;
80  }
81  } else {
82  if (veh.isStopped()) {
83  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end();) {
84  MSPerson* person = *i;
85  if (&(person->getDestination()) == veh.getEdge()) {
88  }
89  i = myPersons.erase(i);
90  } else {
91  ++i;
92  }
93  }
94  myStopped = true;
95  }
96  }
97  return true;
98 }
99 
100 
101 bool
104  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
105  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
106  }
107  }
108  return true;
109 }
110 
111 
112 bool
115  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
116  for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
117  MSPerson* person = *i;
118  if (&(person->getDestination()) != veh.getEdge()) {
119  WRITE_WARNING("Teleporting person '" + person->getID() +
120  "' from vehicle destination '" + veh.getEdge()->getID() +
121  "' to intended destination '" + person->getDestination().getID() + "'");
122  }
125  };
126  }
127  }
128  return true;
129 }
130 
131 
132 void
134  myPersons.push_back(person);
135 }
136 
137 
138 /****************************************************************************/
139