Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/router/RORouteDef.h
193871 views
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
*
96
* (This may be the new route) */
97
void addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle>& router,
98
const ROVehicle* const, RORoute* current, SUMOTime begin,
99
MsgHandler* errorHandler);
100
101
const ROEdge* getOrigin() const;
102
const ROEdge* getDestination() const;
103
104
const RORoute* getFirstRoute() const {
105
if (myAlternatives.empty()) {
106
return 0;
107
}
108
return myAlternatives.front();
109
}
110
111
const RORoute* getUsedRoute() const {
112
return myAlternatives[myLastUsed];
113
}
114
115
/** @brief Saves the built route / route alternatives
116
*
117
* Writes the route into the given stream.
118
*
119
* @param[in] dev The device to write the route into
120
* @param[in] asAlternatives Whether the route shall be saved as route alternatives
121
* @return The same device for further usage
122
*/
123
OutputDevice& writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
124
bool asAlternatives, bool withExitTimes, bool withCost, bool withLength) const;
125
126
127
/** @brief Returns a deep copy of the route definition.
128
*
129
* The resulting route definition contains copies of all
130
* routes contained in this one
131
*
132
* @param[in] id The id for the new route definition
133
* @param[in] stopOffset The offset time for "until"-stops defined in the original route
134
* @return the new route definition
135
*/
136
RORouteDef* copy(const std::string& id, const SUMOTime stopOffset) const;
137
138
/** @brief Returns the sum of the probablities of the contained routes */
139
double getOverallProb() const;
140
141
142
/// @brief whether this route shall be silently discarded
143
bool discardSilent() const {
144
return myDiscardSilent;
145
}
146
147
148
static void setUsingJTRR() {
149
myUsingJTRR = true;
150
}
151
152
static void setSkipNew() {
153
mySkipNewRoutes = true;
154
}
155
156
protected:
157
/// @brief backtrack to last mandatory edge and route to next mandatory
158
static bool backTrack(SUMOAbstractRouter<ROEdge, ROVehicle>& router,
159
ConstROEdgeVector::const_iterator& i, int lastMandatory, const ROEdge* nextMandatory,
160
ConstROEdgeVector& newEdges, const ROVehicle& veh, SUMOTime begin);
161
162
protected:
163
/// @brief precomputed route for out-of-order computation
164
mutable RORoute* myPrecomputed;
165
166
/// @brief Index of the route used within the last step
167
mutable int myLastUsed;
168
169
/// @brief The alternatives
170
std::vector<RORoute*> myAlternatives;
171
172
/// @brief Routes which are deleted someplace else
173
std::set<RORoute*> myRouteRefs;
174
175
/// @brief Information whether a new route was generated
176
mutable bool myNewRoute;
177
178
const bool myTryRepair;
179
const bool myMayBeDisconnected;
180
181
/// @brief Whether this route should be silently discarded
182
mutable bool myDiscardSilent;
183
184
static bool myUsingJTRR;
185
static bool mySkipNewRoutes;
186
187
private:
188
/// @brief Invalidated copy constructor
189
RORouteDef(const RORouteDef& src) = delete;
190
191
/// @brief Invalidated assignment operator
192
RORouteDef& operator=(const RORouteDef& src) = delete;
193
194
};
195
196