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-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 
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 "MSContainerControl.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  * static member definitions
54  * ----------------------------------------------------------------------- */
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 /* -------------------------------------------------------------------------
61  * MSContainer::MSContainerStage_Driving - methods
62  * ----------------------------------------------------------------------- */
64  MSStoppingPlace* toStop, const SUMOReal arrivalPos, const std::vector<std::string>& lines)
65  : MSTransportable::Stage(destination, toStop, arrivalPos, DRIVING), myLines(lines.begin(), lines.end()),
66  myVehicle(0) {}
67 
68 
70 
71 void
73  if (previous->getDestinationStop() != 0) {
74  // the arrival stop may have an access point
75  myWaitingEdge = &previous->getDestinationStop()->getLane().getEdge();
76  } else {
77  myWaitingEdge = previous->getEdge();
78  }
79  myWaitingPos = previous->getEdgePos(now);
80  myWaitingSince = now;
81  SUMOVehicle* availableVehicle = net->getVehicleControl().getWaitingVehicle(myWaitingEdge, myLines, myWaitingPos, container->getID());
82  if (availableVehicle != 0 && availableVehicle->getParameter().departProcedure == DEPART_CONTAINER_TRIGGERED) {
83  myVehicle = availableVehicle;
84  myWaitingEdge->removeContainer(container);
85  myVehicle->addContainer(container);
89  } else {
90  net->getContainerControl().addWaiting(myWaitingEdge, container);
91  myWaitingEdge->addContainer(container);
92  }
93 }
94 
95 const MSEdge*
97  if (myVehicle != 0) {
98  return myVehicle->getEdge();
99  }
100  return myWaitingEdge;
101 }
102 
103 
104 const MSEdge*
106  return myWaitingEdge;
107 }
108 
109 
110 SUMOReal
112  if (myVehicle != 0) {
113  // vehicle may already have passed the lane (check whether this is correct)
115  }
116  return myWaitingPos;
117 }
118 
119 Position
121  if (myVehicle != 0) {
123  return myVehicle->getEdge()->getLanes()[0]->getShape().positionAtOffset(myVehicle->getPositionOnLane());
124  }
126 }
127 
128 SUMOReal
130  if (myVehicle != 0) {
131  MSVehicle* veh = dynamic_cast<MSVehicle*>(myVehicle);
132  if (veh != 0) {
133  return veh->getAngle();
134  } else {
135  return 0;
136  }
137  }
139 }
140 
141 bool
143  return myLines.count(line) > 0;
144 }
145 
146 bool
148  return myVehicle == 0;
149 }
150 
151 SUMOTime
153  return isWaiting4Vehicle() ? now - myWaitingSince : 0;
154 }
155 
156 SUMOReal
158  return myVehicle == 0 ? 0 : myVehicle->getSpeed();
159 }
160 
161 std::string
163  return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : "transport";
164 }
165 
168  return myDepartContainerStop;
169 }
170 
171 void
173  os.openTag("transport").writeAttr("depart", time2string(myDeparted)).writeAttr("arrival", time2string(myArrived)).closeTag();
174 }
175 
176 void
180 }
181 
182 void
184  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival").writeAttr("agent", container.getID()).writeAttr("link", getEdge()->getID()).closeTag();
185 }
186 
187 void
189  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival").writeAttr("agent", container.getID()).writeAttr("link", getEdge()->getID()).closeTag();
190 }
191 
192 
193 
194 /* -------------------------------------------------------------------------
195  * MSContainer::MSContainerStage_Waiting - methods
196  * ----------------------------------------------------------------------- */
198  SUMOTime duration, SUMOTime until, SUMOReal pos, const std::string& actType) :
199  MSTransportable::Stage(destination, 0, SUMOVehicleParameter::interpretEdgePos(
200  pos, destination.getLength(), SUMO_ATTR_DEPARTPOS, "container stopping at " + destination.getID()), WAITING),
201  myWaitingDuration(duration),
202  myWaitingUntil(until),
203  myActType(actType) {
204 }
205 
207 
208 const MSEdge*
210  return &myDestination;
211 }
212 
213 const MSEdge*
215  return &myDestination;
216 }
217 
218 SUMOReal
220  return myArrivalPos;
221 }
222 
223 SUMOTime
225  return myWaitingUntil;
226 }
227 
228 Position
231 }
232 
233 SUMOReal
236 }
237 
238 SUMOTime
240  return now - myWaitingStart;
241 }
242 
243 SUMOReal
245  return 0;
246 }
247 
250  return myCurrentContainerStop;
251 }
252 
253 void
255  previous->getEdge()->addContainer(container);
256  myWaitingStart = now;
257  const SUMOTime until = MAX3(now, now + myWaitingDuration, myWaitingUntil);
258  net->getContainerControl().setWaitEnd(until, container);
259 }
260 
261 void
263  os.openTag("stop").writeAttr("arrival", time2string(myArrived)).closeTag();
264 }
265 
266 void
269  if (myWaitingDuration >= 0) {
271  }
272  if (myWaitingUntil >= 0) {
274  }
275  os.closeTag();
276 }
277 
278 void
280  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "actstart " + myActType)
281  .writeAttr("agent", container.getID()).writeAttr("link", getEdge()->getID()).closeTag();
282 }
283 
284 void
286  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "actend " + myActType).writeAttr("agent", container.getID())
287  .writeAttr("link", getEdge()->getID()).closeTag();
288 }
289 
290 /* -------------------------------------------------------------------------
291  * MSContainer::MSContainerStage_Tranship - methods
292  * ----------------------------------------------------------------------- */
294  MSStoppingPlace* toStop,
295  SUMOReal speed,
296  SUMOReal departPos, SUMOReal arrivalPos) :
297  MSTransportable::Stage(*route.back(), toStop, SUMOVehicleParameter::interpretEdgePos(
298  arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS, "container getting transhipped to " + route.back()->getID()), MOVING_WITHOUT_VEHICLE), myRoute(route),
299  mySpeed(speed), myContainerState(0), myCurrentInternalEdge(0) {
301  departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS, "container getting transhipped from " + myRoute.front()->getID());
302 }
303 
305 }
306 
307 void
309  previous->getEdge()->removeContainer(container);
310  myRouteStep = myRoute.end() - 1; //define that the container is already on its destination edge
312  myDepartPos = previous->getEdgePos(now);
313  myContainerState = MSCModel_NonInteracting::getModel()->add(container, this, now);
314  (*myRouteStep)->addContainer(container);
315 }
316 
317 const MSEdge*
319  if (myCurrentInternalEdge != 0) {
320  return myCurrentInternalEdge;
321  } else {
322  return *myRouteStep;
323  }
324 }
325 
326 const MSEdge*
328  return myRoute.front();
329 }
330 
331 const MSEdge*
333  return myRoute.back();
334 }
335 
336 SUMOReal
338  return myContainerState->getEdgePos(*this, now);
339 }
340 
341 Position
343  return myContainerState->getPosition(*this, now);
344 }
345 
346 SUMOReal
348  return myContainerState->getAngle(*this, now);
349 }
350 
351 SUMOTime
353  return 0;
354 }
355 
356 SUMOReal
358  return myContainerState->getSpeed(*this);
359 }
360 
363  return myDepartContainerStop;
364 }
365 
366 void
368  os.openTag("tranship").writeAttr("arrival", time2string(myArrived)).closeTag();
369 }
370 
371 
372 void
374  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
376  os.closeTag();
377 }
378 
379 
380 void
382  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "departure")
383  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.front()->getID()).closeTag();
384 }
385 
386 
387 void
389  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival")
390  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag();
391 }
392 
393 bool
395  ((MSEdge*)getEdge())->removeContainer(container);
396  if (myRouteStep == myRoute.end() - 1) {
398  if (myDestinationStop != 0) {
399  myDestinationStop->addTransportable(container); //jakob
400  }
401  if (!container->proceed(MSNet::getInstance(), currentTime)) {
403  }
404  return true;
405  } else {
406  if (nextInternal == 0) {
407  ++myRouteStep;
409  } else {
410  myCurrentInternalEdge = nextInternal;
411  }
412  ((MSEdge*) getEdge())->addContainer(container);
413  return false;
414  }
415 }
416 
417 /* -------------------------------------------------------------------------
418  * MSContainer - methods
419  * ----------------------------------------------------------------------- */
421  : MSTransportable(pars, vtype, plan) {
422 }
423 
425 }
426 
427 bool
429  Stage* prior = *myStep;
430  prior->setArrived(time);
431  myStep++;
432  if (myStep != myPlan->end()) {
433  (*myStep)->proceed(net, this, time, prior);
434  return true;
435  } else {
436  prior->getEdge()->removeContainer(this);
437  return false;
438  }
439 }
440 
441 
442 void
444  MSTransportablePlan::const_iterator i = myPlan->begin();
445  if ((*i)->getStageType() == WAITING && getDesiredDepart() == static_cast<MSContainerStage_Waiting*>(*i)->getUntil()) {
446  ++i;
447  }
448  for (; i != myPlan->end(); ++i) {
449  (*i)->routeOutput(os);
450  }
451 }
452 
453 
454 /****************************************************************************/
virtual ~MSContainer()
destructor
SUMOReal getEdgePos(SUMOTime now) const
Returns the offset from the start of the current edge measured in its natural direction.
const std::set< std::string > myLines
the lines to choose from
Definition: MSContainer.h:163
SUMOReal myDepartPos
the depart position
Definition: MSContainer.h:396
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:461
virtual void beginEventOutput(const MSTransportable &c, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getAngle(SUMOTime now) const
the angle of the edge minus 90deg
MSStoppingPlace * myDepartContainerStop
The container stop from which the container departs.
Definition: MSContainer.h:399
SUMOTime myWaitingDuration
the time the container is waiting
Definition: MSContainer.h:265
A lane area vehicles can halt at.
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSContainer.h:393
virtual void proceed(MSNet *net, MSTransportable *container, SUMOTime now, Stage *previous)
proceeds to the next step
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:186
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:72
The departure is container triggered.
#define M_PI
Definition: angles.h:37
bool isWaitingFor(const std::string &line) const
Whether the container waits for a vehicle of the line specified.
MSContainerStage_Tranship(const std::vector< const MSEdge * > &route, MSStoppingPlace *toStop, SUMOReal speed, SUMOReal departPos, SUMOReal arrivalPos)
constructor
MSStoppingPlace * myDepartContainerStop
The container stop from which the container departs.
Definition: MSContainer.h:169
SUMOTime getWaitingTime(SUMOTime now) const
time spent waiting for a ride
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
virtual void addContainer(MSTransportable *container) const
Add a container to myContainers.
Definition: MSEdge.h:566
virtual const MSEdge * getEdge() const =0
Returns the current edge.
const MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
virtual SUMOReal getEdgePos(SUMOTime now) const =0
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
SUMOTime getWaitingTime(SUMOTime now) const
the time this transportable spent waiting
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:63
SUMOReal getSpeed() const
Returns the speed of the container which is always zero in that stage.
MSContainerStage_Waiting(const MSEdge &destination, SUMOTime duration, SUMOTime until, SUMOReal pos, const std::string &actType)
constructor
void addWaiting(const MSEdge *edge, MSTransportable *container)
adds a container to the list of containers waiting for a vehicle on the specified edge ...
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
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.
virtual bool proceed(MSNet *net, SUMOTime time)=0
SUMOReal getEdgePos(SUMOTime now) const
MSTransportablePlan::iterator myStep
the iterator over the route
SUMOTime myWaitingUntil
the time until the container is waiting
Definition: MSContainer.h:268
virtual void beginEventOutput(const MSTransportable &container, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
T MAX3(T a, T b, T c)
Definition: StdDefs.h:93
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:571
SUMOReal getEdgeAngle(const MSEdge *e, SUMOReal at) const
get angle of the edge at a certain position
The simulated network and simulation perfomer.
Definition: MSNet.h:94
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal getAngle(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the direction in which the container heading to
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
void unregisterOneWaitingForContainer()
decreases the count of vehicles waiting for a container to allow recogniztion of container related de...
const MSEdge * getEdge() const
Returns the current edge.
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:390
virtual void addContainer(MSTransportable *container)=0
Adds a container to this vehicle.
virtual void beginEventOutput(const MSTransportable &container, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A road/street connecting two junctions.
Definition: MSEdge.h:81
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSContainer.cpp:96
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:535
Position getEdgePosition(const MSEdge *e, SUMOReal at, SUMOReal offset) const
get position on edge e at length at with orthogonal offset
void setWaitEnd(SUMOTime time, MSTransportable *container)
sets the arrival time for a waiting container
const MSLane & getLane() const
Returns the lane this stop is located at.
SUMOTime myArrived
the time at which this stage ended
SUMOTime myWaitingSince
The time since which this container is waiting for a ride.
Definition: MSContainer.h:174
the edges of a route
SUMOTime getUntil() const
Returns time until the container waits.
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:65
SUMOReal mySpeed
the speed of the container
Definition: MSContainer.h:402
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
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:704
SUMOReal getSpeed() const
the speed of the container
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
std::string myActType
The type of activity.
Definition: MSContainer.h:274
Position getPosition(SUMOTime now) const
Returns the position of the container.
SUMOReal myArrivalPos
the position at which we want to arrive
void setTranship(MSTransportable *c)
adds a container to myTranship
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOReal getSpeed() const
Returns the speed of the container.
T MIN2(T a, T b)
Definition: StdDefs.h:73
static const SUMOReal ROADSIDE_OFFSET
the offset for computing container positions when standing at an edge
Definition: MSContainer.h:71
Position getPosition(SUMOTime now) const
returns the position of the transportable
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
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:405
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
Position getPosition(SUMOTime now) const
returns the position of the transportable
const MSEdge * getFromEdge() const
Returns the current edge.
std::string getStageDescription() const
returns the stage description as a string
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
Structure representing possible vehicle parameter.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:349
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
Position getPosition(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the network coordinate of the container
bool proceed(MSNet *net, SUMOTime time)
SUMOReal getAngle(SUMOTime now) const
the angle of the vehicle or the angle of the edge + 90deg
void unsetTranship(MSTransportable *c)
removes a container from myTranship
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
MSStoppingPlace * myCurrentContainerStop
the container stop at which the container is waiting
Definition: MSContainer.h:277
MSStoppingPlace * getDepartContainerStop() const
const MSEdge * getFromEdge() const
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:159
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:214
MSStoppingPlace * getDepartContainerStop() const
returns the container stop from which the container departs
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.
SUMOTime myWaitingStart
the time the container started waiting
Definition: MSContainer.h:271
bool isWaiting4Vehicle() const
Whether the container waits for a vehicle.
MSStoppingPlace * getDepartContainerStop() const
returns the container stop from which the container departs
const MSEdge & myDestination
the next edge to reach by getting transported
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
SUMOVehicle * myVehicle
The taken vehicle.
Definition: MSContainer.h:166
virtual void endEventOutput(const MSTransportable &container, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
virtual void erase(MSTransportable *container)
removes a single container
virtual void endEventOutput(const MSTransportable &container, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
static MSCModel_NonInteracting * getModel()
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
SUMOReal getEdgePos(SUMOTime now) const
SUMOReal getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MSVehicle.cpp:663
MSEdge * myCurrentInternalEdge
The current internal edge this container is on or 0.
Definition: MSContainer.h:408