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 "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) {
122  return myVehicle->getPosition();
123  }
125 }
126 
127 SUMOReal
129  if (myVehicle != 0) {
130  MSVehicle* veh = dynamic_cast<MSVehicle*>(myVehicle);
131  if (veh != 0) {
132  return veh->getAngle();
133  } else {
134  return 0;
135  }
136  }
138 }
139 
140 bool
142  return myLines.count(line) > 0;
143 }
144 
145 bool
147  return myVehicle == 0;
148 }
149 
150 SUMOTime
152  return isWaiting4Vehicle() ? now - myWaitingSince : 0;
153 }
154 
155 SUMOReal
157  return myVehicle == 0 ? 0 : myVehicle->getSpeed();
158 }
159 
160 std::string
162  return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : "transport";
163 }
164 
167  return myDepartContainerStop;
168 }
169 
170 void
172  os.openTag("transport").writeAttr("depart", time2string(myDeparted)).writeAttr("arrival", time2string(myArrived)).closeTag();
173 }
174 
175 void
179 }
180 
181 void
183  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival").writeAttr("agent", container.getID()).writeAttr("link", getEdge()->getID()).closeTag();
184 }
185 
186 void
188  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival").writeAttr("agent", container.getID()).writeAttr("link", getEdge()->getID()).closeTag();
189 }
190 
191 
192 
193 /* -------------------------------------------------------------------------
194  * MSContainer::MSContainerStage_Waiting - methods
195  * ----------------------------------------------------------------------- */
197  SUMOTime duration, SUMOTime until, SUMOReal pos, const std::string& actType) :
198  MSTransportable::Stage(destination, 0, SUMOVehicleParameter::interpretEdgePos(
199  pos, destination.getLength(), SUMO_ATTR_DEPARTPOS, "container stopping at " + destination.getID()), WAITING),
200  myWaitingDuration(duration),
201  myWaitingUntil(until),
202  myActType(actType) {
203 }
204 
206 
207 const MSEdge*
209  return &myDestination;
210 }
211 
212 const MSEdge*
214  return &myDestination;
215 }
216 
217 SUMOReal
219  return myArrivalPos;
220 }
221 
222 SUMOTime
224  return myWaitingUntil;
225 }
226 
227 Position
230 }
231 
232 SUMOReal
235 }
236 
237 SUMOTime
239  return now - myWaitingStart;
240 }
241 
242 SUMOReal
244  return 0;
245 }
246 
249  return myCurrentContainerStop;
250 }
251 
252 void
254  previous->getEdge()->addContainer(container);
255  myWaitingStart = now;
256  const SUMOTime until = MAX3(now, now + myWaitingDuration, myWaitingUntil);
257  net->getContainerControl().setWaitEnd(until, container);
258 }
259 
260 void
262  os.openTag("stop").writeAttr("arrival", time2string(myArrived)).closeTag();
263 }
264 
265 void
268  if (myWaitingDuration >= 0) {
270  }
271  if (myWaitingUntil >= 0) {
273  }
274  os.closeTag();
275 }
276 
277 void
279  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "actstart " + myActType)
280  .writeAttr("agent", container.getID()).writeAttr("link", getEdge()->getID()).closeTag();
281 }
282 
283 void
285  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "actend " + myActType).writeAttr("agent", container.getID())
286  .writeAttr("link", getEdge()->getID()).closeTag();
287 }
288 
289 /* -------------------------------------------------------------------------
290  * MSContainer::MSContainerStage_Tranship - methods
291  * ----------------------------------------------------------------------- */
293  MSStoppingPlace* toStop,
294  SUMOReal speed,
295  SUMOReal departPos, SUMOReal arrivalPos) :
296  MSTransportable::Stage(*route.back(), toStop, SUMOVehicleParameter::interpretEdgePos(
297  arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS, "container getting transhipped to " + route.back()->getID()), MOVING_WITHOUT_VEHICLE), myRoute(route),
298  mySpeed(speed), myContainerState(0), myCurrentInternalEdge(0) {
300  departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS, "container getting transhipped from " + myRoute.front()->getID());
301 }
302 
304 }
305 
306 void
308  previous->getEdge()->removeContainer(container);
309  myRouteStep = myRoute.end() - 1; //define that the container is already on its destination edge
311  myDepartPos = previous->getEdgePos(now);
312  myContainerState = MSCModel_NonInteracting::getModel()->add(container, this, now);
313  (*myRouteStep)->addContainer(container);
314 }
315 
316 const MSEdge*
318  if (myCurrentInternalEdge != 0) {
319  return myCurrentInternalEdge;
320  } else {
321  return *myRouteStep;
322  }
323 }
324 
325 const MSEdge*
327  return myRoute.front();
328 }
329 
330 const MSEdge*
332  return myRoute.back();
333 }
334 
335 SUMOReal
337  return myContainerState->getEdgePos(*this, now);
338 }
339 
340 Position
342  return myContainerState->getPosition(*this, now);
343 }
344 
345 SUMOReal
347  return myContainerState->getAngle(*this, now);
348 }
349 
350 SUMOTime
352  return 0;
353 }
354 
355 SUMOReal
357  return myContainerState->getSpeed(*this);
358 }
359 
362  return myDepartContainerStop;
363 }
364 
365 void
367  os.openTag("tranship").writeAttr("arrival", time2string(myArrived)).closeTag();
368 }
369 
370 
371 void
373  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
375  os.closeTag();
376 }
377 
378 
379 void
381  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "departure")
382  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.front()->getID()).closeTag();
383 }
384 
385 
386 void
388  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival")
389  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag();
390 }
391 
392 bool
394  ((MSEdge*)getEdge())->removeContainer(container);
395  if (myRouteStep == myRoute.end() - 1) {
397  if (myDestinationStop != 0) {
398  myDestinationStop->addTransportable(container); //jakob
399  }
400  if (!container->proceed(MSNet::getInstance(), currentTime)) {
402  }
403  return true;
404  } else {
405  if (nextInternal == 0) {
406  ++myRouteStep;
408  } else {
409  myCurrentInternalEdge = nextInternal;
410  }
411  ((MSEdge*) getEdge())->addContainer(container);
412  return false;
413  }
414 }
415 
416 /* -------------------------------------------------------------------------
417  * MSContainer - methods
418  * ----------------------------------------------------------------------- */
420  : MSTransportable(pars, vtype, plan) {
421 }
422 
424 }
425 
426 bool
428  Stage* prior = *myStep;
429  prior->setArrived(time);
430  myStep++;
431  if (myStep != myPlan->end()) {
432  (*myStep)->proceed(net, this, time, prior);
433  return true;
434  } else {
435  prior->getEdge()->removeContainer(this);
436  return false;
437  }
438 }
439 
440 
441 void
443  MSTransportablePlan::const_iterator i = myPlan->begin();
444  if ((*i)->getStageType() == WAITING && getDesiredDepart() == static_cast<MSContainerStage_Waiting*>(*i)->getUntil()) {
445  ++i;
446  }
447  for (; i != myPlan->end(); ++i) {
448  (*i)->routeOutput(os);
449  }
450 }
451 
452 
453 /****************************************************************************/
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:467
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
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:597
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:59
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:160
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:89
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:602
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:80
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:562
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:698
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:69
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
virtual Position getPosition(const SUMOReal offset=0) const =0
Return current position (x/y, cartesian)
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:160
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:213
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.h:452
MSEdge * myCurrentInternalEdge
The current internal edge this container is on or 0.
Definition: MSContainer.h:408