/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file NBAlgorithms_Ramps.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @date 29. March 201217///18// Algorithms for highway on-/off-ramps computation19/****************************************************************************/20#pragma once21#include <config.h>2223#include <vector>242526// ===========================================================================27// class declarations28// ===========================================================================29class NBNetBuilder;30class OptionsCont;31class NBNode;32class NBEdgeCont;33class NBDistrictCont;343536// ===========================================================================37// class definitions38// ===========================================================================39// ---------------------------------------------------------------------------40// NBAlgorithms_Ramps41// ---------------------------------------------------------------------------42/* @class NBRampsComputer43* @brief Computes highway on-/off-ramps (if wished)44*/45class NBRampsComputer {46public:47/** @brief Computes highway on-/off-ramps (if wished)48* @param[in, changed] nb The network builder which contains the current network representation49* @param[in] oc The options container50*/51NBRampsComputer();5253void computeRamps(NBNetBuilder& nb, OptionsCont& oc, bool mayAddOrRemove);5455/// @brief suffix for newly generated on-ramp edges56static const std::string ADDED_ON_RAMP_EDGE;5758private:5960std::map<NBEdge*, double> myShiftedEdges;616263/** @brief Determines whether the given node may be an on-ramp begin64* @param[in] cur The node to check65* @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway66* @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp67* @param[in] noramps Edges that shall not be treated as ramps68* @param[in] minWeaveLength The minimum length for weaving areas69* @return Whether the node is assumed to be an on-ramp begin70*/71static bool mayNeedOnRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed,72const std::set<std::string>& noramps, double minWeaveLength);737475/** @brief Determines whether the given node may be an off-ramp end76* @param[in] cur The node to check77* @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway78* @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp79* @param[in] noramps Edges that shall not be treated as ramps80* @return Whether the node is assumed to be an off-ramp end81*/82static bool mayNeedOffRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed,83const std::set<std::string>& noramps);848586/** @brief Builds an on-ramp starting at the given node87* @param[in] cur The node at which the on-ramp shall begin88* @param[in] nc The container of nodes89* @param[in] ec The container of edges90* @param[in] dc The container of districts91* @param[in] rampLength The wished ramp length92* @param[in] dontSplit Whether no edges shall be split93* @param[in, filled] incremented The list of edges which lane number was already incremented94*/95void buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes);969798/** @brief Builds an off-ramp ending at the given node99* @param[in] cur The node at which the off-ramp shall end100* @param[in] nc The container of nodes101* @param[in] ec The container of edges102* @param[in] dc The container of districts103* @param[in] rampLength The wished ramp length104* @param[in] dontSplit Whether no edges shall be split105* @param[in, filled] incremented The list of edges which lane number was already incremented106*/107void buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes,108const std::set<NBNode*, ComparatorIdLess>& potOnRamps);109110111static void getOnRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other);112static void getOffRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other);113static bool determinedBySpeed(NBEdge** potHighway, NBEdge** potRamp);114static bool determinedByLaneNumber(NBEdge** potHighway, NBEdge** potRamp);115116/** @brief Checks whether an on-/off-ramp can be bult here117*118* - none of the participating edges must be a macroscopic connector119* - ramp+highways together must have more lanes than the continuation120* - speeds must match the defined swells121* @param[in] potHighway The highway part to check122* @param[in] potRamp The ramp part to check123* @param[in] other The successor/predecessor edge124* @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway125* @param[in] maxRampSpeed The maximum speed limit a ramp must have for being a ramp126* @param[in] noramps Edges that shall not be treated as ramps127* @return Whether a ramp can be built here128*/129static bool fulfillsRampConstraints(NBEdge* potHighway, NBEdge* potRamp, NBEdge* other, double minHighwaySpeed, double maxRampSpeed,130const std::set<std::string>& noramps);131132133/** @brief Moves the ramp to the right, as new lanes were added134* @param[in] ramp The ramp to move135* @param[in] addedLanes The number of added lanes136*/137void moveRampRight(NBEdge* ramp, int addedLanes);138139/// @brief whether the edge has a mode that does not indicate a ramp edge140static bool hasWrongMode(NBEdge* edge);141142/// @brief shift ramp geometry to merge smoothly with the motorway143static void patchRampGeometry(NBEdge* potRamp, NBEdge* first, NBEdge* potHighway, bool onRamp);144145template <class T>146static std::string getUnusedID(const std::string& prefix, const T& objectCont) {147if (objectCont.retrieve(prefix) == nullptr) {148return prefix;149}150int i = 0;151std::string result = prefix + "#" + toString(i);152while (objectCont.retrieve(result) != nullptr) {153i++;154result = prefix + "#" + toString(i);155}156return result;157}158};159160161