LCOV - code coverage report
Current view: top level - src/netbuild - NBAlgorithms_Railway.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 9 9
Test Date: 2026-03-26 16:31:35 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2012-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    NBAlgorithms_Railway.h
      15              : /// @author  Jakob Erdmann
      16              : /// @author  Melanie Weber
      17              : /// @date    29. March 2018
      18              : ///
      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              :  */
      49              : class NBRailwayTopologyAnalyzer {
      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 setPTLinePriority(NBEdgeCont& ec, NBPTLineCont& lc, SVCPermissions vClasses);
      55              :     static void extendDirectionPriority(NBEdgeCont& ec, bool fromUniDir);
      56              : 
      57              :     /// routing edge
      58              :     class Track {
      59              :     public:
      60        24814 :         Track(NBEdge* e, int i = -1, const std::string& _id = "", double _penalty = 1) :
      61        24814 :             edge(e),
      62        24814 :             penalty(_penalty),
      63        24814 :             index(i < 0 ? edge->getNumericalID() : i),
      64        24814 :             id(_id == "" ? edge->getID() : _id),
      65        24814 :             minPermissions(edge->getPermissions()) {
      66        24814 :         }
      67              : 
      68              :         void addSuccessor(Track* track);
      69              :         const std::vector<Track*>& getSuccessors(SUMOVehicleClass svc = SVC_IGNORING) const;
      70              :         const std::vector<std::pair<const Track*, const Track*> >& getViaSuccessors(SUMOVehicleClass svc = SVC_IGNORING, bool ignoreTransientPermissions = false) const;
      71              : 
      72              :         const std::string& getID() const {
      73              :             return id;
      74              :         }
      75              :         int getNumericalID() const {
      76        20017 :             return index;
      77              :         }
      78              :         double getLength() const {
      79              :             return 0;
      80              :         }
      81              :         const Track* getBidiEdge() const {
      82              :             return this;
      83              :         }
      84              :         bool isInternal() const {
      85              :             return false;
      86              :         }
      87              :         inline bool prohibits(const NBVehicle* const /*veh*/) const {
      88              :             return false;
      89              :         }
      90              :         inline bool restricts(const NBVehicle* const /*veh*/) const {
      91              :             return false;
      92              :         }
      93              : 
      94              :         NBEdge* edge;
      95              :         double penalty;
      96              : 
      97              :     private:
      98              :         const int index;
      99              :         const std::string id;
     100              :         std::vector<Track*> successors;
     101              :         std::vector<std::pair<const Track*, const Track*> > viaSuccessors;
     102              :         SVCPermissions minPermissions;
     103              :         mutable std::map<SUMOVehicleClass, std::vector<Track*> > svcSuccessors;
     104              :         mutable std::map<SUMOVehicleClass, std::vector<std::pair<const Track*, const Track*> > > svcViaSuccessors;
     105              : 
     106              :         Track& operator=(const Track&) = delete;
     107              :     };
     108              :     static double getTravelTimeStatic(const Track* const track, const NBVehicle* const veh, double time);
     109              :     static std::set<NBNode*> getRailNodes(NBEdgeCont& ec, bool verbose = false);
     110              : 
     111              : private:
     112              :     static std::set<NBNode*> getBrokenRailNodes(NBEdgeCont& ec, bool verbose = false);
     113              : 
     114              :     /// @brief filter out rail edges among all edges of a the given node
     115              :     static void getRailEdges(const NBNode* node, EdgeVector& inEdges, EdgeVector& outEdges);
     116              : 
     117              :     /// @brief filter for rail edges but do not return (legacy) all purpose edges
     118              :     static bool hasRailway(SVCPermissions permissions) {
     119        46109 :         return (permissions & SVC_RAIL_CLASSES) > 0 && permissions != SVCAll;
     120              :     }
     121              : 
     122              :     static bool isStraight(const NBNode* node, const NBEdge* e1, const NBEdge* e2);
     123              :     static bool hasStraightPair(const NBNode* node, const EdgeVector& edges, const EdgeVector& edges2);
     124              :     static bool allBroken(const NBNode* node, NBEdge* candOut, const EdgeVector& in, const EdgeVector& out);
     125              :     static bool allSharp(const NBNode* node, const EdgeVector& in, const EdgeVector& out, bool countBidiAsSharp = false);
     126              :     static bool allBidi(const EdgeVector& edges);
     127              :     static NBEdge* isBidiSwitch(const NBNode* n);
     128              : 
     129              :     /// @brief add bidi-edge for the given edge
     130              :     static NBEdge* addBidiEdge(NBEdgeCont& ec, NBEdge* edge, bool update = true);
     131              : 
     132              :     /// @brief add further bidi-edges near existing bidi-edges
     133              :     static int extendBidiEdges(NBEdgeCont& ec);
     134              :     static int extendBidiEdges(NBEdgeCont& ec, NBNode* node, NBEdge* bidiIn);
     135              : 
     136              :     /// @brief reverse edges sequences that are to broken nodes on both sides
     137              :     static int reverseEdges(NBEdgeCont& ec, NBPTStopCont& sc, NBPTLineCont& lc);
     138              : 
     139              :     /// @brief reverse a single edge
     140              :     static void reverseEdge(NBEdge* e);
     141              : 
     142              :     /// @brief add bidi-edges to connect buffers stops in both directions
     143              :     static int addBidiEdgesForBufferStops(NBEdgeCont& ec);
     144              : 
     145              :     /// @brief add bidi-edges to connect switches that are approached in both directions
     146              :     static int addBidiEdgesBetweenSwitches(NBEdgeCont& ec);
     147              : 
     148              :     /// @brief add bidi-edges to connect successive public transport stops
     149              :     static int addBidiEdgesForStops(NBEdgeCont& ec, NBPTLineCont& lc, NBPTStopCont& sc, bool minimal);
     150              : 
     151              :     /// @brief add bidi-edges to connect straight tracks
     152              :     static int addBidiEdgesForStraightConnectivity(NBEdgeCont& ec, bool geometryLike);
     153              : 
     154              :     /// @brief recompute turning directions for both nodes of the given edge
     155              :     static void updateTurns(NBEdge* edge);
     156              : 
     157              :     /// @brief identify lines that are likely to require bidirectional tracks
     158              :     static std::set<NBPTLine*> findBidiCandidates(NBPTLineCont& lc);
     159              : 
     160              : };
     161              : 
     162              : 
     163              : class NBRailwaySignalGuesser {
     164              : 
     165              : public:
     166              :     static int guessRailSignals(NBNodeCont& nc, NBEdgeCont& ec, NBPTStopCont& sc);
     167              : 
     168              : private:
     169              :     static int guessByStops(NBEdgeCont& ec, NBPTStopCont& sc, double minLength);
     170              :     static bool canBeSignal(const NBNode* node);
     171              : };
     172              : 
     173              : class NBRailwayGeometryHelper {
     174              : 
     175              : public:
     176              :     static int straigthenCorrdidor(NBEdgeCont& ec, double maxAngle);
     177              : 
     178              : };
        

Generated by: LCOV version 2.0-1