SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSDevice_Container.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A device which is used to keep track of containers riding with a vehicle
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifdef _MSC_VER
22 #include <windows_config.h>
23 #else
24 #include <config.h>
25 #endif
26 
27 //#include <utils/iodevices/OutputDevice.h>
28 #include <microsim/MSNet.h>
29 //#include <microsim/MSLane.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSContainer.h>
34 #include "MSDevice_Container.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 // ---------------------------------------------------------------------------
45 // static initialisation methods
46 // ---------------------------------------------------------------------------
48 MSDevice_Container::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
49  MSDevice_Container* device = new MSDevice_Container(v, "container_" + v.getID());
50  into.push_back(device);
51  return device;
52 }
53 
54 
55 // ---------------------------------------------------------------------------
56 // MSDevice_Container-methods
57 // ---------------------------------------------------------------------------
58 MSDevice_Container::MSDevice_Container(SUMOVehicle& holder, const std::string& id)
59  : MSDevice(holder, id), myContainers(), myStopped(holder.isStopped()) {
60 }
61 
62 
64 }
65 
66 
67 bool
68 MSDevice_Container::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) {
69  if (myStopped) {
70  // if veh is not anymore at the stop
71  if (!veh.isStopped()) {
72  for (std::vector<MSContainer*>::iterator i = myContainers.begin(); i != myContainers.end(); ++i) {
73  (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
74  }
75  myStopped = false;
76  }
77  } else {
78  if (veh.isStopped()) {
79  for (std::vector<MSContainer*>::iterator i = myContainers.begin(); i != myContainers.end();) {
80  MSContainer* container = *i;
81  if (&(container->getDestination()) == veh.getEdge()) {
84  }
85  i = myContainers.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<MSContainer*>::iterator i = myContainers.begin(); i != myContainers.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<MSContainer*>::iterator i = myContainers.begin(); i != myContainers.end(); ++i) {
113  MSContainer* container = *i;
114  if (&(container->getDestination()) != veh.getEdge()) {
115  WRITE_WARNING("Teleporting container '" + container->getID() +
116  "' from vehicle destination '" + veh.getEdge()->getID() +
117  "' to intended destination '" + container->getDestination().getID() + "'");
118  }
121  };
122  }
123  }
124  return true;
125 }
126 
127 
128 void
130  myContainers.push_back(container);
131 }
132 
133 
134 /****************************************************************************/
135 
std::vector< MSContainer * > myContainers
The containers of the vehicle.
void addContainer(MSContainer *container)
Add a container.
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
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:235
MSDevice_Container(SUMOVehicle &holder, const std::string &id)
Constructor.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
virtual void erase(MSContainer *container)
removes a single container
const std::string & getID() const
Returns the id.
Definition: Named.h:60
static MSDevice_Container * buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
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 container action is needed.
Representation of a vehicle.
Definition: SUMOVehicle.h:65
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Containers leaving on arrival.
~MSDevice_Container()
Destructor.
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:666
The vehicle arrived at its destination (is deleted)
Abstract in-vehicle device.
Definition: MSDevice.h:69
The vehicle has departed (was inserted into the network)
bool myStopped
Whether the vehicle is at a stop.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Adds containers on vehicle insertion.
bool proceed(MSNet *net, SUMOTime time)
const std::string & getID() const
returns the container id
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop.
#define SUMOReal
Definition: config.h:218
const MSEdge & getDestination() const
Returns the current destination.
Definition: MSContainer.h:596
virtual const std::string & getID() const =0
Get the vehicle's ID.