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-2013 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 
~MSDevice_Person()
Destructor.
const std::string & getID() const
returns the person id
Definition: MSPerson.cpp:553
bool myStopped
Whether the vehicle is at a stop.
static MSDevice_Person * buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
Notification
Definition of a vehicle state.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:150
SUMOTime getCurrentTimeStep() const
Returns the current simulation step (in s)
Definition: MSNet.cpp:500
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
const MSEdge & getDestination() const
Returns the current destination.
Definition: MSPerson.h:514
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the vehicle is at a stop and person action is needed.
const std::string & getID() const
Returns the id.
Definition: Named.h:60
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Adds passengers on vehicle insertion.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
void addPerson(MSPerson *person)
Add a passenger.
The vehicle arrived at its destination (is deleted)
Abstract in-vehicle device.
Definition: MSDevice.h:68
The vehicle has departed (was inserted into the network)
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:602
bool proceed(MSNet *net, SUMOTime time)
Definition: MSPerson.cpp:559
MSDevice_Person(SUMOVehicle &holder, const std::string &id)
Constructor.
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Passengers leaving on arrival.
std::vector< MSPerson * > myPersons
The passengers of the vehicle.
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop.
#define SUMOReal
Definition: config.h:221
virtual void erase(MSPerson *person)
removes a single person
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.