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>
40 #include "MSDevice_Transportable.h"
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 // ---------------------------------------------------------------------------
51 // static initialisation methods
52 // ---------------------------------------------------------------------------
54 MSDevice_Transportable::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into, const bool isContainer) {
55  MSDevice_Transportable* device = new MSDevice_Transportable(v, isContainer ? "container_" + v.getID() : "person_" + v.getID(), isContainer);
56  into.push_back(device);
57  return device;
58 }
59 
60 
61 // ---------------------------------------------------------------------------
62 // MSDevice_Transportable-methods
63 // ---------------------------------------------------------------------------
64 MSDevice_Transportable::MSDevice_Transportable(SUMOVehicle& holder, const std::string& id, const bool isContainer)
65  : MSDevice(holder, id), myAmContainer(isContainer), myTransportables(), myStopped(holder.isStopped()) {
66 }
67 
68 
70 }
71 
72 
73 bool
74 MSDevice_Transportable::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) {
75  if (myStopped) {
76  if (!veh.isStopped()) {
77  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end(); ++i) {
78  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
79  }
80  myStopped = false;
81  }
82  } else {
83  if (veh.isStopped()) {
84  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end();) {
85  MSTransportable* transportable = *i;
86  if (&(transportable->getDestination()) == veh.getEdge()) {
87  if (!transportable->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep())) {
88  if (myAmContainer) {
89  MSNet::getInstance()->getContainerControl().erase(transportable);
90  } else {
91  MSNet::getInstance()->getPersonControl().erase(transportable);
92  }
93  }
94  i = myTransportables.erase(i);
95  } else {
96  ++i;
97  }
98  }
99  myStopped = true;
100  }
101  }
102  return true;
103 }
104 
105 
106 bool
109  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end(); ++i) {
110  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
111  }
112  }
113  return true;
114 }
115 
116 
117 bool
120  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
121  for (std::vector<MSTransportable*>::iterator i = myTransportables.begin(); i != myTransportables.end(); ++i) {
122  MSTransportable* transportable = *i;
123  if (&(transportable->getDestination()) != veh.getEdge()) {
124  WRITE_WARNING((myAmContainer ? "Teleporting container '" : "Teleporting person '") + transportable->getID() +
125  "' from vehicle destination edge '" + veh.getEdge()->getID() +
126  "' to intended destination edge '" + transportable->getDestination().getID() + "'");
127  }
128  if (!transportable->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep())) {
129  if (myAmContainer) {
130  MSNet::getInstance()->getContainerControl().erase(transportable);
131  } else {
132  MSNet::getInstance()->getPersonControl().erase(transportable);
133  }
134  }
135  }
136  }
137  return true;
138 }
139 
140 
141 void
143  myTransportables.push_back(transportable);
144 }
145 
146 
147 /****************************************************************************/
148 
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:159
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:254
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Adds passengers on vehicle insertion.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
virtual void erase(MSTransportable *transportable)
removes a single transportable
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:707
const std::string & getID() const
Returns the id.
Definition: Named.h:66
Representation of a vehicle.
Definition: SUMOVehicle.h:66
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:699
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.
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 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.