Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2002-2026 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 RORoutable.h
15 : /// @author Michael Behrisch
16 : /// @date Oct 2015
17 : ///
18 : // A routable thing such as a vehicle or person
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <string>
24 : #include <iostream>
25 : #include <utils/common/StdDefs.h>
26 : #include <utils/common/SUMOTime.h>
27 : #include <utils/common/RandHelper.h>
28 : #include <utils/router/RouterProvider.h>
29 : #include <utils/vehicle/SUMOVehicleParameter.h>
30 : #include <utils/vehicle/SUMOVTypeParameter.h>
31 :
32 : // ===========================================================================
33 : // class declarations
34 : // ===========================================================================
35 : class OutputDevice;
36 : class ROEdge;
37 : class ROLane;
38 : class RONode;
39 : class ROVehicle;
40 :
41 : typedef std::vector<const ROEdge*> ConstROEdgeVector;
42 : typedef IntermodalRouter<ROEdge, ROLane, RONode, ROVehicle> ROIntermodalRouter;
43 : typedef RouterProvider<ROEdge, ROLane, RONode, ROVehicle> RORouterProvider;
44 :
45 :
46 : // ===========================================================================
47 : // class definitions
48 : // ===========================================================================
49 : /**
50 : * @class RORoutable
51 : * @brief A routable thing such as a vehicle or person
52 : */
53 : class RORoutable {
54 : public:
55 : /** @brief Constructor
56 : *
57 : * @param[in] pars Parameter of this routable
58 : * @param[in] type The type of the routable
59 : */
60 301309 : RORoutable(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type) :
61 301309 : myParameter(pars),
62 301309 : myType(type),
63 301309 : myRandomSeed(RandHelper::murmur3_32(pars.id, RandHelper::getSeed())),
64 602618 : myRoutingSuccess(false) {}
65 :
66 :
67 : /// @brief Destructor
68 301309 : virtual ~RORoutable() {}
69 :
70 :
71 : /** @brief Returns the definition of the vehicle / person parameter
72 : *
73 : * @return The vehicle / person's parameter
74 : */
75 : inline const SUMOVehicleParameter& getParameter() const {
76 395242 : return myParameter;
77 : }
78 :
79 : inline SUMOVehicleParameter& getParameterMutable() {
80 : return myParameter;
81 : }
82 :
83 : /** @brief Returns the type of the routable
84 : *
85 : * @return The routable's type
86 : *
87 : * @todo Why not return a reference?
88 : */
89 : inline const SUMOVTypeParameter* getType() const {
90 15523351 : return myType;
91 : }
92 :
93 :
94 : /** @brief Returns the id of the routable
95 : *
96 : * @return The id of the routable
97 : */
98 : inline const std::string& getID() const {
99 582946 : return myParameter.id;
100 : }
101 :
102 : /// @brief return vehicle-specific random number
103 : long long int getRandomSeed() const {
104 6984 : return myRandomSeed;
105 : }
106 :
107 : /** @brief Returns an upper bound for the speed factor of this vehicle
108 : * @return the maximum speed factor
109 : */
110 : inline double getChosenSpeedFactor() const {
111 13267883 : return getParameter().wasSet(VEHPARS_SPEEDFACTOR_SET) ? getParameter().speedFactor : getType()->speedFactor.getParameter(0);
112 : }
113 :
114 : /** @brief Returns the time the vehicle starts at, -1 for triggered vehicles
115 : *
116 : * @return The vehicle's depart time
117 : */
118 : inline SUMOTime getDepart() const {
119 300344 : return myParameter.depart;
120 : }
121 :
122 : /// @brief update depart time (for triggered persons)
123 : inline void setDepart(SUMOTime t) {
124 : myParameter.depart = t;
125 : }
126 :
127 : inline SUMOVehicleClass getVClass() const {
128 20027738 : return getType() != 0 ? getType()->vehicleClass : SVC_IGNORING;
129 : }
130 :
131 : /** @brief Returns whether this object is ignoring transient permission
132 : * changes (during routing)
133 : */
134 : bool ignoreTransientPermissions() const {
135 : return false;
136 : };
137 :
138 : /// @brief Returns the vehicle's maximum speed
139 : inline double getMaxSpeed() const {
140 13262110 : return MIN2(getType()->maxSpeed,
141 13266671 : getType()->desiredMaxSpeed * getChosenSpeedFactor());
142 : }
143 :
144 : virtual const ROEdge* getDepartEdge() const = 0;
145 :
146 :
147 : inline bool isPublicTransport() const {
148 597166 : return myParameter.line != "";
149 : }
150 :
151 : inline bool isPartOfFlow() const {
152 297774 : return myParameter.repetitionNumber >= 0;
153 : }
154 :
155 : virtual void computeRoute(const RORouterProvider& provider,
156 : const bool removeLoops, MsgHandler* errorHandler) = 0;
157 :
158 :
159 : /** @brief Saves the routable including the vehicle type (if it was not saved before).
160 : *
161 : * @param[in] os The routes - output device to store the vehicle's description into
162 : * @param[in] altos The route alternatives - output device to store the vehicle's description into
163 : * @param[in] typeos The types - output device to store the vehicle types into
164 : * @exception IOError If something fails (not yet implemented)
165 : */
166 280915 : void write(OutputDevice* os, OutputDevice* const altos,
167 : OutputDevice* const typeos, OptionsCont& options, int quota) const {
168 561886 : for (int i = 0; i < quota; i++) {
169 280971 : if (os != nullptr) {
170 280969 : if (altos == nullptr && typeos == nullptr) {
171 159362 : saveAsXML(*os, os, false, options, i);
172 : } else {
173 121607 : saveAsXML(*os, typeos, false, options, i);
174 : }
175 : }
176 280971 : if (altos != nullptr) {
177 114033 : saveAsXML(*altos, typeos, true, options, i);
178 : }
179 : }
180 280915 : }
181 :
182 :
183 : inline bool getRoutingSuccess() const {
184 300131 : return myRoutingSuccess;
185 : }
186 :
187 :
188 : protected:
189 : /** @brief Saves the complete routable description.
190 : *
191 : * Saves the routable itself including the route and stops.
192 : *
193 : * @param[in] os The routes or alternatives output device to store the routable's description into
194 : * @param[in] typeos The types - output device to store additional types into
195 : * @param[in] asAlternatives Whether the route shall be saved as route alternatives
196 : * @param[in] options to find out about defaults and whether exit times for the edges shall be written
197 : * @exception IOError If something fails (not yet implemented)
198 : */
199 : virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex = 0) const = 0;
200 :
201 :
202 : private:
203 : /// @brief The vehicle's parameter
204 : SUMOVehicleParameter myParameter;
205 :
206 : /// @brief The type of the vehicle
207 : const SUMOVTypeParameter* const myType;
208 :
209 : /// @brief object-specific random constant
210 : const long long int myRandomSeed;
211 :
212 : protected:
213 : /// @brief Whether the last routing was successful
214 : bool myRoutingSuccess;
215 :
216 :
217 : private:
218 : /// @brief Invalidated copy constructor
219 : RORoutable(const RORoutable& src);
220 :
221 : /// @brief Invalidated assignment operator
222 : RORoutable& operator=(const RORoutable& src);
223 :
224 : };
|