Eclipse SUMO - Simulation of Urban MObility
NBAlgorithms_Railway.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2012-2022 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/****************************************************************************/
19// Algorithms for railways
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24#include <vector>
25#include "NBEdge.h"
26
27
28// ===========================================================================
29// class declarations
30// ===========================================================================
31class NBEdgeCont;
32class NBPTStopCont;
33class NBPTLineCont;
34class OptionsCont;
35class NBVehicle;
36
37
38// ===========================================================================
39// class definitions
40// ===========================================================================
41// ---------------------------------------------------------------------------
42// NBAlgorithms_Railway
43// ---------------------------------------------------------------------------
44/* @class NBRailwayTopologyAnalyzer
45 * @brief Computes and adapts the topology for the rail network, especially bidi
46 */
48public:
49 static void analyzeTopology(NBEdgeCont& ec);
50 static int repairTopology(NBEdgeCont& ec, NBPTStopCont& sc, NBPTLineCont& lc);
51 static int makeAllBidi(NBEdgeCont& ec);
52 static void extendDirectionPriority(NBEdgeCont& ec, bool fromUniDir);
53
55 class Track {
56 public:
57 Track(NBEdge* e, int i = -1, const std::string& _id = "") :
58 edge(e),
59 index(i < 0 ? edge->getNumericalID() : i),
60 id(_id == "" ? edge->getID() : _id),
61 minPermissions(edge->getPermissions()) {
62 }
63
64 void addSuccessor(Track* track);
65 const std::vector<Track*>& getSuccessors(SUMOVehicleClass svc = SVC_IGNORING) const;
66 const std::vector<std::pair<const Track*, const Track*> >& getViaSuccessors(SUMOVehicleClass svc = SVC_IGNORING) const;
67
68 const std::string& getID() const {
69 return id;
70 }
71 int getNumericalID() const {
72 return index;
73 }
74 double getLength() const {
75 return 0.;
76 }
77 const Track* getBidiEdge() const {
78 return this;
79 }
80 bool isInternal() const {
81 return false;
82 }
83 inline bool prohibits(const NBVehicle* const /*veh*/) const {
84 return false;
85 }
86 inline bool restricts(const NBVehicle* const /*veh*/) const {
87 return false;
88 }
89
91
92 private:
93 const int index;
94 const std::string id;
95 std::vector<Track*> successors;
96 std::vector<std::pair<const Track*, const Track*> > viaSuccessors;
98 mutable std::map<SUMOVehicleClass, std::vector<Track*> > svcSuccessors;
99 mutable std::map<SUMOVehicleClass, std::vector<std::pair<const Track*, const Track*> > > svcViaSuccessors;
100
101 Track& operator=(const Track&) = delete;
102 };
103 static double getTravelTimeStatic(const Track* const track, const NBVehicle* const veh, double time);
104
105private:
106 static std::set<NBNode*> getRailNodes(NBEdgeCont& ec, bool verbose = false);
107 static std::set<NBNode*> getBrokenRailNodes(NBEdgeCont& ec, bool verbose = false);
108
110 static void getRailEdges(const NBNode* node, EdgeVector& inEdges, EdgeVector& outEdges);
111
113 static bool hasRailway(SVCPermissions permissions) {
114 return (permissions & SVC_RAIL_CLASSES) > 0 && permissions != SVCAll;
115 }
116
117 static bool isStraight(const NBNode* node, const NBEdge* e1, const NBEdge* e2);
118 static bool hasStraightPair(const NBNode* node, const EdgeVector& edges, const EdgeVector& edges2);
119 static bool allBroken(const NBNode* node, NBEdge* candOut, const EdgeVector& in, const EdgeVector& out);
120 static bool allSharp(const NBNode* node, const EdgeVector& in, const EdgeVector& out, bool countBidiAsSharp = false);
121 static bool allBidi(const EdgeVector& edges);
122 static NBEdge* isBidiSwitch(const NBNode* n);
123
125 static NBEdge* addBidiEdge(NBEdgeCont& ec, NBEdge* edge, bool update = true);
126
128 static int extendBidiEdges(NBEdgeCont& ec);
129 static int extendBidiEdges(NBEdgeCont& ec, NBNode* node, NBEdge* bidiIn);
130
132 static int reverseEdges(NBEdgeCont& ec, NBPTStopCont& sc);
133
136
139
142
144 static int addBidiEdgesForStraightConnectivity(NBEdgeCont& ec, bool geometryLike);
145
147 static void updateTurns(NBEdge* edge);
148
150 static std::set<NBPTLine*> findBidiCandidates(NBPTLineCont& lc);
151
152};
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:42
const SVCPermissions SVCAll
all VClasses are allowed
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_RAIL_CLASSES
classes which drive on tracks
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
The representation of a single edge during network building.
Definition: NBEdge.h:92
Represents a single node (junction) during network building.
Definition: NBNode.h:66
const std::vector< std::pair< const Track *, const Track * > > & getViaSuccessors(SUMOVehicleClass svc=SVC_IGNORING) const
Track & operator=(const Track &)=delete
const std::vector< Track * > & getSuccessors(SUMOVehicleClass svc=SVC_IGNORING) const
const std::string & getID() const
std::vector< std::pair< const Track *, const Track * > > viaSuccessors
std::map< SUMOVehicleClass, std::vector< std::pair< const Track *, const Track * > > > svcViaSuccessors
bool restricts(const NBVehicle *const) const
std::map< SUMOVehicleClass, std::vector< Track * > > svcSuccessors
bool prohibits(const NBVehicle *const) const
Track(NBEdge *e, int i=-1, const std::string &_id="")
static NBEdge * isBidiSwitch(const NBNode *n)
static int addBidiEdgesForStops(NBEdgeCont &ec, NBPTLineCont &lc, NBPTStopCont &sc)
add bidi-edges to connect successive public transport stops
static int repairTopology(NBEdgeCont &ec, NBPTStopCont &sc, NBPTLineCont &lc)
static void getRailEdges(const NBNode *node, EdgeVector &inEdges, EdgeVector &outEdges)
filter out rail edges among all edges of a the given node
static void extendDirectionPriority(NBEdgeCont &ec, bool fromUniDir)
static std::set< NBNode * > getRailNodes(NBEdgeCont &ec, bool verbose=false)
static void updateTurns(NBEdge *edge)
recompute turning directions for both nodes of the given edge
static bool isStraight(const NBNode *node, const NBEdge *e1, const NBEdge *e2)
static void analyzeTopology(NBEdgeCont &ec)
static std::set< NBPTLine * > findBidiCandidates(NBPTLineCont &lc)
identify lines that are likely to require bidirectional tracks
static int addBidiEdgesForStraightConnectivity(NBEdgeCont &ec, bool geometryLike)
add bidi-edges to connect straight tracks
static bool allSharp(const NBNode *node, const EdgeVector &in, const EdgeVector &out, bool countBidiAsSharp=false)
static bool allBroken(const NBNode *node, NBEdge *candOut, const EdgeVector &in, const EdgeVector &out)
static std::set< NBNode * > getBrokenRailNodes(NBEdgeCont &ec, bool verbose=false)
static int addBidiEdgesBetweenSwitches(NBEdgeCont &ec)
add bidi-edges to connect switches that are approached in both directions
static bool allBidi(const EdgeVector &edges)
static int makeAllBidi(NBEdgeCont &ec)
static double getTravelTimeStatic(const Track *const track, const NBVehicle *const veh, double time)
static bool hasRailway(SVCPermissions permissions)
filter for rail edges but do not return (legacy) all purpose edges
static int reverseEdges(NBEdgeCont &ec, NBPTStopCont &sc)
reverse edges sequences that are to broken nodes on both sides
static bool hasStraightPair(const NBNode *node, const EdgeVector &edges, const EdgeVector &edges2)
static int addBidiEdgesForBufferStops(NBEdgeCont &ec)
add bidi-edges to connect buffers stops in both directions
static NBEdge * addBidiEdge(NBEdgeCont &ec, NBEdge *edge, bool update=true)
add bidi-edge for the given edge
static int extendBidiEdges(NBEdgeCont &ec)
add further bidi-edges near existing bidi-edges
A vehicle as used by router.
Definition: NBVehicle.h:42
A storage for options typed value containers)
Definition: OptionsCont.h:89