1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-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    RORoutable.h
11 /// @author  Michael Behrisch
12 /// @date    Oct 2015
13 /// @version $Id$
14 ///
15 // A routable thing such as a vehicle or person
16 /****************************************************************************/
17 #ifndef RORoutable_h
18 #define RORoutable_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <iostream>
28 #include <utils/common/StdDefs.h>
29 #include <utils/common/SUMOTime.h>
30 #include <utils/router/RouterProvider.h>
31 #include <utils/vehicle/SUMOVehicleParameter.h>
32 #include <utils/vehicle/SUMOVTypeParameter.h>
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class OutputDevice;
38 class ROEdge;
39 class ROLane;
40 class RONode;
41 class ROVehicle;
42 
43 typedef std::vector<const ROEdge*> ConstROEdgeVector;
44 typedef IntermodalRouter<ROEdge, ROLane, RONode, ROVehicle> ROIntermodalRouter;
45 typedef RouterProvider<ROEdge, ROLane, RONode, ROVehicle> RORouterProvider;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
51 /**
52  * @class RORoutable
53  * @brief A routable thing such as a vehicle or person
54  */
55 class RORoutable {
56 public:
57     /** @brief Constructor
58      *
59      * @param[in] pars Parameter of this routable
60      * @param[in] type The type of the routable
61      */
RORoutable(const SUMOVehicleParameter & pars,const SUMOVTypeParameter * type)62     RORoutable(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type)
63         : myParameter(pars), myType(type), myRoutingSuccess(false) {}
64 
65 
66     /// @brief Destructor
~RORoutable()67     virtual ~RORoutable() {}
68 
69 
70     /** @brief Returns the definition of the vehicle / person parameter
71     *
72     * @return The vehicle / person's parameter
73     */
getParameter()74     inline const SUMOVehicleParameter& getParameter() const {
75         return myParameter;
76     }
77 
78 
79     /** @brief Returns the type of the routable
80      *
81      * @return The routable's type
82      *
83      * @todo Why not return a reference?
84      */
getType()85     inline const SUMOVTypeParameter* getType() const {
86         return myType;
87     }
88 
89 
90     /** @brief Returns the id of the routable
91      *
92      * @return The id of the routable
93      */
getID()94     inline const std::string& getID() const {
95         return myParameter.id;
96     }
97 
98 
99     /** @brief Returns the time the vehicle starts at, -1 for triggered vehicles
100      *
101      * @return The vehicle's depart time
102      */
getDepart()103     inline SUMOTime getDepart() const {
104         return myParameter.depart;
105     }
106 
107 
getVClass()108     inline SUMOVehicleClass getVClass() const {
109         return getType() != 0 ? getType()->vehicleClass : SVC_IGNORING;
110     }
111 
112 
113     /// @brief Returns the vehicle's maximum speed
getMaxSpeed()114     inline double getMaxSpeed() const {
115         return myType->maxSpeed;
116     }
117 
118 
119     virtual const ROEdge* getDepartEdge() const = 0;
120 
121 
isPublicTransport()122     inline bool isPublicTransport() const {
123         return myParameter.line != "";
124     }
125 
isPartOfFlow()126     inline bool isPartOfFlow() const {
127         return myParameter.repetitionNumber >= 0;
128     }
129 
130     virtual void computeRoute(const RORouterProvider& provider,
131                               const bool removeLoops, MsgHandler* errorHandler) = 0;
132 
133 
134     /** @brief  Saves the routable including the vehicle type (if it was not saved before).
135      *
136      * @param[in] os The routes - output device to store the vehicle's description into
137      * @param[in] altos The route alternatives - output device to store the vehicle's description into
138      * @param[in] typeos The types - output device to store the vehicle types into
139      * @exception IOError If something fails (not yet implemented)
140      */
write(OutputDevice & os,OutputDevice * const altos,OutputDevice * const typeos,OptionsCont & options)141     void write(OutputDevice& os, OutputDevice* const altos,
142                OutputDevice* const typeos, OptionsCont& options) const {
143         if (altos == 0 && typeos == 0) {
144             saveAsXML(os, &os, false, options);
145         } else {
146             saveAsXML(os, typeos, false, options);
147         }
148         if (altos != 0) {
149             saveAsXML(*altos, typeos, true, options);
150         }
151     }
152 
153 
getRoutingSuccess()154     inline bool getRoutingSuccess() const {
155         return myRoutingSuccess;
156     }
157 
158 
159 protected:
160     /** @brief Saves the complete routable description.
161      *
162      * Saves the routable itself including the route and stops.
163      *
164      * @param[in] os The routes or alternatives output device to store the routable's description into
165      * @param[in] typeos The types - output device to store additional types into
166      * @param[in] asAlternatives Whether the route shall be saved as route alternatives
167      * @param[in] options to find out about defaults and whether exit times for the edges shall be written
168      * @exception IOError If something fails (not yet implemented)
169      */
170     virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const = 0;
171 
172 
173 private:
174     /// @brief The vehicle's parameter
175     SUMOVehicleParameter myParameter;
176 
177     /// @brief The type of the vehicle
178     const SUMOVTypeParameter* const myType;
179 
180 protected:
181     /// @brief Whether the last routing was successful
182     bool myRoutingSuccess;
183 
184 
185 private:
186     /// @brief Invalidated copy constructor
187     RORoutable(const RORoutable& src);
188 
189     /// @brief Invalidated assignment operator
190     RORoutable& operator=(const RORoutable& src);
191 
192 };
193 
194 
195 #endif
196 
197 /****************************************************************************/
198