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 RORouteDef.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @author Jakob Erdmann
18 : /// @date Sept 2002
19 : ///
20 : // Base class for a vehicle's route definition
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <iostream>
27 : #include <utils/common/Named.h>
28 : #include <utils/router/SUMOAbstractRouter.h>
29 : #include "RORoute.h"
30 :
31 :
32 : // ===========================================================================
33 : // class declarations
34 : // ===========================================================================
35 : class ROEdge;
36 : class OptionsCont;
37 : class ROVehicle;
38 : class OutputDevice;
39 :
40 :
41 : // ===========================================================================
42 : // class definitions
43 : // ===========================================================================
44 : /**
45 : * @class RORouteDef
46 : * @brief Base class for a vehicle's route definition
47 : *
48 : * This class resembles what a vehicle knows about his route when being loaded
49 : * into a router. Whether it is just the origin and the destination, the whole
50 : * route through the network or even a route with alternatives depends on
51 : * the derived class.
52 : */
53 : class RORouteDef : public Named {
54 : public:
55 : /** @brief Constructor
56 : *
57 : * @param[in] id The id of the route
58 : * @param[in] color The color of the route
59 : */
60 : RORouteDef(const std::string& id, const int lastUsed,
61 : const bool tryRepair, const bool mayBeDisconnected);
62 :
63 :
64 : /// @brief Destructor
65 : virtual ~RORouteDef();
66 :
67 :
68 : /** @brief Adds a single alternative loaded from the file
69 : An alternative may also be generated during DUA */
70 : void addLoadedAlternative(RORoute* alternative);
71 :
72 : /** @brief Adds an alternative loaded from the file */
73 : void addAlternativeDef(const RORouteDef* alternative);
74 :
75 : /** @brief removes invalid alternatives and raise an error or warning **/
76 : void validateAlternatives(const ROVehicle* veh, MsgHandler* errorHandler);
77 :
78 : /** @brief Triggers building of the complete route (via
79 : * preComputeCurrentRoute) or returns precomputed route */
80 : RORoute* buildCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
81 : const ROVehicle& veh) const;
82 :
83 : /** @brief Builds the complete route
84 : * (or chooses her from the list of alternatives, when existing) */
85 : void preComputeCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
86 : const ROVehicle& veh) const;
87 :
88 : /** @brief Builds the complete route
89 : * (or chooses her from the list of alternatives, when existing) */
90 : bool repairCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
91 : const ROVehicle& veh, ConstROEdgeVector oldEdges, ConstROEdgeVector& newEdges,
92 : bool isTrip = false) const;
93 :
94 : /** @brief Adds an alternative to the list of routes
95 : * and returns the route that was replaced or nullptr
96 : *
97 : * (This may be the new route) */
98 : RORoute* addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle>& router,
99 : const ROVehicle* const, RORoute* current, SUMOTime begin,
100 : MsgHandler* errorHandler);
101 :
102 : const ROEdge* getOrigin() const;
103 : const ROEdge* getDestination() const;
104 :
105 : const RORoute* getFirstRoute() const {
106 972570 : if (myAlternatives.empty()) {
107 : return 0;
108 : }
109 971808 : return myAlternatives.front();
110 : }
111 :
112 : const RORoute* getUsedRoute() const {
113 40 : return myAlternatives[myLastUsed];
114 : }
115 :
116 : /** @brief Saves the built route / route alternatives
117 : *
118 : * Writes the route into the given stream.
119 : *
120 : * @param[in] dev The device to write the route into
121 : * @param[in] asAlternatives Whether the route shall be saved as route alternatives
122 : * @return The same device for further usage
123 : */
124 : OutputDevice& writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
125 : bool asAlternatives, bool withExitTimes, bool withCost, bool withLength) const;
126 :
127 :
128 : /** @brief Returns a deep copy of the route definition.
129 : *
130 : * The resulting route definition contains copies of all
131 : * routes contained in this one
132 : *
133 : * @param[in] id The id for the new route definition
134 : * @param[in] stopOffset The offset time for "until"-stops defined in the original route
135 : * @return the new route definition
136 : */
137 : RORouteDef* copy(const std::string& id, const SUMOTime stopOffset) const;
138 :
139 : /** @brief Returns the sum of the probablities of the contained routes */
140 : double getOverallProb() const;
141 :
142 :
143 : /// @brief whether this route shall be silently discarded
144 : bool discardSilent() const {
145 1925 : return myDiscardSilent;
146 : }
147 :
148 :
149 : static void setUsingJTRR() {
150 112 : myUsingJTRR = true;
151 : }
152 :
153 : static void setSkipNew() {
154 23 : mySkipNewRoutes = true;
155 23 : }
156 :
157 : protected:
158 : /// @brief backtrack to last mandatory edge and route to next mandatory
159 : static bool backTrack(SUMOAbstractRouter<ROEdge, ROVehicle>& router,
160 : ConstROEdgeVector::const_iterator& i, int lastMandatory, const ROEdge* nextMandatory,
161 : ConstROEdgeVector& newEdges, const ROVehicle& veh, SUMOTime begin);
162 :
163 : protected:
164 : /// @brief precomputed route for out-of-order computation
165 : mutable RORoute* myPrecomputed;
166 :
167 : /// @brief Index of the route used within the last step
168 : mutable int myLastUsed;
169 :
170 : /// @brief The alternatives
171 : std::vector<RORoute*> myAlternatives;
172 :
173 : /// @brief Routes which are deleted someplace else
174 : std::set<RORoute*> myRouteRefs;
175 :
176 : /// @brief Information whether a new route was generated
177 : mutable bool myNewRoute;
178 :
179 : const bool myTryRepair;
180 : const bool myMayBeDisconnected;
181 :
182 : /// @brief Whether this route should be silently discarded
183 : mutable bool myDiscardSilent;
184 :
185 : static bool myUsingJTRR;
186 : static bool mySkipNewRoutes;
187 :
188 : private:
189 : /// @brief Invalidated copy constructor
190 : RORouteDef(const RORouteDef& src) = delete;
191 :
192 : /// @brief Invalidated assignment operator
193 : RORouteDef& operator=(const RORouteDef& src) = delete;
194 :
195 : };
|