Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file SUMOTrafficObject.h
15 : /// @author Jakob Erdmann
16 : /// @date Mon, 25 Mar 2019
17 : ///
18 : // Abstract base class for vehicle, person, and container representations
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <string>
24 : #include <vector>
25 : #include <typeinfo>
26 : #include <memory>
27 : #include <utils/common/SUMOTime.h>
28 : #include <utils/common/Named.h>
29 : #include <utils/common/SUMOVehicleClass.h>
30 :
31 :
32 : // ===========================================================================
33 : // class declarations
34 : // ===========================================================================
35 : class MSVehicleType;
36 : class SUMOVehicleParameter;
37 : class SUMOVTypeParameter;
38 : class MSEdge;
39 : class MSLane;
40 : class Position;
41 : class MSDevice;
42 : class MSRoute;
43 :
44 : typedef std::shared_ptr<const MSRoute> ConstMSRoutePtr;
45 :
46 :
47 : // ===========================================================================
48 : // class definitions
49 : // ===========================================================================
50 : /**
51 : * @class SUMOTrafficObject
52 : * @brief Representation of a vehicle, person, or container
53 : */
54 : class SUMOTrafficObject : public Named {
55 : public:
56 : typedef long long int NumericalID;
57 :
58 : /// @brief Constructor
59 : SUMOTrafficObject(const std::string& id) : Named(id) {}
60 :
61 : /// @brief Destructor
62 0 : virtual ~SUMOTrafficObject() {}
63 :
64 : /** @brief Whether it is a vehicle
65 : * @return true for vehicles, false otherwise
66 : */
67 1678112 : virtual bool isVehicle() const {
68 1678112 : return false;
69 : }
70 :
71 : /** @brief Whether it is a person
72 : * @return true for persons, false otherwise
73 : */
74 9535924 : virtual bool isPerson() const {
75 9535924 : return false;
76 : }
77 :
78 : /** @brief Whether it is a container
79 : * @return true for containers, false otherwise
80 : */
81 0 : virtual bool isContainer() const {
82 0 : return false;
83 : }
84 :
85 : /// @brief return the numerical ID which is only for internal usage
86 : // (especially fast comparison in maps which need vehicles as keys)
87 : virtual NumericalID getNumericalID() const = 0;
88 :
89 :
90 : /** @brief Returns the object's "vehicle" type
91 : * @return The vehicle's type
92 : */
93 : virtual const MSVehicleType& getVehicleType() const = 0;
94 :
95 : /** @brief Returns the object's "vehicle" type parameter
96 : * @return The type parameter
97 : */
98 : virtual const SUMOVTypeParameter& getVTypeParameter() const = 0;
99 :
100 : /** @brief Replaces the current vehicle type by the one given
101 : *
102 : * If the currently used vehicle type is marked as being used by this object
103 : * only, it is deleted, first. The new, given type is then assigned to
104 : * "myVType".
105 : * @param[in] type The new vehicle type
106 : * @see MSTransportable::myVType
107 : */
108 : virtual void replaceVehicleType(MSVehicleType* type) = 0;
109 :
110 :
111 : /** @brief Returns the vehicle's parameter (including departure definition)
112 : *
113 : * @return The vehicle's parameter
114 : */
115 : virtual const SUMOVehicleParameter& getParameter() const = 0;
116 :
117 : /** @brief Returns the associated RNG for this object
118 : * @return The vehicle's associated RNG
119 : */
120 : virtual SumoRNG* getRNG() const = 0;
121 :
122 : /// @brief @return The index of the associated RNG
123 : virtual int getRNGIndex() const = 0;
124 :
125 : /** @brief Returns whether the object is at a stop
126 : * @return Whether it has stopped
127 : */
128 : virtual bool isStopped() const = 0;
129 :
130 : /** @brief Returns the edge the object is currently at
131 : *
132 : * @return The current edge in the object's route
133 : */
134 : virtual const MSEdge* getEdge() const = 0;
135 :
136 : /// @brief returns the next edge (possibly an internal edge)
137 : virtual const MSEdge* getNextEdgePtr() const = 0;
138 :
139 : /// @brief returns the numerical IDs of edges to be used (possibly of future stages)
140 : virtual const std::set<NumericalID> getUpcomingEdgeIDs() const = 0;
141 :
142 : /** @brief Returns the lane the object is currently at
143 : *
144 : * @return The current lane or nullptr if the object is not on a lane
145 : */
146 : virtual const MSLane* getLane() const = 0;
147 :
148 : /** @brief Returns the lane the where the rear of the object is currently at
149 : *
150 : * @return The current back lane or nullptr if the object is not on a lane
151 : */
152 : virtual const MSLane* getBackLane() const = 0;
153 :
154 :
155 : /// @brief return index of edge within route
156 : virtual int getRoutePosition() const = 0;
157 :
158 : /** @brief Returns the end point for reroutes (usually the last edge of the route)
159 : *
160 : * @return The rerouting end point
161 : */
162 : virtual const MSEdge* getRerouteDestination() const = 0;
163 :
164 : /// Replaces the current route by the given one
165 : virtual bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true, std::string* msgReturn = nullptr) = 0;
166 :
167 : /** @brief Returns the slope of the road at object's position in degrees
168 : * @return The slope
169 : */
170 : virtual double getSlope() const = 0;
171 :
172 : virtual double getChosenSpeedFactor() const = 0;
173 :
174 : /** @brief Returns the object's access class
175 : * @return The object's access class
176 : */
177 : virtual SUMOVehicleClass getVClass() const = 0;
178 :
179 : /** @brief Returns whether this object is ignoring transient permission
180 : * changes (during routing)
181 : */
182 0 : virtual bool ignoreTransientPermissions() const {
183 0 : return false;
184 : };
185 :
186 : virtual int getRoutingMode() const = 0;
187 :
188 : /** @brief Returns the object's maximum speed (minimum of technical and desired maximum speed)
189 : * @return The object's maximum speed
190 : */
191 : virtual double getMaxSpeed() const = 0;
192 :
193 : virtual SUMOTime getWaitingTime(const bool accumulated = false) const = 0;
194 :
195 : /** @brief Returns the object's current speed
196 : * @return The object's speed
197 : */
198 : virtual double getSpeed() const = 0;
199 :
200 : // This definition was introduced to make the MSVehicle's previousSpeed Refs. #2579
201 : /** @brief Returns the object's previous speed
202 : * @return The object's previous speed
203 : */
204 : virtual double getPreviousSpeed() const = 0;
205 :
206 :
207 : /** @brief Returns the object's acceleration
208 : * @return The acceleration
209 : */
210 : virtual double getAcceleration() const = 0;
211 :
212 : /** @brief Get the object's position along the lane
213 : * @return The position of the object (in m from the lane's begin)
214 : */
215 : virtual double getPositionOnLane() const = 0;
216 :
217 : /** @brief Get the object's back position along the given lane
218 : * @return The position of the object (in m from the given lane's begin)
219 : */
220 : virtual double getBackPositionOnLane(const MSLane* lane) const = 0;
221 :
222 :
223 : /** @brief Return current position (x/y, cartesian)
224 : *
225 : * If the object is not in the net, Position::INVALID.
226 : * @param[in] offset optional offset in longitudinal direction
227 : * @return The current position (in cartesian coordinates)
228 : * @see myLane
229 : */
230 : virtual Position getPosition(const double offset = 0) const = 0;
231 :
232 : /** @brief Returns the object's angle in degrees
233 : */
234 : virtual double getAngle() const = 0;
235 :
236 : /** @brief Returns whether this object has arrived
237 : */
238 : virtual bool hasArrived() const = 0;
239 :
240 : /// @brief whether the vehicle is individually influenced (via TraCI or special parameters)
241 : virtual bool hasInfluencer() const = 0;
242 :
243 : /// @brief whether this object is selected in the GUI
244 : virtual bool isSelected() const = 0;
245 :
246 : /// @brief Returns a device of the given type if it exists or nullptr if not
247 : virtual MSDevice* getDevice(const std::type_info& type) const = 0;
248 :
249 : /// @name Helper methods for parsing parameters from the object itself, it's type or the global OptionsCont
250 : /// @{
251 : /** @brief Retrieve a string parameter for the traffic object.
252 : * @param paramName the parameter name
253 : * @param required whether it is an error if the parameter is not set
254 : * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
255 : * @return the string value
256 : */
257 : std::string getStringParam(const std::string& paramName, const bool required = false, const std::string& deflt = "") const;
258 :
259 : /** @brief Retrieve a floating point parameter for the traffic object.
260 : * @param paramName the parameter name
261 : * @param required whether it is an error if the parameter is not set
262 : * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
263 : * @return the float value
264 : */
265 : double getFloatParam(const std::string& paramName, const bool required = false, const double deflt = INVALID_DOUBLE) const;
266 :
267 : /** @brief Retrieve a boolean parameter for the traffic object.
268 : * @param paramName the parameter name
269 : * @param required whether it is an error if the parameter is not set
270 : * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
271 : * @return the bool value
272 : */
273 : bool getBoolParam(const std::string& paramName, const bool required = false, const bool deflt = false) const;
274 :
275 : /** @brief Retrieve a time parameter for the traffic object.
276 : * @param paramName the parameter name
277 : * @param required whether it is an error if the parameter is not set
278 : * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
279 : * @return the time value
280 : */
281 : SUMOTime getTimeParam(const std::string& paramName, const bool required = false, const SUMOTime deflt = SUMOTime_MIN) const;
282 : /// @}
283 : };
|