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"
46 #include "MSVehicleControl.h"
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 /* -------------------------------------------------------------------------
53  * MSContainer::MSContainerStage_Driving - methods
54  * ----------------------------------------------------------------------- */
56  MSStoppingPlace* toStop, const double arrivalPos, const std::vector<std::string>& lines) :
57  MSTransportable::Stage_Driving(destination, toStop,
58  SUMOVehicleParameter::interpretEdgePos(
59  arrivalPos, destination.getLength(), SUMO_ATTR_ARRIVALPOS, "container getting transported to " + destination.getID()),
60  lines) {
61 }
62 
63 
65 
66 
67 void
69  if (previous->getDestinationStop() != 0) {
70  // the arrival stop may have an access point
71  myWaitingEdge = &previous->getDestinationStop()->getLane().getEdge();
72  } else {
73  myWaitingEdge = previous->getEdge();
74  }
75  myWaitingPos = previous->getEdgePos(now);
76  myWaitingSince = now;
77  SUMOVehicle* availableVehicle = net->getVehicleControl().getWaitingVehicle(myWaitingEdge, myLines, myWaitingPos, container->getID());
78  if (availableVehicle != 0 && availableVehicle->getParameter().departProcedure == DEPART_CONTAINER_TRIGGERED && !availableVehicle->hasDeparted()) {
79  setVehicle(availableVehicle);
80  myWaitingEdge->removeContainer(container);
81  myVehicle->addContainer(container);
85  } else {
86  net->getContainerControl().addWaiting(myWaitingEdge, container);
87  myWaitingEdge->addContainer(container);
88  }
89 }
90 
91 
92 std::string
94  return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : "transport";
95 }
96 
97 
98 void
100  os.openTag("transport");
101  os.writeAttr("waitingTime", time2string(myDeparted - myWaitingSince));
102  os.writeAttr("vehicle", myVehicleID);
103  os.writeAttr("depart", time2string(myDeparted));
104  os.writeAttr("arrival", time2string(myArrived));
105  os.writeAttr("arrivalPos", toString(myArrivalPos));
106  os.closeTag();
107 }
108 
109 
110 void
114 }
115 
116 
117 
118 /* -------------------------------------------------------------------------
119  * MSContainer::MSContainerStage_Tranship - methods
120  * ----------------------------------------------------------------------- */
122  MSStoppingPlace* toStop,
123  double speed,
124  double departPos, double arrivalPos) :
125  MSTransportable::Stage(*route.back(), toStop, SUMOVehicleParameter::interpretEdgePos(
126  arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS, "container getting transhipped to " + route.back()->getID()), MOVING_WITHOUT_VEHICLE), myRoute(route),
127  mySpeed(speed), myContainerState(0), myCurrentInternalEdge(0) {
129  departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS, "container getting transhipped from " + myRoute.front()->getID());
130 }
131 
133 }
134 
135 void
137  previous->getEdge()->removeContainer(container);
138  myDeparted = now;
139  myRouteStep = myRoute.end() - 1; //define that the container is already on its destination edge
140  myDepartPos = previous->getEdgePos(now);
141  myContainerState = MSCModel_NonInteracting::getModel()->add(container, this, now);
142  (*myRouteStep)->addContainer(container);
143 }
144 
145 const MSEdge*
147  if (myCurrentInternalEdge != 0) {
148  return myCurrentInternalEdge;
149  } else {
150  return *myRouteStep;
151  }
152 }
153 
154 const MSEdge*
156  return myRoute.front();
157 }
158 
159 const MSEdge*
161  return myRoute.back();
162 }
163 
164 double
166  return myContainerState->getEdgePos(*this, now);
167 }
168 
169 Position
171  return myContainerState->getPosition(*this, now);
172 }
173 
174 double
176  return myContainerState->getAngle(*this, now);
177 }
178 
179 SUMOTime
181  return 0;
182 }
183 
184 double
186  return myContainerState->getSpeed(*this);
187 }
188 
189 
192  return myRoute;
193 }
194 
195 
196 void
198  os.openTag("tranship");
199  os.writeAttr("depart", time2string(myDeparted));
200  os.writeAttr("arrival", time2string(myArrived));
201  os.writeAttr("arrivalPos", toString(myArrivalPos));
202  os.closeTag();
203 }
204 
205 
206 void
208  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
210  os.closeTag();
211 }
212 
213 
214 void
216  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "departure")
217  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.front()->getID()).closeTag();
218 }
219 
220 
221 void
223  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival")
224  .writeAttr("agent", c.getID()).writeAttr("link", myRoute.back()->getID()).closeTag();
225 }
226 
227 bool
229  ((MSEdge*)getEdge())->removeContainer(container);
230  if (myRouteStep == myRoute.end() - 1) {
231  if (myDestinationStop != 0) {
232  myDestinationStop->addTransportable(container); //jakob
233  }
234  if (!container->proceed(MSNet::getInstance(), currentTime)) {
236  }
237  return true;
238  } else {
239  if (nextInternal == 0) {
240  ++myRouteStep;
242  } else {
243  myCurrentInternalEdge = nextInternal;
244  }
245  ((MSEdge*) getEdge())->addContainer(container);
246  return false;
247  }
248 }
249 
250 /* -------------------------------------------------------------------------
251  * MSContainer - methods
252  * ----------------------------------------------------------------------- */
254  : MSTransportable(pars, vtype, plan) {
255 }
256 
257 
259 }
260 
261 
262 bool
264  Stage* prior = *myStep;
265  prior->setArrived(time);
266  myStep++;
267  if (myStep != myPlan->end()) {
268  (*myStep)->proceed(net, this, time, prior);
269  return true;
270  } else {
271  prior->getEdge()->removeContainer(this);
272  return false;
273  }
274 }
275 
276 
277 void
279  os.openTag("containerinfo").writeAttr("id", getID()).writeAttr("depart", time2string(getDesiredDepart()));
280  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
281  (*i)->tripInfoOutput(os);
282  }
283  os.closeTag();
284 }
285 
286 
287 void
290  if (myStep == myPlan->end()) {
291  os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
292  }
293  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
294  (*i)->routeOutput(os);
295  }
296  os.closeTag();
297  os.lf();
298 }
299 
300 /****************************************************************************/
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:261
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:68
The departure is container triggered.
virtual void addContainer(MSTransportable *container) const
Add a container to myContainers.
Definition: MSEdge.h:608
const MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSContainer.cpp:99
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.
MSContainer(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:169
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:79
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:613
The simulated network and simulation perfomer.
Definition: MSNet.h:89
The car-following model and parameter.
Definition: MSVehicleType.h:73
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:775
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:81
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
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
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:305
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:93
Structure representing possible vehicle parameter.
virtual const MSEdge * getEdge() const =0
Returns the current edge.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:358
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:55
MSTransportablePlan * myPlan
the plan of the transportable
long long int SUMOTime
Definition: TraCIDefs.h:52
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:237
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:239
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 myArrivalPos
the position at which we want to arrive
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