Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2002-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 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 Triggers building of the complete route (via
76 : * preComputeCurrentRoute) or returns precomputed route */
77 : RORoute* buildCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
78 : const ROVehicle& veh) const;
79 :
80 : /** @brief Builds the complete route
81 : * (or chooses her from the list of alternatives, when existing) */
82 : void preComputeCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
83 : const ROVehicle& veh) const;
84 :
85 : /** @brief Builds the complete route
86 : * (or chooses her from the list of alternatives, when existing) */
87 : bool repairCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
88 : const ROVehicle& veh, ConstROEdgeVector oldEdges, ConstROEdgeVector& newEdges) const;
89 :
90 : /** @brief Adds an alternative to the list of routes
91 : *
92 : * (This may be the new route) */
93 : void addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle>& router,
94 : const ROVehicle* const, RORoute* current, SUMOTime begin);
95 :
96 : const ROEdge* getDestination() const;
97 :
98 : const RORoute* getFirstRoute() const {
99 317072 : if (myAlternatives.empty()) {
100 : return 0;
101 : }
102 316582 : return myAlternatives.front();
103 : }
104 :
105 : const RORoute* getUsedRoute() const {
106 28 : return myAlternatives[myLastUsed];
107 : }
108 :
109 : /** @brief Saves the built route / route alternatives
110 : *
111 : * Writes the route into the given stream.
112 : *
113 : * @param[in] dev The device to write the route into
114 : * @param[in] asAlternatives Whether the route shall be saved as route alternatives
115 : * @return The same device for further usage
116 : */
117 : OutputDevice& writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
118 : bool asAlternatives, bool withExitTimes, bool withCost, bool withLength) const;
119 :
120 :
121 : /** @brief Returns a deep copy of the route definition.
122 : *
123 : * The resulting route definition contains copies of all
124 : * routes contained in this one
125 : *
126 : * @param[in] id The id for the new route definition
127 : * @param[in] stopOffset The offset time for "until"-stops defined in the original route
128 : * @return the new route definition
129 : */
130 : RORouteDef* copy(const std::string& id, const SUMOTime stopOffset) const;
131 :
132 : /** @brief Returns the sum of the probablities of the contained routes */
133 : double getOverallProb() const;
134 :
135 :
136 : /// @brief whether this route shall be silently discarded
137 : bool discardSilent() const {
138 1300 : return myDiscardSilent;
139 : }
140 :
141 :
142 : static void setUsingJTRR() {
143 111 : myUsingJTRR = true;
144 : }
145 :
146 : protected:
147 : /// @brief precomputed route for out-of-order computation
148 : mutable RORoute* myPrecomputed;
149 :
150 : /// @brief Index of the route used within the last step
151 : mutable int myLastUsed;
152 :
153 : /// @brief The alternatives
154 : std::vector<RORoute*> myAlternatives;
155 :
156 : /// @brief Routes which are deleted someplace else
157 : std::set<RORoute*> myRouteRefs;
158 :
159 : /// @brief Information whether a new route was generated
160 : mutable bool myNewRoute;
161 :
162 : const bool myTryRepair;
163 : const bool myMayBeDisconnected;
164 :
165 : /// @brief Whether this route should be silently discarded
166 : mutable bool myDiscardSilent;
167 :
168 : static bool myUsingJTRR;
169 :
170 : private:
171 : /// @brief Invalidated copy constructor
172 : RORouteDef(const RORouteDef& src) = delete;
173 :
174 : /// @brief Invalidated assignment operator
175 : RORouteDef& operator=(const RORouteDef& src) = delete;
176 :
177 : };
|