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: 2024-11-21 15:56:26 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-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              : /****************************************************************************/
      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 extendDirectionPriority(NBEdgeCont& ec, bool fromUniDir);
      55              : 
      56              :     /// routing edge
      57              :     class Track {
      58              :     public:
      59        24622 :         Track(NBEdge* e, int i = -1, const std::string& _id = "", double _penalty = 1) :
      60        24622 :             edge(e),
      61        24622 :             penalty(_penalty),
      62        24622 :             index(i < 0 ? edge->getNumericalID() : i),
      63        24622 :             id(_id == "" ? edge->getID() : _id),
      64        24622 :             minPermissions(edge->getPermissions()) {
      65        24622 :         }
      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        44590 :             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              : 
      93              :         NBEdge* edge;
      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;
     101              :         SVCPermissions minPermissions;
     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              :     static std::set<NBNode*> getRailNodes(NBEdgeCont& ec, bool verbose = false);
     109              : 
     110              : private:
     111              :     static std::set<NBNode*> getBrokenRailNodes(NBEdgeCont& ec, bool verbose = false);
     112              : 
     113              :     /// @brief filter out rail edges among all edges of a the given node
     114              :     static void getRailEdges(const NBNode* node, EdgeVector& inEdges, EdgeVector& outEdges);
     115              : 
     116              :     /// @brief filter for rail edges but do not return (legacy) all purpose edges
     117              :     static bool hasRailway(SVCPermissions permissions) {
     118        45802 :         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              : 
     128              :     /// @brief add bidi-edge for the given edge
     129              :     static NBEdge* addBidiEdge(NBEdgeCont& ec, NBEdge* edge, bool update = true);
     130              : 
     131              :     /// @brief add further bidi-edges near existing bidi-edges
     132              :     static int extendBidiEdges(NBEdgeCont& ec);
     133              :     static int extendBidiEdges(NBEdgeCont& ec, NBNode* node, NBEdge* bidiIn);
     134              : 
     135              :     /// @brief reverse edges sequences that are to broken nodes on both sides
     136              :     static int reverseEdges(NBEdgeCont& ec, NBPTStopCont& sc);
     137              : 
     138              :     /// @brief add bidi-edges to connect buffers stops in both directions
     139              :     static int addBidiEdgesForBufferStops(NBEdgeCont& ec);
     140              : 
     141              :     /// @brief add bidi-edges to connect switches that are approached in both directions
     142              :     static int addBidiEdgesBetweenSwitches(NBEdgeCont& ec);
     143              : 
     144              :     /// @brief add bidi-edges to connect successive public transport stops
     145              :     static int addBidiEdgesForStops(NBEdgeCont& ec, NBPTLineCont& lc, NBPTStopCont& sc, bool minimal);
     146              : 
     147              :     /// @brief add bidi-edges to connect straight tracks
     148              :     static int addBidiEdgesForStraightConnectivity(NBEdgeCont& ec, bool geometryLike);
     149              : 
     150              :     /// @brief recompute turning directions for both nodes of the given edge
     151              :     static void updateTurns(NBEdge* edge);
     152              : 
     153              :     /// @brief identify lines that are likely to require bidirectional tracks
     154              :     static std::set<NBPTLine*> findBidiCandidates(NBPTLineCont& lc);
     155              : 
     156              : };
     157              : 
     158              : 
     159              : class NBRailwaySignalGuesser {
     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              :     static bool canBeSignal(const NBNode* node);
     167              : };
     168              : 
     169              : class NBRailwayGeometryHelper {
     170              : 
     171              : public:
     172              :     static int straigthenCorrdidor(NBEdgeCont& ec, double maxAngle);
     173              : 
     174              : };
        

Generated by: LCOV version 2.0-1