LCOV - code coverage report
Current view: top level - src/netbuild - NBAlgorithms_Ramps.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 77.8 % 9 7
Test Date: 2024-12-21 15:45:41 Functions: 100.0 % 2 2

            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_Ramps.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @date    29. March 2012
      18              : ///
      19              : // Algorithms for highway on-/off-ramps computation
      20              : /****************************************************************************/
      21              : #pragma once
      22              : #include <config.h>
      23              : 
      24              : #include <vector>
      25              : 
      26              : 
      27              : // ===========================================================================
      28              : // class declarations
      29              : // ===========================================================================
      30              : class NBNetBuilder;
      31              : class OptionsCont;
      32              : class NBNode;
      33              : class NBEdgeCont;
      34              : class NBDistrictCont;
      35              : 
      36              : 
      37              : // ===========================================================================
      38              : // class definitions
      39              : // ===========================================================================
      40              : // ---------------------------------------------------------------------------
      41              : // NBAlgorithms_Ramps
      42              : // ---------------------------------------------------------------------------
      43              : /* @class NBRampsComputer
      44              :  * @brief Computes highway on-/off-ramps (if wished)
      45              :  */
      46         1616 : class NBRampsComputer {
      47              : public:
      48              :     /** @brief Computes highway on-/off-ramps (if wished)
      49              :      * @param[in, changed] nb The network builder which contains the current network representation
      50              :      * @param[in] oc The options container
      51              :      */
      52              :     NBRampsComputer();
      53              : 
      54              :     void computeRamps(NBNetBuilder& nb, OptionsCont& oc, bool mayAddOrRemove);
      55              : 
      56              :     /// @brief suffix for newly generated on-ramp edges
      57              :     static const std::string ADDED_ON_RAMP_EDGE;
      58              : 
      59              : private:
      60              : 
      61              :     std::map<NBEdge*, double> myShiftedEdges;
      62              : 
      63              : 
      64              :     /** @brief Determines whether the given node may be an on-ramp begin
      65              :      * @param[in] cur The node to check
      66              :      * @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway
      67              :      * @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp
      68              :      * @param[in] noramps Edges that shall not be treated as ramps
      69              :      * @param[in] minWeaveLength The minimum length for weaving areas
      70              :      * @return Whether the node is assumed to be an on-ramp begin
      71              :      */
      72              :     static bool mayNeedOnRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed,
      73              :                               const std::set<std::string>& noramps, double minWeaveLength);
      74              : 
      75              : 
      76              :     /** @brief Determines whether the given node may be an off-ramp end
      77              :      * @param[in] cur The node to check
      78              :      * @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway
      79              :      * @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp
      80              :      * @param[in] noramps Edges that shall not be treated as ramps
      81              :      * @return Whether the node is assumed to be an off-ramp end
      82              :      */
      83              :     static bool mayNeedOffRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed,
      84              :                                const std::set<std::string>& noramps);
      85              : 
      86              : 
      87              :     /** @brief Builds an on-ramp starting at the given node
      88              :      * @param[in] cur The node at which the on-ramp shall begin
      89              :      * @param[in] nc The container of nodes
      90              :      * @param[in] ec The container of edges
      91              :      * @param[in] dc The container of districts
      92              :      * @param[in] rampLength The wished ramp length
      93              :      * @param[in] dontSplit Whether no edges shall be split
      94              :      * @param[in, filled] incremented The list of edges which lane number was already incremented
      95              :      */
      96              :     void buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes);
      97              : 
      98              : 
      99              :     /** @brief Builds an off-ramp ending at the given node
     100              :      * @param[in] cur The node at which the off-ramp shall end
     101              :      * @param[in] nc The container of nodes
     102              :      * @param[in] ec The container of edges
     103              :      * @param[in] dc The container of districts
     104              :      * @param[in] rampLength The wished ramp length
     105              :      * @param[in] dontSplit Whether no edges shall be split
     106              :      * @param[in, filled] incremented The list of edges which lane number was already incremented
     107              :      */
     108              :     void buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes,
     109              :                       const std::set<NBNode*, ComparatorIdLess>& potOnRamps);
     110              : 
     111              : 
     112              :     static void getOnRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other);
     113              :     static void getOffRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other);
     114              :     static bool determinedBySpeed(NBEdge** potHighway, NBEdge** potRamp);
     115              :     static bool determinedByLaneNumber(NBEdge** potHighway, NBEdge** potRamp);
     116              : 
     117              :     /** @brief Checks whether an on-/off-ramp can be bult here
     118              :      *
     119              :      * - none of the participating edges must be a macroscopic connector
     120              :      * - ramp+highways together must have more lanes than the continuation
     121              :      * - speeds must match the defined swells
     122              :      * @param[in] potHighway The highway part to check
     123              :      * @param[in] potRamp The ramp part to check
     124              :      * @param[in] other The successor/predecessor edge
     125              :      * @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway
     126              :      * @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp
     127              :      * @param[in] noramps Edges that shall not be treated as ramps
     128              :      * @return Whether a ramp can be built here
     129              :      */
     130              :     static bool fulfillsRampConstraints(NBEdge* potHighway, NBEdge* potRamp, NBEdge* other, double minHighwaySpeed, double maxRampSpeed,
     131              :                                         const std::set<std::string>& noramps);
     132              : 
     133              : 
     134              :     /** @brief Moves the ramp to the right, as new lanes were added
     135              :      * @param[in] ramp The ramp to move
     136              :      * @param[in] addedLanes The number of added lanes
     137              :      */
     138              :     void moveRampRight(NBEdge* ramp, int addedLanes);
     139              : 
     140              :     /// @brief whether the edge has a mode that does not indicate a ramp edge
     141              :     static bool hasWrongMode(NBEdge* edge);
     142              : 
     143              :     /// @brief shift ramp geometry to merge smoothly with the motorway
     144              :     static void patchRampGeometry(NBEdge* potRamp, NBEdge* first, NBEdge* potHighway, bool onRamp);
     145              : 
     146              :     template <class T>
     147           90 :     static std::string getUnusedID(const std::string& prefix, const T& objectCont) {
     148           90 :         if (objectCont.retrieve(prefix) == nullptr) {
     149              :             return prefix;
     150              :         }
     151            4 :         int i = 0;
     152            8 :         std::string result = prefix + "#" + toString(i);
     153            4 :         while (objectCont.retrieve(result) != nullptr) {
     154            0 :             i++;
     155            0 :             result = prefix + "#" + toString(i);
     156              :         }
     157            4 :         return result;
     158              :     }
     159              : };
        

Generated by: LCOV version 2.0-1