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