Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2002-2025 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 301128 : RORoutable(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type) :
61 301128 : myParameter(pars),
62 301128 : myType(type),
63 301128 : myRandomSeed(RandHelper::murmur3_32(pars.id, RandHelper::getSeed())),
64 602256 : myRoutingSuccess(false) {}
65 :
66 :
67 : /// @brief Destructor
68 301128 : 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 394970 : return myParameter;
77 : }
78 :
79 :
80 : /** @brief Returns the type of the routable
81 : *
82 : * @return The routable's type
83 : *
84 : * @todo Why not return a reference?
85 : */
86 : inline const SUMOVTypeParameter* getType() const {
87 15537875 : return myType;
88 : }
89 :
90 :
91 : /** @brief Returns the id of the routable
92 : *
93 : * @return The id of the routable
94 : */
95 : inline const std::string& getID() const {
96 300701 : return myParameter.id;
97 : }
98 :
99 : /// @brief return vehicle-specific random number
100 : long long int getRandomSeed() const {
101 6984 : return myRandomSeed;
102 : }
103 :
104 : /** @brief Returns the time the vehicle starts at, -1 for triggered vehicles
105 : *
106 : * @return The vehicle's depart time
107 : */
108 : inline SUMOTime getDepart() const {
109 300175 : return myParameter.depart;
110 : }
111 :
112 : /// @brief update depart time (for triggered persons)
113 : inline void setDepart(SUMOTime t) {
114 : myParameter.depart = t;
115 : }
116 :
117 : inline SUMOVehicleClass getVClass() const {
118 20047602 : return getType() != 0 ? getType()->vehicleClass : SVC_IGNORING;
119 : }
120 :
121 : /** @brief Returns whether this object is ignoring transient permission
122 : * changes (during routing)
123 : */
124 : bool ignoreTransientPermissions() const {
125 : return false;
126 : };
127 :
128 : /// @brief Returns the vehicle's maximum speed
129 : inline double getMaxSpeed() const {
130 14447 : return MIN2(getType()->maxSpeed,
131 9036755 : getType()->desiredMaxSpeed * getType()->speedFactor.getParameter(0));
132 : }
133 :
134 : virtual const ROEdge* getDepartEdge() const = 0;
135 :
136 :
137 : inline bool isPublicTransport() const {
138 596835 : return myParameter.line != "";
139 : }
140 :
141 : inline bool isPartOfFlow() const {
142 297612 : return myParameter.repetitionNumber >= 0;
143 : }
144 :
145 : virtual void computeRoute(const RORouterProvider& provider,
146 : const bool removeLoops, MsgHandler* errorHandler) = 0;
147 :
148 :
149 : /** @brief Saves the routable including the vehicle type (if it was not saved before).
150 : *
151 : * @param[in] os The routes - output device to store the vehicle's description into
152 : * @param[in] altos The route alternatives - output device to store the vehicle's description into
153 : * @param[in] typeos The types - output device to store the vehicle types into
154 : * @exception IOError If something fails (not yet implemented)
155 : */
156 280773 : void write(OutputDevice* os, OutputDevice* const altos,
157 : OutputDevice* const typeos, OptionsCont& options, int quota) const {
158 561602 : for (int i = 0; i < quota; i++) {
159 280829 : if (os != nullptr) {
160 280827 : if (altos == nullptr && typeos == nullptr) {
161 159350 : saveAsXML(*os, os, false, options, i);
162 : } else {
163 121477 : saveAsXML(*os, typeos, false, options, i);
164 : }
165 : }
166 280829 : if (altos != nullptr) {
167 113903 : saveAsXML(*altos, typeos, true, options, i);
168 : }
169 : }
170 280773 : }
171 :
172 :
173 : inline bool getRoutingSuccess() const {
174 299962 : return myRoutingSuccess;
175 : }
176 :
177 :
178 : protected:
179 : /** @brief Saves the complete routable description.
180 : *
181 : * Saves the routable itself including the route and stops.
182 : *
183 : * @param[in] os The routes or alternatives output device to store the routable's description into
184 : * @param[in] typeos The types - output device to store additional types into
185 : * @param[in] asAlternatives Whether the route shall be saved as route alternatives
186 : * @param[in] options to find out about defaults and whether exit times for the edges shall be written
187 : * @exception IOError If something fails (not yet implemented)
188 : */
189 : virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex = 0) const = 0;
190 :
191 :
192 : private:
193 : /// @brief The vehicle's parameter
194 : SUMOVehicleParameter myParameter;
195 :
196 : /// @brief The type of the vehicle
197 : const SUMOVTypeParameter* const myType;
198 :
199 : /// @brief object-specific random constant
200 : const long long int myRandomSeed;
201 :
202 : protected:
203 : /// @brief Whether the last routing was successful
204 : bool myRoutingSuccess;
205 :
206 :
207 : private:
208 : /// @brief Invalidated copy constructor
209 : RORoutable(const RORoutable& src);
210 :
211 : /// @brief Invalidated assignment operator
212 : RORoutable& operator=(const RORoutable& src);
213 :
214 : };
|