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-2016 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 
182 void
184  os.openTag("tranship").writeAttr("arrival", time2string(myArrived)).closeTag();
185 }
186 
187 
188 void
190  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
192  os.closeTag();
193 }
194 
195 
196 void
198  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "departure")
199  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.front()->getID()).closeTag();
200 }
201 
202 
203 void
205  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival")
206  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag();
207 }
208 
209 bool
211  ((MSEdge*)getEdge())->removeContainer(container);
212  if (myRouteStep == myRoute.end() - 1) {
213  if (myDestinationStop != 0) {
214  myDestinationStop->addTransportable(container); //jakob
215  }
216  if (!container->proceed(MSNet::getInstance(), currentTime)) {
218  }
219  return true;
220  } else {
221  if (nextInternal == 0) {
222  ++myRouteStep;
224  } else {
225  myCurrentInternalEdge = nextInternal;
226  }
227  ((MSEdge*) getEdge())->addContainer(container);
228  return false;
229  }
230 }
231 
232 /* -------------------------------------------------------------------------
233  * MSContainer - methods
234  * ----------------------------------------------------------------------- */
236  : MSTransportable(pars, vtype, plan) {
237 }
238 
239 
241 }
242 
243 
244 bool
246  Stage* prior = *myStep;
247  prior->setArrived(time);
248  myStep++;
249  if (myStep != myPlan->end()) {
250  (*myStep)->proceed(net, this, time, prior);
251  return true;
252  } else {
253  prior->getEdge()->removeContainer(this);
254  return false;
255  }
256 }
257 
258 
259 void
261  os.openTag("containerinfo").writeAttr("id", getID()).writeAttr("depart", time2string(getDesiredDepart()));
262  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
263  (*i)->tripInfoOutput(os);
264  }
265  os.closeTag();
266 }
267 
268 
269 void
272  if (myStep == myPlan->end()) {
273  os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
274  }
275  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
276  (*i)->routeOutput(os);
277  }
278  os.closeTag();
279  os.lf();
280 }
281 
282 /****************************************************************************/
Position getPosition(SUMOTime now) const
Returns the position of the container.
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 myDepartPos
the depart position
Definition: MSContainer.h:211
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
void setArrived(SUMOTime now)
logs end of the step
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:571
long long int SUMOTime
Definition: SUMOTime.h:43
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
A lane area vehicles can halt at.
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSContainer.h:208
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.
SUMOReal getAngle(SUMOTime now) const
Returns the angle of the container.
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
virtual const MSEdge * getEdge() const =0
Returns the current edge.
const MSEdge * getToEdge() const
Returns last edge of the containers route.
virtual SUMOReal getEdgePos(SUMOTime now) const =0
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
MSContainerStage_Driving(const MSEdge &destination, MSStoppingPlace *toStop, const SUMOReal arrivalPos, const std::vector< std::string > &lines)
constructor
Definition: MSContainer.cpp:58
SUMOReal getEdgePos(SUMOTime now) const
Returns the offset from the start of the current edge measured in its natural direction.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
const MSEdge * getFromEdge() const
Returns first edge of the containers route.
const std::set< std::string > myLines
the lines to choose from
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.
virtual bool proceed(MSNet *net, SUMOTime time)=0
MSTransportablePlan::iterator myStep
the iterator over the route
const MSEdge * getFromEdge() const
SUMOReal getSpeed(const MSContainer::MSContainerStage_Tranship &stage) const
return the current speed of the container
virtual void endEventOutput(const MSTransportable &c, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
The simulated network and simulation perfomer.
Definition: MSNet.h:93
The car-following model and parameter.
Definition: MSVehicleType.h:74
virtual void erase(MSTransportable *transportable)
removes a single transportable
void addTransportable(MSTransportable *p)
adds a transportable to this stop
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:707
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.
std::vector< const MSEdge * > myRoute
The route of the container.
Definition: MSContainer.h:205
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
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.
A road/street connecting two junctions.
Definition: MSEdge.h:80
SUMOReal getSpeed() const
Returns the speed of the container.
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
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 tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
SUMOTime myArrived
the time at which this stage ended
the edges of a route
SUMOTime myDeparted
the time at which this stage started
Representation of a vehicle.
Definition: SUMOVehicle.h:66
SUMOReal mySpeed
the speed of the container
Definition: MSContainer.h:214
MSStoppingPlace *const myDestinationStop
the stop to reach by getting transported (if any)
MSContainerStage_Tranship(const std::vector< const MSEdge *> &route, MSStoppingPlace *toStop, SUMOReal speed, SUMOReal departPos, SUMOReal arrivalPos)
constructor
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOTime getDesiredDepart() const
Returns the desired departure time.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSContainer.cpp:98
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
const std::string & getID() const
returns the id of the transportable
SUMOVehicle * myVehicle
The taken vehicle.
CState * myContainerState
state that is to be manipulated by MSCModel
Definition: MSContainer.h:217
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:631
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
virtual void beginEventOutput(const MSTransportable &c, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
Structure representing possible vehicle parameter.
const MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
std::string getStageDescription() const
returns the stage description as a string
Definition: MSContainer.cpp:92
virtual void addContainer(MSTransportable *container) const
Add a container to myContainers.
Definition: MSEdge.h:626
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:360
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)
virtual bool proceed(MSNet *net, SUMOTime time)
SUMOTime getWaitingTime(SUMOTime now) const
Returns the time the container spent waiting.
const MSEdge & getDestination() const
returns the destination edge
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:188
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
SUMOReal getAngle(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the direction in which the container heading to
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
MSTransportablePlan * myPlan
the plan of the transportable
const MSEdge * getEdge() const
Returns the current edge.
MSContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
const MSLane & getLane() const
Returns the lane this stop is located at.
Position getPosition(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the network coordinate of the container
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
static MSCModel_NonInteracting * getModel()
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:235
MSEdge * myCurrentInternalEdge
The current internal edge this container is on or 0.
Definition: MSContainer.h:220