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: stdcm: minor improvements #7807

Merged
merged 2 commits into from
Jun 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class STDCMPathfinding(
if (Duration.between(start, Instant.now()).toSeconds() >= pathfindingTimeout)
throw OSRDError(ErrorType.PathfindingTimeoutError)
val edge = queue.poll() ?: return null
if (edge.weight!!.isInfinite()) {
Erashin marked this conversation as resolved.
Show resolved Hide resolved
// TODO: filter with max running time, can't be done with abstract weight
return null
}
// TODO: we mostly reason in terms of endNode, we should probably change the queue.
val endNode = graph.getEdgeEnd(edge)
if (endNode.waypointIndex >= graph.steps.size - 1) {
Expand Down Expand Up @@ -204,9 +208,10 @@ class STDCMPathfinding(
step.locations
.filter { it.edge == edge.block }
.mapNotNull { edge.edgeOffsetFromBlock(it.offset) }
assert(locationOnEdge.size <= 1)
if (locationOnEdge.isNotEmpty()) {
res.add(EdgeLocation(edge, locationOnEdge.first()))
.minOrNull()
// Sometimes a step has several locations on the same edge, we just pick the first
bougue-pe marked this conversation as resolved.
Show resolved Hide resolved
if (locationOnEdge != null) {
Erashin marked this conversation as resolved.
Show resolved Hide resolved
res.add(EdgeLocation(edge, locationOnEdge))
nextStepIndex++
} else {
currentEdgeIndex++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,28 @@ class STDCMPathfindingTests {
.run()
assertNull(res)
}

/**
* This is mostly a malformed input, but it can happen on misplaced operational points. It's
* actually really hard to handle it *perfectly* but we should at least not crash.
*/
@Test
fun repeatedLocationsOnEdge() {
/*
a --> b --> c
*/
val infra = DummyInfra()
val firstBlock = infra.addBlock("a", "b")
val secondBlock = infra.addBlock("b", "c")
STDCMPathfindingBuilder()
.setInfra(infra.fullInfra())
.setStartLocations(
setOf(
EdgeLocation(firstBlock, Offset(0.meters)),
EdgeLocation(firstBlock, Offset(10.meters)),
)
)
.setEndLocations(setOf(EdgeLocation(secondBlock, Offset(50.meters))))
.run()!!
}
}
Loading