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 : 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 : static void computeRamps(NBNetBuilder& nb, OptionsCont& oc, bool mayAddOrRemove); 53 : 54 : /// @brief suffix for newly generated on-ramp edges 55 : static const std::string ADDED_ON_RAMP_EDGE; 56 : 57 : private: 58 : /** @brief Determines whether the given node may be an on-ramp begin 59 : * @param[in] cur The node to check 60 : * @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway 61 : * @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp 62 : * @param[in] noramps Edges that shall not be treated as ramps 63 : * @param[in] minWeaveLength The minimum length for weaving areas 64 : * @return Whether the node is assumed to be an on-ramp begin 65 : */ 66 : static bool mayNeedOnRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed, 67 : const std::set<std::string>& noramps, double minWeaveLength); 68 : 69 : 70 : /** @brief Determines whether the given node may be an off-ramp end 71 : * @param[in] cur The node to check 72 : * @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway 73 : * @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp 74 : * @param[in] noramps Edges that shall not be treated as ramps 75 : * @return Whether the node is assumed to be an off-ramp end 76 : */ 77 : static bool mayNeedOffRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed, 78 : const std::set<std::string>& noramps); 79 : 80 : 81 : /** @brief Builds an on-ramp starting at the given node 82 : * @param[in] cur The node at which the on-ramp shall begin 83 : * @param[in] nc The container of nodes 84 : * @param[in] ec The container of edges 85 : * @param[in] dc The container of districts 86 : * @param[in] rampLength The wished ramp length 87 : * @param[in] dontSplit Whether no edges shall be split 88 : * @param[in, filled] incremented The list of edges which lane number was already incremented 89 : */ 90 : static void buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes); 91 : 92 : 93 : /** @brief Builds an off-ramp ending at the given node 94 : * @param[in] cur The node at which the off-ramp shall end 95 : * @param[in] nc The container of nodes 96 : * @param[in] ec The container of edges 97 : * @param[in] dc The container of districts 98 : * @param[in] rampLength The wished ramp length 99 : * @param[in] dontSplit Whether no edges shall be split 100 : * @param[in, filled] incremented The list of edges which lane number was already incremented 101 : */ 102 : static void buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes, 103 : const std::set<NBNode*, ComparatorIdLess>& potOnRamps); 104 : 105 : 106 : static void getOnRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other); 107 : static void getOffRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other); 108 : static bool determinedBySpeed(NBEdge** potHighway, NBEdge** potRamp); 109 : static bool determinedByLaneNumber(NBEdge** potHighway, NBEdge** potRamp); 110 : 111 : /** @brief Checks whether an on-/off-ramp can be bult here 112 : * 113 : * - none of the participating edges must be a macroscopic connector 114 : * - ramp+highways together must have more lanes than the continuation 115 : * - speeds must match the defined swells 116 : * @param[in] potHighway The highway part to check 117 : * @param[in] potRamp The ramp part to check 118 : * @param[in] other The successor/predecessor edge 119 : * @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway 120 : * @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp 121 : * @param[in] noramps Edges that shall not be treated as ramps 122 : * @return Whether a ramp can be built here 123 : */ 124 : static bool fulfillsRampConstraints(NBEdge* potHighway, NBEdge* potRamp, NBEdge* other, double minHighwaySpeed, double maxRampSpeed, 125 : const std::set<std::string>& noramps); 126 : 127 : 128 : /** @brief Moves the ramp to the right, as new lanes were added 129 : * @param[in] ramp The ramp to move 130 : * @param[in] addedLanes The number of added lanes 131 : */ 132 : static void moveRampRight(NBEdge* ramp, int addedLanes); 133 : 134 : /// @brief whether the edge has a mode that does not indicate a ramp edge 135 : static bool hasWrongMode(NBEdge* edge); 136 : 137 : /// @brief shift ramp geometry to merge smoothly with the motorway 138 : static void patchRampGeometry(NBEdge* potRamp, NBEdge* first, NBEdge* potHighway, bool onRamp); 139 : 140 : template <class T> 141 90 : static std::string getUnusedID(const std::string& prefix, const T& objectCont) { 142 90 : if (objectCont.retrieve(prefix) == nullptr) { 143 : return prefix; 144 : } 145 4 : int i = 0; 146 8 : std::string result = prefix + "#" + toString(i); 147 4 : while (objectCont.retrieve(result) != nullptr) { 148 0 : i++; 149 0 : result = prefix + "#" + toString(i); 150 : } 151 : return result; 152 : } 153 : };