1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MSContainer.h
11 /// @author  Melanie Weber
12 /// @author  Andreas Kendziorra
13 /// @date    Thu, 12 Jun 2014
14 /// @version $Id$
15 ///
16 // The class for modelling container-movements
17 /****************************************************************************/
18 #ifndef MSContainer_h
19 #define MSContainer_h
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <vector>
28 #include <set>
29 #include <utils/common/SUMOTime.h>
30 #include <utils/common/Command.h>
31 #include <utils/geom/Position.h>
32 #include <utils/geom/PositionVector.h>
33 #include <microsim/MSTransportable.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSNet;
40 class MSEdge;
41 class MSLane;
42 class OutputDevice;
43 class SUMOVehicleParameter;
44 class MSStoppingPlace;
45 class SUMOVehicle;
46 class MSVehicleType;
47 class MSCModel_NonInteracting;
48 class CState;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
54 /**
55   * @class MSContainer
56   *
57   * The class holds a simulated container together with its movement stages
58   */
59 
60 
61 class MSContainer : public MSTransportable {
62 public:
63 
64 
65     /**
66      * A "real" stage performing the travelling by a transport system
67      * A container is in this stage if it is on a ride or if its waiting for a ride.
68      * The given route will be chosen. The travel time is computed by the simulation
69      */
70     class MSContainerStage_Driving : public MSTransportable::Stage_Driving {
71     public:
72         /// constructor
73         MSContainerStage_Driving(const MSEdge* destination, MSStoppingPlace* toStop,
74                                  const double arrivalPos, const std::vector<std::string>& lines);
75 
76         /// destructor
77         ~MSContainerStage_Driving();
78 
79         Stage* clone() const;
80 
81         /// proceeds to the next step
82         virtual void proceed(MSNet* net, MSTransportable* container, SUMOTime now, Stage* previous);
83 
84         /// @brief returns the stage description as a string
85         std::string getStageDescription() const;
86         std::string getStageSummary() const;
87 
88         /** @brief Called on writing tripinfo output
89          *
90          * @param[in] os The stream to write the information into
91          * @exception IOError not yet implemented
92          */
93         virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
94 
95         /** @brief Called on writing vehroute output
96          *
97          * @param[in] os The stream to write the information into
98          * @exception IOError not yet implemented
99          */
100         virtual void routeOutput(OutputDevice& os, const bool withRouteLength) const;
101     };
102 
103     /**
104     * A "real" stage performing the tranship of a container
105     * A container is in this stage if it gets transhipred between two stops that are
106     * assumed to be connected.
107     */
108     class MSContainerStage_Tranship : public MSTransportable::Stage {
109         friend class MSCModel_NonInteracting;
110 
111     public:
112         /// constructor
113         MSContainerStage_Tranship(const std::vector<const MSEdge*>& route, MSStoppingPlace* toStop, double speed, double departPos, double arrivalPos);
114 
115         /// destructor
116         ~MSContainerStage_Tranship();
117 
118         Stage* clone() const;
119 
120         /// proceeds to the next step
121         virtual void proceed(MSNet* net, MSTransportable* container, SUMOTime now, Stage* previous);
122 
123         /// Returns the current edge
124         const MSEdge* getEdge() const;
125 
126         /// Returns first edge of the containers route
127         const MSEdge* getFromEdge() const;
128 
129         /// Returns last edge of the containers route
130         const MSEdge* getToEdge() const;
131 
132         /// Returns the offset from the start of the current edge measured in its natural direction
133         double getEdgePos(SUMOTime now) const;
134 
135         /// Returns the position of the container
136         Position getPosition(SUMOTime now) const;
137 
138         /// Returns the angle of the container
139         double getAngle(SUMOTime now) const;
140 
141         /// Returns the time the container spent waiting
142         SUMOTime getWaitingTime(SUMOTime now) const;
143 
144         /// Returns the speed of the container
145         double getSpeed() const;
146 
147         /// @brief the edges of the current stage
148         ConstMSEdgeVector getEdges() const;
149 
150         /// Returns the current stage description as a string
getStageDescription()151         std::string getStageDescription() const {
152             return "tranship";
153         }
154         std::string getStageSummary() const;
155 
156         /** @brief Called on writing tripinfo output
157          * @param[in] os The stream to write the information into
158          * @exception IOError not yet implemented
159          */
160         virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
161 
162         /** @brief Called on writing vehroute output
163          * @param[in] os The stream to write the information into
164          * @exception IOError not yet implemented
165          */
166         virtual void routeOutput(OutputDevice& os, const bool withRouteLength) const;
167 
168         /** @brief Called for writing the events output
169          * @param[in] os The stream to write the information into
170          * @exception IOError not yet implemented
171          */
172         virtual void beginEventOutput(const MSTransportable& c, SUMOTime t, OutputDevice& os) const;
173 
174         /** @brief Called for writing the events output (end of an action)
175          * @param[in] os The stream to write the information into
176          * @exception IOError not yet implemented
177          */
178         virtual void endEventOutput(const MSTransportable& c, SUMOTime t, OutputDevice& os) const;
179 
180         /// @brief move forward and return whether the container arrived
181         bool moveToNextEdge(MSTransportable* container, SUMOTime currentTime, MSEdge* nextInternal = 0);
182 
183 
184         /// @brief accessors to be used by MSCModel_NonInteracting
getMaxSpeed()185         inline double getMaxSpeed() const {
186             return mySpeed;
187         }
188 
getDepartPos()189         inline double getDepartPos() const {
190             return myDepartPos;
191         }
192 
getArrivalPos()193         inline double getArrivalPos() const {
194             return myArrivalPos;
195         }
196 
getNextRouteEdge()197         inline const MSEdge* getNextRouteEdge() const {
198             return myRouteStep == myRoute.end() - 1 ? 0 : *(myRouteStep + 1);
199         }
200 
getContainerState()201         CState* getContainerState() const {
202             return myContainerState;
203         }
204 
205     private:
206         /// @brief The route of the container
207         std::vector<const MSEdge*> myRoute;
208 
209         /// @brief current step
210         std::vector<const MSEdge*>::iterator myRouteStep;
211 
212         /// @brief the depart position
213         double myDepartPos;
214 
215         /// @brief the speed of the container
216         double mySpeed;
217 
218         /// @brief state that is to be manipulated by MSCModel
219         CState* myContainerState;
220 
221         /// @brief The current internal edge this container is on or 0
222         MSEdge* myCurrentInternalEdge;
223 
224     private:
225         /// @brief Invalidated copy constructor.
226         MSContainerStage_Tranship(const MSContainerStage_Tranship&);
227 
228         /// @brief Invalidated assignment operator.
229         MSContainerStage_Tranship& operator=(const MSContainerStage_Tranship&);
230 
231     };
232 
233 public:
234     /// constructor
235     MSContainer(const SUMOVehicleParameter* pars, MSVehicleType* vtype,  MSTransportablePlan* plan);
236 
237     /// destructor
238     virtual ~MSContainer();
239 
240     /* @brief proceeds to the next step of the route,
241      * @return Whether the persons plan continues  */
242     virtual bool proceed(MSNet* net, SUMOTime time);
243 
244     /** @brief Called on writing tripinfo output
245     *
246     * @param[in] os The stream to write the information into
247     * @exception IOError not yet implemented
248     */
249     virtual void tripInfoOutput(OutputDevice& os) const;
250 
251     /** @brief Called on writing vehroute output
252     *
253     * @param[in] os The stream to write the information into
254     * @param[in] withRouteLength whether route length shall be written
255     * @exception IOError not yet implemented
256     */
257     virtual void routeOutput(OutputDevice& os, const bool withRouteLength) const;
258 
259 private:
260     /// @brief Invalidated copy constructor.
261     MSContainer(const MSContainer&);
262 
263     /// @brief Invalidated assignment operator.
264     MSContainer& operator=(const MSContainer&);
265 
266 };
267 
268 
269 #endif
270 
271 /****************************************************************************/
272