SUMO - Simulation of Urban MObility
MSContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // The class for modelling container-movements
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 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 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <vector>
36 #include <utils/common/ToString.h>
37 #include <utils/geom/GeomHelper.h>
38 #include "MSNet.h"
39 #include "MSEdge.h"
40 #include "MSLane.h"
41 #include "MSContainer.h"
43 #include "MSTransportableControl.h"
44 #include "MSInsertionControl.h"
45 #include "MSVehicle.h"
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 /* -------------------------------------------------------------------------
56  * MSContainer::MSContainerStage_Driving - methods
57  * ----------------------------------------------------------------------- */
59  MSStoppingPlace* toStop, const SUMOReal arrivalPos, const std::vector<std::string>& lines)
60  : MSTransportable::Stage_Driving(destination, toStop, arrivalPos, lines) {}
61 
62 
64 
65 
66 void
68  if (previous->getDestinationStop() != 0) {
69  // the arrival stop may have an access point
70  myWaitingEdge = &previous->getDestinationStop()->getLane().getEdge();
71  } else {
72  myWaitingEdge = previous->getEdge();
73  }
74  myWaitingPos = previous->getEdgePos(now);
75  myWaitingSince = now;
76  SUMOVehicle* availableVehicle = net->getVehicleControl().getWaitingVehicle(myWaitingEdge, myLines, myWaitingPos, container->getID());
77  if (availableVehicle != 0 && availableVehicle->getParameter().departProcedure == DEPART_CONTAINER_TRIGGERED && !availableVehicle->hasDeparted()) {
78  myVehicle = availableVehicle;
79  myWaitingEdge->removeContainer(container);
80  myVehicle->addContainer(container);
84  } else {
85  net->getContainerControl().addWaiting(myWaitingEdge, container);
86  myWaitingEdge->addContainer(container);
87  }
88 }
89 
90 
91 std::string
93  return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : "transport";
94 }
95 
96 
97 void
99  os.openTag("transport").writeAttr("depart", time2string(myDeparted)).writeAttr("arrival", time2string(myArrived)).closeTag();
100 }
101 
102 
103 void
107 }
108 
109 
110 
111 /* -------------------------------------------------------------------------
112  * MSContainer::MSContainerStage_Tranship - methods
113  * ----------------------------------------------------------------------- */
115  MSStoppingPlace* toStop,
116  SUMOReal speed,
117  SUMOReal departPos, SUMOReal arrivalPos) :
118  MSTransportable::Stage(*route.back(), toStop, SUMOVehicleParameter::interpretEdgePos(
119  arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS, "container getting transhipped to " + route.back()->getID()), MOVING_WITHOUT_VEHICLE), myRoute(route),
120  mySpeed(speed), myContainerState(0), myCurrentInternalEdge(0) {
122  departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS, "container getting transhipped from " + myRoute.front()->getID());
123 }
124 
126 }
127 
128 void
130  previous->getEdge()->removeContainer(container);
131  myRouteStep = myRoute.end() - 1; //define that the container is already on its destination edge
132  myDepartPos = previous->getEdgePos(now);
133  myContainerState = MSCModel_NonInteracting::getModel()->add(container, this, now);
134  (*myRouteStep)->addContainer(container);
135 }
136 
137 const MSEdge*
139  if (myCurrentInternalEdge != 0) {
140  return myCurrentInternalEdge;
141  } else {
142  return *myRouteStep;
143  }
144 }
145 
146 const MSEdge*
148  return myRoute.front();
149 }
150 
151 const MSEdge*
153  return myRoute.back();
154 }
155 
156 SUMOReal
158  return myContainerState->getEdgePos(*this, now);
159 }
160 
161 Position
163  return myContainerState->getPosition(*this, now);
164 }
165 
166 SUMOReal
168  return myContainerState->getAngle(*this, now);
169 }
170 
171 SUMOTime
173  return 0;
174 }
175 
176 SUMOReal
178  return myContainerState->getSpeed(*this);
179 }
180 
181 
184  return myRoute;
185 }
186 
187 
188 void
190  os.openTag("tranship").writeAttr("arrival", time2string(myArrived)).closeTag();
191 }
192 
193 
194 void
196  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
198  os.closeTag();
199 }
200 
201 
202 void
204  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "departure")
205  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.front()->getID()).closeTag();
206 }
207 
208 
209 void
211  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival")
212  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag();
213 }
214 
215 bool
217  ((MSEdge*)getEdge())->removeContainer(container);
218  if (myRouteStep == myRoute.end() - 1) {
219  if (myDestinationStop != 0) {
220  myDestinationStop->addTransportable(container); //jakob
221  }
222  if (!container->proceed(MSNet::getInstance(), currentTime)) {
224  }
225  return true;
226  } else {
227  if (nextInternal == 0) {
228  ++myRouteStep;
230  } else {
231  myCurrentInternalEdge = nextInternal;
232  }
233  ((MSEdge*) getEdge())->addContainer(container);
234  return false;
235  }
236 }
237 
238 /* -------------------------------------------------------------------------
239  * MSContainer - methods
240  * ----------------------------------------------------------------------- */
242  : MSTransportable(pars, vtype, plan) {
243 }
244 
245 
247 }
248 
249 
250 bool
252  Stage* prior = *myStep;
253  prior->setArrived(time);
254  myStep++;
255  if (myStep != myPlan->end()) {
256  (*myStep)->proceed(net, this, time, prior);
257  return true;
258  } else {
259  prior->getEdge()->removeContainer(this);
260  return false;
261  }
262 }
263 
264 
265 void
267  os.openTag("containerinfo").writeAttr("id", getID()).writeAttr("depart", time2string(getDesiredDepart()));
268  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
269  (*i)->tripInfoOutput(os);
270  }
271  os.closeTag();
272 }
273 
274 
275 void
278  if (myStep == myPlan->end()) {
279  os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
280  }
281  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
282  (*i)->routeOutput(os);
283  }
284  os.closeTag();
285  os.lf();
286 }
287 
288 /****************************************************************************/
virtual ~MSContainer()
destructor
void addWaiting(const MSEdge *edge, MSTransportable *person)
adds a transportable to the list of transportables waiting for a vehicle on the specified edge ...
SUMOReal getEdgePos(SUMOTime now) const
Returns the offset from the start of the current edge measured in its natural direction.
SUMOReal myDepartPos
the depart position
Definition: MSContainer.h:214
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
void setArrived(SUMOTime now)
logs end of the step
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:571
virtual void beginEventOutput(const MSTransportable &c, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
long long int SUMOTime
Definition: SUMOTime.h:43
virtual SUMOReal getEdgePos(SUMOTime now) const =0
A lane area vehicles can halt at.
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSContainer.h:211
SUMOReal getEdgePos(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the offset from the start of the current edge measured in its natural direction ...
virtual void proceed(MSNet *net, MSTransportable *container, SUMOTime now, Stage *previous)
proceeds to the next step
Definition: MSContainer.cpp:67
The departure is container triggered.
MSContainerStage_Tranship(const std::vector< const MSEdge * > &route, MSStoppingPlace *toStop, SUMOReal speed, SUMOReal departPos, SUMOReal arrivalPos)
constructor
virtual void addContainer(MSTransportable *container) const
Add a container to myContainers.
Definition: MSEdge.h:615
const MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSContainer.cpp:98
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
const MSEdge * getEdge() const
Returns the current edge.
MSContainerStage_Driving(const MSEdge &destination, MSStoppingPlace *toStop, const SUMOReal arrivalPos, const std::vector< std::string > &lines)
constructor
Definition: MSContainer.cpp:58
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
const std::set< std::string > myLines
the lines to choose from
const std::string & getID() const
returns the id of the transportable
SUMOVehicle * getWaitingVehicle(const MSEdge *const edge, const std::set< std::string > &lines, const SUMOReal position, const std::string ridingID)
void removeWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
Removes a vehicle from the list of waiting vehicles to a given edge.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
virtual bool proceed(MSNet *net, SUMOTime time)=0
MSTransportablePlan::iterator myStep
the iterator over the route
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:620
The simulated network and simulation perfomer.
Definition: MSNet.h:94
The car-following model and parameter.
Definition: MSVehicleType.h:74
virtual void erase(MSTransportable *transportable)
removes a single transportable
SUMOReal getAngle(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the direction in which the container heading to
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
void addTransportable(MSTransportable *p)
adds a transportable to this stop
SUMOTime getDesiredDepart() const
Returns the desired departure time.
CState * add(MSTransportable *container, MSContainer::MSContainerStage_Tranship *stage, SUMOTime now)
register the given container as a transhiped container
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:718
void unregisterOneWaitingForContainer()
decreases the count of vehicles waiting for a container to allow recogniztion of container related de...
static SUMOReal interpretEdgePos(SUMOReal pos, SUMOReal maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
const MSEdge & getDestination() const
returns the destination edge
std::vector< const MSEdge * > myRoute
The route of the container.
Definition: MSContainer.h:208
virtual void addContainer(MSTransportable *container)=0
Adds a container to this vehicle.
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
const MSEdge * getFromEdge() const
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
const MSLane & getLane() const
Returns the lane this stop is located at.
SUMOTime myArrived
the time at which this stage ended
the edges of a route
SUMOTime myDeparted
the time at which this stage started
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
SUMOReal mySpeed
the speed of the container
Definition: MSContainer.h:217
MSStoppingPlace *const myDestinationStop
the stop to reach by getting transported (if any)
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
Position getPosition(SUMOTime now) const
Returns the position of the container.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOReal getSpeed() const
Returns the speed of the container.
SUMOVehicle * myVehicle
The taken vehicle.
virtual void endEventOutput(const MSTransportable &c, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
const MSEdge * getFromEdge() const
Returns first edge of the containers route.
CState * myContainerState
state that is to be manipulated by MSCModel
Definition: MSContainer.h:220
bool moveToNextEdge(MSTransportable *container, SUMOTime currentTime, MSEdge *nextInternal=0)
move forward and return whether the container arrived
virtual void proceed(MSNet *net, MSTransportable *container, SUMOTime now, Stage *previous)
proceeds to the next step
std::string getStageDescription() const
returns the stage description as a string
Definition: MSContainer.cpp:92
Structure representing possible vehicle parameter.
virtual const MSEdge * getEdge() const =0
Returns the current edge.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:361
Position getPosition(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the network coordinate of the container
virtual bool proceed(MSNet *net, SUMOTime time)
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
SUMOTime getWaitingTime(SUMOTime now) const
Returns the time the container spent waiting.
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:208
MSTransportablePlan * myPlan
the plan of the transportable
SUMOReal getSpeed(const MSContainer::MSContainerStage_Tranship &stage) const
return the current speed of the container
MSContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
const MSEdge * getToEdge() const
Returns last edge of the containers route.
SUMOReal getAngle(SUMOTime now) const
Returns the angle of the container.
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
static MSCModel_NonInteracting * getModel()
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:188
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:234
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
ConstMSEdgeVector getEdges() const
the edges of the current stage
MSEdge * myCurrentInternalEdge
The current internal edge this container is on or 0.
Definition: MSContainer.h:223