Skip to content

Commit

Permalink
fix #14839
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed May 7, 2024
1 parent dbf34f2 commit b0a23d3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
16 changes: 15 additions & 1 deletion src/netbuild/NBAlgorithms_Ramps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
//#define DEBUG_RAMPS
#define DEBUGNODEID ""
#define DEBUGCOND(obj) ((obj != 0 && (obj)->getID() == DEBUGNODEID))
//#define DEBUGCOND(obj) true

// ===========================================================================
// static members
Expand All @@ -49,6 +50,9 @@ const std::string NBRampsComputer::ADDED_ON_RAMP_EDGE("-AddedOnRampEdge");
// ---------------------------------------------------------------------------
// NBRampsComputer
// ---------------------------------------------------------------------------

NBRampsComputer::NBRampsComputer() { }

void
NBRampsComputer::computeRamps(NBNetBuilder& nb, OptionsCont& oc, bool mayAddOrRemove) {
const bool guessAndAdd = oc.getBool("ramps.guess") && mayAddOrRemove;
Expand Down Expand Up @@ -250,12 +254,15 @@ NBRampsComputer::buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDist
NBNode* rn = new NBNode(newNodeID, curr->getGeometry().positionAtOffset(rampLength - currLength));
nc.insert(rn);
std::string name = curr->getID();
const double currShift = myShiftedEdges[curr];
if (!ec.splitAt(dc, curr, rn, newEdgeID, curr->getID(), curr->getNumLanes() + toAdd, curr->getNumLanes())) {
WRITE_WARNING("Could not build on-ramp for edge '" + curr->getID() + "' for unknown reason");
return;
}
//ec.retrieve(name)->invalidateConnections();
curr = ec.retrieve(newEdgeID);
// copy shift over
myShiftedEdges[curr] = currShift;
incremented.insert(curr);
last = curr;
moveRampRight(curr, toAdd);
Expand Down Expand Up @@ -356,11 +363,14 @@ NBRampsComputer::buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDis
NBNode* rn = new NBNode(newNodeID, pos);
nc.insert(rn);
std::string name = curr->getID();
const double currShift = myShiftedEdges[curr];
if (!ec.splitAt(dc, curr, rn, curr->getID(), newEdgeID, curr->getNumLanes(), curr->getNumLanes() + toAdd)) {
WRITE_WARNING("Could not build off-ramp for edge '" + curr->getID() + "' for unknown reason");
return;
}
curr = ec.retrieve(newEdgeID);
// copy shift over
myShiftedEdges[curr] = currShift;
incremented.insert(curr);
last = curr;
moveRampRight(curr, toAdd);
Expand Down Expand Up @@ -414,10 +424,14 @@ NBRampsComputer::moveRampRight(NBEdge* ramp, int addedLanes) {
}
try {
PositionVector g = ramp->getGeometry();
const double offset = (0.5 * addedLanes *
double offset = (0.5 * addedLanes *
(ramp->getLaneWidth() == NBEdge::UNSPECIFIED_WIDTH ? SUMO_const_laneWidth : ramp->getLaneWidth()));
if (myShiftedEdges.count(ramp) != 0) {
offset -= myShiftedEdges[ramp];
}
g.move2side(offset);
ramp->setGeometry(g);
myShiftedEdges[ramp] = offset;
} catch (InvalidArgument&) {
WRITE_WARNINGF(TL("For edge '%': could not compute shape."), ramp->getID());
}
Expand Down
14 changes: 10 additions & 4 deletions src/netbuild/NBAlgorithms_Ramps.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ class NBRampsComputer {
* @param[in, changed] nb The network builder which contains the current network representation
* @param[in] oc The options container
*/
static void computeRamps(NBNetBuilder& nb, OptionsCont& oc, bool mayAddOrRemove);
NBRampsComputer();

void computeRamps(NBNetBuilder& nb, OptionsCont& oc, bool mayAddOrRemove);

/// @brief suffix for newly generated on-ramp edges
static const std::string ADDED_ON_RAMP_EDGE;

private:

std::map<NBEdge*, double> myShiftedEdges;


/** @brief Determines whether the given node may be an on-ramp begin
* @param[in] cur The node to check
* @param[in] minHighwaySpeed The minimum speed limit a highway must have for being a highway
Expand Down Expand Up @@ -87,7 +93,7 @@ class NBRampsComputer {
* @param[in] dontSplit Whether no edges shall be split
* @param[in, filled] incremented The list of edges which lane number was already incremented
*/
static void buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes);
void buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes);


/** @brief Builds an off-ramp ending at the given node
Expand All @@ -99,7 +105,7 @@ class NBRampsComputer {
* @param[in] dontSplit Whether no edges shall be split
* @param[in, filled] incremented The list of edges which lane number was already incremented
*/
static void buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes,
void buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes,
const std::set<NBNode*, ComparatorIdLess>& potOnRamps);


Expand Down Expand Up @@ -129,7 +135,7 @@ class NBRampsComputer {
* @param[in] ramp The ramp to move
* @param[in] addedLanes The number of added lanes
*/
static void moveRampRight(NBEdge* ramp, int addedLanes);
void moveRampRight(NBEdge* ramp, int addedLanes);

/// @brief whether the edge has a mode that does not indicate a ramp edge
static bool hasWrongMode(NBEdge* edge);
Expand Down
4 changes: 3 additions & 1 deletion src/netbuild/NBNetBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ NBNetBuilder::compute(OptionsCont& oc, const std::set<std::string>& explicitTurn
PROGRESS_BEGIN_MESSAGE(TL("Guessing and setting on-/off-ramps"));
}
NBNodesEdgesSorter::sortNodesEdges(myNodeCont);
NBRampsComputer::computeRamps(*this, oc, mayAddOrRemove);
NBRampsComputer rc;
rc.computeRamps(*this, oc, mayAddOrRemove);

if (modifyRamps) {
PROGRESS_TIME_MESSAGE(before);
}
Expand Down

0 comments on commit b0a23d3

Please sign in to comment.