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.dev/sumo
3 // Copyright (C) 2012-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 /****************************************************************************/
19 // Algorithms for railways
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <set>
25 #include <vector>
26 
27 
28 // ===========================================================================
29 // class declarations
30 // ===========================================================================
31 class NBEdge;
32 class NBEdgeCont;
33 class NBPTStopCont;
34 class NBPTLine;
35 class NBPTLineCont;
36 class OptionsCont;
37 class NBVehicle;
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
43 // ---------------------------------------------------------------------------
44 // NBAlgorithms_Railway
45 // ---------------------------------------------------------------------------
46 /* @class NBRailwayTopologyAnalyzer
47  * @brief Computes and adapts the topology for the rail network, especially bidi
48  */
50 public:
51  static void analyzeTopology(NBEdgeCont& ec);
52  static int repairTopology(NBEdgeCont& ec, NBPTStopCont& sc, NBPTLineCont& lc);
53  static int makeAllBidi(NBEdgeCont& ec);
54  static void extendDirectionPriority(NBEdgeCont& ec, bool fromUniDir);
55 
57  class Track {
58  public:
59  Track(NBEdge* e, int i = -1, const std::string& _id = "", double _penalty = 1) :
60  edge(e),
61  penalty(_penalty),
62  index(i < 0 ? edge->getNumericalID() : i),
63  id(_id == "" ? edge->getID() : _id),
64  minPermissions(edge->getPermissions()) {
65  }
66 
67  void addSuccessor(Track* track);
68  const std::vector<Track*>& getSuccessors(SUMOVehicleClass svc = SVC_IGNORING) const;
69  const std::vector<std::pair<const Track*, const Track*> >& getViaSuccessors(SUMOVehicleClass svc = SVC_IGNORING, bool ignoreTransientPermissions = false) const;
70 
71  const std::string& getID() const {
72  return id;
73  }
74  int getNumericalID() const {
75  return index;
76  }
77  double getLength() const {
78  return 0;
79  }
80  const Track* getBidiEdge() const {
81  return this;
82  }
83  bool isInternal() const {
84  return false;
85  }
86  inline bool prohibits(const NBVehicle* const /*veh*/) const {
87  return false;
88  }
89  inline bool restricts(const NBVehicle* const /*veh*/) const {
90  return false;
91  }
92 
94  double penalty;
95 
96  private:
97  const int index;
98  const std::string id;
99  std::vector<Track*> successors;
100  std::vector<std::pair<const Track*, const Track*> > viaSuccessors;
102  mutable std::map<SUMOVehicleClass, std::vector<Track*> > svcSuccessors;
103  mutable std::map<SUMOVehicleClass, std::vector<std::pair<const Track*, const Track*> > > svcViaSuccessors;
104 
105  Track& operator=(const Track&) = delete;
106  };
107  static double getTravelTimeStatic(const Track* const track, const NBVehicle* const veh, double time);
108 
109 private:
110  static std::set<NBNode*> getRailNodes(NBEdgeCont& ec, bool verbose = false);
111  static std::set<NBNode*> getBrokenRailNodes(NBEdgeCont& ec, bool verbose = false);
112 
114  static void getRailEdges(const NBNode* node, EdgeVector& inEdges, EdgeVector& outEdges);
115 
117  static bool hasRailway(SVCPermissions permissions) {
118  return (permissions & SVC_RAIL_CLASSES) > 0 && permissions != SVCAll;
119  }
120 
121  static bool isStraight(const NBNode* node, const NBEdge* e1, const NBEdge* e2);
122  static bool hasStraightPair(const NBNode* node, const EdgeVector& edges, const EdgeVector& edges2);
123  static bool allBroken(const NBNode* node, NBEdge* candOut, const EdgeVector& in, const EdgeVector& out);
124  static bool allSharp(const NBNode* node, const EdgeVector& in, const EdgeVector& out, bool countBidiAsSharp = false);
125  static bool allBidi(const EdgeVector& edges);
126  static NBEdge* isBidiSwitch(const NBNode* n);
127 
129  static NBEdge* addBidiEdge(NBEdgeCont& ec, NBEdge* edge, bool update = true);
130 
132  static int extendBidiEdges(NBEdgeCont& ec);
133  static int extendBidiEdges(NBEdgeCont& ec, NBNode* node, NBEdge* bidiIn);
134 
136  static int reverseEdges(NBEdgeCont& ec, NBPTStopCont& sc);
137 
139  static int addBidiEdgesForBufferStops(NBEdgeCont& ec);
140 
142  static int addBidiEdgesBetweenSwitches(NBEdgeCont& ec);
143 
145  static int addBidiEdgesForStops(NBEdgeCont& ec, NBPTLineCont& lc, NBPTStopCont& sc, bool minimal);
146 
148  static int addBidiEdgesForStraightConnectivity(NBEdgeCont& ec, bool geometryLike);
149 
151  static void updateTurns(NBEdge* edge);
152 
154  static std::set<NBPTLine*> findBidiCandidates(NBPTLineCont& lc);
155 
156 };
157 
158 
160 
161 public:
162  static int guessRailSignals(NBEdgeCont& ec, NBPTStopCont& sc);
163 
164 private:
165  static int guessByStops(NBEdgeCont& ec, NBPTStopCont& sc, double minLength);
166 };
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
const SVCPermissions SVCAll
all VClasses are allowed
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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
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
Container for public transport stops during the net building process.
Definition: NBPTStopCont.h:44
static int guessByStops(NBEdgeCont &ec, NBPTStopCont &sc, double minLength)
static int guessRailSignals(NBEdgeCont &ec, NBPTStopCont &sc)
const std::vector< std::pair< const Track *, const Track * > > & getViaSuccessors(SUMOVehicleClass svc=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Track(NBEdge *e, int i=-1, const std::string &_id="", double _penalty=1)
const std::vector< Track * > & getSuccessors(SUMOVehicleClass svc=SVC_IGNORING) 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
Track & operator=(const Track &)=delete
std::map< SUMOVehicleClass, std::vector< Track * > > svcSuccessors
bool prohibits(const NBVehicle *const) const
const std::string & getID() const
static NBEdge * isBidiSwitch(const NBNode *n)
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 int addBidiEdgesForStops(NBEdgeCont &ec, NBPTLineCont &lc, NBPTStopCont &sc, bool minimal)
add bidi-edges to connect successive public transport stops
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