-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
NBAlgorithms_Railway.h
166 lines (137 loc) · 6.6 KB
/
NBAlgorithms_Railway.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
// Copyright (C) 2012-2024 German Aerospace Center (DLR) and others.
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0/
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License 2.0 are satisfied: GNU General Public License, version 2
// or later which is available at
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
/****************************************************************************/
/// @file NBAlgorithms_Railway.h
/// @author Jakob Erdmann
/// @author Melanie Weber
/// @date 29. March 2018
///
// Algorithms for railways
/****************************************************************************/
#pragma once
#include <config.h>
#include <set>
#include <vector>
// ===========================================================================
// class declarations
// ===========================================================================
class NBEdge;
class NBEdgeCont;
class NBPTStopCont;
class NBPTLine;
class NBPTLineCont;
class OptionsCont;
class NBVehicle;
// ===========================================================================
// class definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// NBAlgorithms_Railway
// ---------------------------------------------------------------------------
/* @class NBRailwayTopologyAnalyzer
* @brief Computes and adapts the topology for the rail network, especially bidi
*/
class NBRailwayTopologyAnalyzer {
public:
static void analyzeTopology(NBEdgeCont& ec);
static int repairTopology(NBEdgeCont& ec, NBPTStopCont& sc, NBPTLineCont& lc);
static int makeAllBidi(NBEdgeCont& ec);
static void extendDirectionPriority(NBEdgeCont& ec, bool fromUniDir);
/// routing edge
class Track {
public:
Track(NBEdge* e, int i = -1, const std::string& _id = "", double _penalty = 1) :
edge(e),
penalty(_penalty),
index(i < 0 ? edge->getNumericalID() : i),
id(_id == "" ? edge->getID() : _id),
minPermissions(edge->getPermissions()) {
}
void addSuccessor(Track* track);
const std::vector<Track*>& getSuccessors(SUMOVehicleClass svc = SVC_IGNORING) const;
const std::vector<std::pair<const Track*, const Track*> >& getViaSuccessors(SUMOVehicleClass svc = SVC_IGNORING, bool ignoreTransientPermissions = false) const;
const std::string& getID() const {
return id;
}
int getNumericalID() const {
return index;
}
double getLength() const {
return 0;
}
const Track* getBidiEdge() const {
return this;
}
bool isInternal() const {
return false;
}
inline bool prohibits(const NBVehicle* const /*veh*/) const {
return false;
}
inline bool restricts(const NBVehicle* const /*veh*/) const {
return false;
}
NBEdge* edge;
double penalty;
private:
const int index;
const std::string id;
std::vector<Track*> successors;
std::vector<std::pair<const Track*, const Track*> > viaSuccessors;
SVCPermissions minPermissions;
mutable std::map<SUMOVehicleClass, std::vector<Track*> > svcSuccessors;
mutable std::map<SUMOVehicleClass, std::vector<std::pair<const Track*, const Track*> > > svcViaSuccessors;
Track& operator=(const Track&) = delete;
};
static double getTravelTimeStatic(const Track* const track, const NBVehicle* const veh, double time);
private:
static std::set<NBNode*> getRailNodes(NBEdgeCont& ec, bool verbose = false);
static std::set<NBNode*> getBrokenRailNodes(NBEdgeCont& ec, bool verbose = false);
/// @brief filter out rail edges among all edges of a the given node
static void getRailEdges(const NBNode* node, EdgeVector& inEdges, EdgeVector& outEdges);
/// @brief filter for rail edges but do not return (legacy) all purpose edges
static bool hasRailway(SVCPermissions permissions) {
return (permissions & SVC_RAIL_CLASSES) > 0 && permissions != SVCAll;
}
static bool isStraight(const NBNode* node, const NBEdge* e1, const NBEdge* e2);
static bool hasStraightPair(const NBNode* node, const EdgeVector& edges, const EdgeVector& edges2);
static bool allBroken(const NBNode* node, NBEdge* candOut, const EdgeVector& in, const EdgeVector& out);
static bool allSharp(const NBNode* node, const EdgeVector& in, const EdgeVector& out, bool countBidiAsSharp = false);
static bool allBidi(const EdgeVector& edges);
static NBEdge* isBidiSwitch(const NBNode* n);
/// @brief add bidi-edge for the given edge
static NBEdge* addBidiEdge(NBEdgeCont& ec, NBEdge* edge, bool update = true);
/// @brief add further bidi-edges near existing bidi-edges
static int extendBidiEdges(NBEdgeCont& ec);
static int extendBidiEdges(NBEdgeCont& ec, NBNode* node, NBEdge* bidiIn);
/// @brief reverse edges sequences that are to broken nodes on both sides
static int reverseEdges(NBEdgeCont& ec, NBPTStopCont& sc);
/// @brief add bidi-edges to connect buffers stops in both directions
static int addBidiEdgesForBufferStops(NBEdgeCont& ec);
/// @brief add bidi-edges to connect switches that are approached in both directions
static int addBidiEdgesBetweenSwitches(NBEdgeCont& ec);
/// @brief add bidi-edges to connect successive public transport stops
static int addBidiEdgesForStops(NBEdgeCont& ec, NBPTLineCont& lc, NBPTStopCont& sc, bool minimal);
/// @brief add bidi-edges to connect straight tracks
static int addBidiEdgesForStraightConnectivity(NBEdgeCont& ec, bool geometryLike);
/// @brief recompute turning directions for both nodes of the given edge
static void updateTurns(NBEdge* edge);
/// @brief identify lines that are likely to require bidirectional tracks
static std::set<NBPTLine*> findBidiCandidates(NBPTLineCont& lc);
};
class NBRailwaySignalGuesser {
public:
static int guessRailSignals(NBEdgeCont& ec, NBPTStopCont& sc);
private:
static int guessByStops(NBEdgeCont& ec, NBPTStopCont& sc, double minLength);
};