Skip to content

Commit

Permalink
core: fix typo in initFixedPoints, with unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi Charpentier <[email protected]>
  • Loading branch information
eckter committed Jan 23, 2025
1 parent fff6686 commit 5bd1d85
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private fun initFixedPoints(
val engineeringAllowanceStart = prevEdgeLength - engineeringAllowanceLength
// Edges can have overlapping engineering allowance, only the last one is relevant.
// So we remove any point in the current allowance range.
res.removeIf { it.offset.distance > engineeringAllowanceStart && it.stopTime != null }
res.removeIf { it.offset.distance > engineeringAllowanceStart && it.stopTime == null }

addFixedPointAvoidingDuplicates(prevEdgeLength)
addFixedPointAvoidingDuplicates(engineeringAllowanceStart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,58 @@ class EngineeringAllowanceTests {
Assertions.assertNull(res)
}

@Test
fun testOverwrittenEngineeringAllowance() {
/*
a --> b --> c --> d --> e --> f
space
^ end
f |###################### /
|#################x####/
e |############# _/ /
|#############_/ __/
d | _/ __/
| _/ __/
c | _/__/
| _/_/
b | _/
| /#######################
a |_/_#######################> time
First engineering allowance to avoid the conflict at d->e,
which is then overwritten by the allowance to avoid the
conflict at e->f
*/
val infra = DummyInfra()
val blocks =
listOf(
infra.addBlock("a", "b", 1000.meters),
infra.addBlock("b", "c", 50_000.meters),
infra.addBlock("c", "d", 20_000.meters),
infra.addBlock("d", "e", 1000.meters),
infra.addBlock("e", "f", 1000.meters),
)
val occupancyGraph =
ImmutableMultimap.of(
blocks[0],
OccupancySegment(600.0, Double.POSITIVE_INFINITY, 0.meters, 1000.meters),
blocks[3],
OccupancySegment(0.0, 2900.0, 0.meters, 1000.meters),
blocks[4],
OccupancySegment(0.0, 3000.0, 0.meters, 1000.meters),
)
STDCMPathfindingBuilder()
.setInfra(infra.fullInfra())
.setStartLocations(setOf(EdgeLocation(blocks[0], Offset(0.meters))))
.setEndLocations(setOf(EdgeLocation(blocks[4], Offset(1000.meters))))
.setUnavailableTimes(occupancyGraph)
.setMaxDepartureDelay(Double.POSITIVE_INFINITY)
.setMaxRunTime(Double.POSITIVE_INFINITY)
.run()!!
}

/** Test that we return the fastest path even if there are some engineering allowances */
@Test
fun testReturnTheFastestPathWithAllowance() {
Expand Down

0 comments on commit 5bd1d85

Please sign in to comment.