SUMO - Simulation of Urban MObility
MSDevice_Transportable.cpp
Go to the documentation of this file.
1 /****************************************************************************/
12 // A device which is used to keep track of persons and containers riding with a vehicle
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
15 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <microsim/MSNet.h>
36 #include <microsim/MSEdge.h>
39 #include <microsim/MSContainer.h>
41 #include "MSDevice_Transportable.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 // ---------------------------------------------------------------------------
52 // static initialisation methods
53 // ---------------------------------------------------------------------------
55 MSDevice_Transportable::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into, const bool isContainer) {
56  MSDevice_Transportable* device = new MSDevice_Transportable(v, isContainer ? "container_" + v.getID() : "person_" + v.getID(), isContainer);
57  into.push_back(device);
58  return device;
59 }
60 
61 
62 // ---------------------------------------------------------------------------
63 // MSDevice_Transportable-methods
64 // ---------------------------------------------------------------------------
65 MSDevice_Transportable::MSDevice_Transportable(SUMOVehicle& holder, const std::string& id, const bool isContainer)
66  : MSDevice(holder, id), myAmContainer(isContainer), myTransportables(), myStopped(holder.isStopped()) {
67 }
68 
69 
71 }
72 
73 
74 bool
75 MSDevice_Transportable::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) {
76  if (myStopped) {
77  if (!veh.isStopped()) {
78  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end(); ++i) {
79  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
80  }
81  myStopped = false;
82  }
83  } else {
84  if (veh.isStopped()) {
85  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end();) {
86  MSTransportable* transportable = *i;
87  if (&(transportable->getDestination()) == veh.getEdge()) {
88  if (!transportable->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep())) {
89  if (myAmContainer) {
90  MSNet::getInstance()->getContainerControl().erase(transportable);
91  } else {
92  MSNet::getInstance()->getPersonControl().erase(transportable);
93  }
94  }
95  i = myTransportables.erase(i);
96  } else {
97  ++i;
98  }
99  }
100  myStopped = true;
101  }
102  }
103  return true;
104 }
105 
106 
107 bool
110  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end(); ++i) {
111  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
112  }
113  }
114  return true;
115 }
116 
117 
118 bool
121  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
122  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end(); ++i) {
123  MSTransportable* transportable = *i;
124  if (&(transportable->getDestination()) != veh.getEdge()) {
125  WRITE_WARNING((myAmContainer ? "Teleporting container '" : "Teleporting person '") + transportable->getID() +
126  "' from vehicle destination edge '" + veh.getEdge()->getID() +
127  "' to intended destination edge '" + transportable->getDestination().getID() + "'");
128  }
129  if (!transportable->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep())) {
130  if (myAmContainer) {
131  MSNet::getInstance()->getContainerControl().erase(transportable);
132  } else {
133  MSNet::getInstance()->getPersonControl().erase(transportable);
134  }
135  }
136  }
137  }
138  return true;
139 }
140 
141 
142 void
144  myTransportables.push_back(transportable);
145 }
146 
147 
148 /****************************************************************************/
149 
virtual void erase(MSTransportable *person)
removes a single person
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:160
const std::string & getID() const
returns the id of the transportable
virtual bool proceed(MSNet *net, SUMOTime time)=0
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:255
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Adds passengers on vehicle insertion.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
const std::string & getID() const
Returns the id.
Definition: Named.h:65
Representation of a vehicle.
Definition: SUMOVehicle.h:65
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:698
The vehicle arrived at its destination (is deleted)
void addTransportable(MSTransportable *transportable)
Add a passenger.
const MSEdge & getDestination() const
Returns the current destination.
bool myAmContainer
Whether it is a container device.
Abstract in-vehicle device.
Definition: MSDevice.h:69
The vehicle has departed (was inserted into the network)
static MSDevice_Transportable * buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into, const bool isContainer)
Build devices for the given vehicle, if needed.
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:690
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the vehicle is at a stop and transportable action is needed.
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop.
#define SUMOReal
Definition: config.h:213
MSDevice_Transportable(SUMOVehicle &holder, const std::string &id, const bool isContainer)
Constructor.
bool myStopped
Whether the vehicle is at a stop.
std::vector< MSTransportable * > myTransportables
The passengers of the vehicle.
virtual void erase(MSTransportable *container)
removes a single container
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Passengers leaving on arrival.