Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: pathfinding: fix pathfinding class to handle overlapping points #10512

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion core/src/main/kotlin/fr/sncf/osrd/graph/Pathfinding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,21 @@ class Pathfinding<NodeT : Any, EdgeT : Any, OffsetType>(
}
val stepTargets = ArrayList(step.targets)
stepTargets.add(target)

// Handle overlapping consecutive waypoints
var newNReachedTargets = step.nReachedTargets + 1
while (
newNReachedTargets < targetsOnEdges.size &&
targetsOnEdges[newNReachedTargets]
.apply(step.range.edge)
.contains(EdgeLocation(step.range.edge, step.range.end))
) newNReachedTargets++

registerStep(
newRange,
step.prev,
step.totalDistance,
step.nReachedTargets + 1,
newNReachedTargets,
stepTargets
)
}
Expand Down
23 changes: 23 additions & 0 deletions core/src/test/java/fr/sncf/osrd/utils/graph/PathfindingTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ class PathfindingTests {
Assertions.assertEquals(listOf("0-1", "1-3", "3-4"), resIDs)
}

@Test
fun overlappingWaypoints() {
val builder = SimpleGraphBuilder()
builder.makeNodes(7)
builder.makeEdge(0, 1, 10.meters)
builder.makeEdge(1, 2, 10.meters)
builder.makeEdge(2, 3, 10.meters)
val g = builder.build()
val res =
Pathfinding(g)
.setEdgeToLength { edge -> edge.length }
.runPathfindingEdgesOnly(
listOf(
listOf(builder.getEdgeLocation("0-1", 10.meters)),
listOf(builder.getEdgeLocation("1-2", 10.meters)),
listOf(builder.getEdgeLocation("1-2", 10.meters)),
listOf(builder.getEdgeLocation("2-3", 1.meters)),
)
)
val resIDs = res!!.map { x -> x.label }
Assertions.assertEquals(listOf("0-1", "1-2", "2-3"), resIDs)
}

@Test
fun severalStartsTest() {
/* Bottom path has more edges but is shorter
Expand Down
Loading