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 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 /* -------------------------------------------------------------------------
52  * MSContainer::MSContainerStage_Driving - methods
53  * ----------------------------------------------------------------------- */
55  MSStoppingPlace* toStop, const double arrivalPos, const std::vector<std::string>& lines)
56  : MSTransportable::Stage_Driving(destination, toStop, arrivalPos, lines) {}
57 
58 
60 
61 
62 void
64  if (previous->getDestinationStop() != 0) {
65  // the arrival stop may have an access point
66  myWaitingEdge = &previous->getDestinationStop()->getLane().getEdge();
67  } else {
68  myWaitingEdge = previous->getEdge();
69  }
70  myWaitingPos = previous->getEdgePos(now);
71  myWaitingSince = now;
72  SUMOVehicle* availableVehicle = net->getVehicleControl().getWaitingVehicle(myWaitingEdge, myLines, myWaitingPos, container->getID());
73  if (availableVehicle != 0 && availableVehicle->getParameter().departProcedure == DEPART_CONTAINER_TRIGGERED && !availableVehicle->hasDeparted()) {
74  myVehicle = availableVehicle;
75  myWaitingEdge->removeContainer(container);
76  myVehicle->addContainer(container);
80  } else {
81  net->getContainerControl().addWaiting(myWaitingEdge, container);
82  myWaitingEdge->addContainer(container);
83  }
84 }
85 
86 
87 std::string
89  return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : "transport";
90 }
91 
92 
93 void
95  os.openTag("transport").writeAttr("depart", time2string(myDeparted)).writeAttr("arrival", time2string(myArrived)).closeTag();
96 }
97 
98 
99 void
103 }
104 
105 
106 
107 /* -------------------------------------------------------------------------
108  * MSContainer::MSContainerStage_Tranship - methods
109  * ----------------------------------------------------------------------- */
111  MSStoppingPlace* toStop,
112  double speed,
113  double departPos, double arrivalPos) :
114  MSTransportable::Stage(*route.back(), toStop, SUMOVehicleParameter::interpretEdgePos(
115  arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS, "container getting transhipped to " + route.back()->getID()), MOVING_WITHOUT_VEHICLE), myRoute(route),
116  mySpeed(speed), myContainerState(0), myCurrentInternalEdge(0) {
118  departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS, "container getting transhipped from " + myRoute.front()->getID());
119 }
120 
122 }
123 
124 void
126  previous->getEdge()->removeContainer(container);
127  myRouteStep = myRoute.end() - 1; //define that the container is already on its destination edge
128  myDepartPos = previous->getEdgePos(now);
129  myContainerState = MSCModel_NonInteracting::getModel()->add(container, this, now);
130  (*myRouteStep)->addContainer(container);
131 }
132 
133 const MSEdge*
135  if (myCurrentInternalEdge != 0) {
136  return myCurrentInternalEdge;
137  } else {
138  return *myRouteStep;
139  }
140 }
141 
142 const MSEdge*
144  return myRoute.front();
145 }
146 
147 const MSEdge*
149  return myRoute.back();
150 }
151 
152 double
154  return myContainerState->getEdgePos(*this, now);
155 }
156 
157 Position
159  return myContainerState->getPosition(*this, now);
160 }
161 
162 double
164  return myContainerState->getAngle(*this, now);
165 }
166 
167 SUMOTime
169  return 0;
170 }
171 
172 double
174  return myContainerState->getSpeed(*this);
175 }
176 
177 
180  return myRoute;
181 }
182 
183 
184 void
186  os.openTag("tranship").writeAttr("arrival", time2string(myArrived)).closeTag();
187 }
188 
189 
190 void
192  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
194  os.closeTag();
195 }
196 
197 
198 void
200  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "departure")
201  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.front()->getID()).closeTag();
202 }
203 
204 
205 void
207  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival")
208  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag();
209 }
210 
211 bool
213  ((MSEdge*)getEdge())->removeContainer(container);
214  if (myRouteStep == myRoute.end() - 1) {
215  if (myDestinationStop != 0) {
216  myDestinationStop->addTransportable(container); //jakob
217  }
218  if (!container->proceed(MSNet::getInstance(), currentTime)) {
220  }
221  return true;
222  } else {
223  if (nextInternal == 0) {
224  ++myRouteStep;
226  } else {
227  myCurrentInternalEdge = nextInternal;
228  }
229  ((MSEdge*) getEdge())->addContainer(container);
230  return false;
231  }
232 }
233 
234 /* -------------------------------------------------------------------------
235  * MSContainer - methods
236  * ----------------------------------------------------------------------- */
238  : MSTransportable(pars, vtype, plan) {
239 }
240 
241 
243 }
244 
245 
246 bool
248  Stage* prior = *myStep;
249  prior->setArrived(time);
250  myStep++;
251  if (myStep != myPlan->end()) {
252  (*myStep)->proceed(net, this, time, prior);
253  return true;
254  } else {
255  prior->getEdge()->removeContainer(this);
256  return false;
257  }
258 }
259 
260 
261 void
263  os.openTag("containerinfo").writeAttr("id", getID()).writeAttr("depart", time2string(getDesiredDepart()));
264  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
265  (*i)->tripInfoOutput(os);
266  }
267  os.closeTag();
268 }
269 
270 
271 void
274  if (myStep == myPlan->end()) {
275  os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
276  }
277  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
278  (*i)->routeOutput(os);
279  }
280  os.closeTag();
281  os.lf();
282 }
283 
284 /****************************************************************************/
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 ...
double getSpeed() const
Returns the speed of the container.
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:582
virtual void beginEventOutput(const MSTransportable &c, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
A lane area vehicles can halt at.
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSContainer.h:211
virtual void proceed(MSNet *net, MSTransportable *container, SUMOTime now, Stage *previous)
proceeds to the next step
Definition: MSContainer.cpp:63
The departure is container triggered.
virtual void addContainer(MSTransportable *container) const
Add a container to myContainers.
Definition: MSEdge.h:624
const MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSContainer.cpp:94
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.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
const std::set< std::string > myLines
the lines to choose from
const std::string & getID() const
returns the id of the transportable
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
double myDepartPos
the depart position
Definition: MSContainer.h:214
MSTransportablePlan::iterator myStep
the iterator over the route
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:629
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
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:738
void unregisterOneWaitingForContainer()
decreases the count of vehicles waiting for a container to allow recogniztion of container related de...
double getEdgePos(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the offset from the start of the current edge measured in its natural direction ...
const MSEdge & getDestination() const
returns the destination edge
std::vector< const MSEdge * > myRoute
The route of the container.
Definition: MSContainer.h:208
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
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
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:310
double getEdgePos(SUMOTime now) const
Returns the offset from the start of the current edge measured in its natural direction.
Position getPosition(SUMOTime now) const
Returns the position of the container.
double mySpeed
the speed of the container
Definition: MSContainer.h:217
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOVehicle * getWaitingVehicle(const MSEdge *const edge, const std::set< std::string > &lines, const double position, const std::string ridingID)
double getAngle(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the direction in which the container heading to
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:88
Structure representing possible vehicle parameter.
virtual const MSEdge * getEdge() const =0
Returns the current edge.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:363
Position getPosition(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the network coordinate of the container
virtual bool proceed(MSNet *net, SUMOTime time)
MSContainerStage_Tranship(const std::vector< const MSEdge * > &route, MSStoppingPlace *toStop, double speed, double departPos, double arrivalPos)
constructor
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.
MSContainerStage_Driving(const MSEdge &destination, MSStoppingPlace *toStop, const double arrivalPos, const std::vector< std::string > &lines)
constructor
Definition: MSContainer.cpp:54
MSTransportablePlan * myPlan
the plan of the transportable
long long int SUMOTime
Definition: TraCIDefs.h:52
MSContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
const MSEdge * getToEdge() const
Returns last edge of the containers route.
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
double getAngle(SUMOTime now) const
Returns the angle of the container.
static MSCModel_NonInteracting * getModel()
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:228
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.
virtual double getEdgePos(SUMOTime now) const =0
ConstMSEdgeVector getEdges() const
the edges of the current stage
double getSpeed(const MSContainer::MSContainerStage_Tranship &stage) const
return the current speed of the container
MSEdge * myCurrentInternalEdge
The current internal edge this container is on or 0.
Definition: MSContainer.h:223