fix(javaTest): preserve historical arrival timing

This commit is contained in:
zgw
2026-07-31 15:18:38 +08:00
parent 3a6e0102c7
commit c31153dc86
11 changed files with 4178 additions and 4171 deletions

View File

@@ -54,6 +54,8 @@ public final class HistoricalDispatchSimulationReportWriter {
.filter(cell -> cell.getValue() == 1 || cell.getValue() == 2).count());
value.put("fullMapSha256", dataset.getFullMapSha256());
value.put("plannerVersion", "GridPathPlanner-BFS/full-grid-v1");
value.put("arrivalTimingPolicy",
"create_date-relative-gap/acceleration-no-truncation");
value.put("pathInfoUsedForPlanning", false);
value.put("inputCount", result.getTaskResults().size());
value.put("acceleration", result.getAcceleration());

View File

@@ -100,8 +100,10 @@ public final class HistoricalDispatchSimulator {
events, traversedEdges);
verifyLedger(ledger, invariants);
boolean awaitingFutureArrival = active.isEmpty() && clearanceMoves.isEmpty()
&& queue.readyAt(now).isEmpty();
if (watchdog.observe(terminal.size(),
businessProgress || clearanceProgress.moved,
businessProgress || clearanceProgress.moved || awaitingFutureArrival,
clearanceProgress.completed)) {
invariants.deadlock();
throw new IllegalStateException("simulation made no physical progress at tick "
@@ -349,7 +351,7 @@ public final class HistoricalDispatchSimulator {
reservations, events);
continue;
}
Instant decisionTime = Instant.EPOCH.plusMillis(now + tick);
Instant decisionTime = Instant.EPOCH.plusMillis(now);
TrafficVehicleSnapshot frozen = new TrafficVehicleSnapshot(vehicleId,
Long.toString(vehicle.getBootId()), tick + 1, tick + 1,
decisionTime, from, to,

View File

@@ -10,7 +10,6 @@ import java.util.List;
import java.util.Map;
public final class SimulationClock {
private static final long MAX_SOURCE_GAP_MILLIS = 30L * 60L * 1000L;
private final int acceleration;
private final Map<LocalDateTime, Long> arrivals;
@@ -33,7 +32,7 @@ public final class SimulationClock {
for (LocalDateTime arrival : ordered) {
if (previous != null) {
long sourceGap = Duration.between(previous, arrival).toMillis();
simulationMillis += Math.min(sourceGap, MAX_SOURCE_GAP_MILLIS) / acceleration;
simulationMillis += sourceGap / acceleration;
}
converted.put(arrival, simulationMillis);
previous = arrival;

View File

@@ -48,6 +48,8 @@ class HistoricalDispatchSimulationReportWriterTest {
assertEquals(64, summary.path("fullMapSha256").asText().length());
assertEquals("GridPathPlanner-BFS/full-grid-v1",
summary.path("plannerVersion").asText());
assertEquals("create_date-relative-gap/acceleration-no-truncation",
summary.path("arrivalTimingPolicy").asText());
assertTrue(summary.has("pathInfoUsedForPlanning"));
assertEquals(false, summary.path("pathInfoUsedForPlanning").asBoolean(true));
assertEquals(result.getArchiveCount(), summary.path("archiveCount").asInt());

View File

@@ -10,18 +10,18 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class SimulationClockTest {
@Test
void scalesRelativeArrivalsAndCapsLongIdleGaps() {
void scalesEveryHistoricalArrivalGapWithoutTruncation() {
LocalDateTime base = LocalDateTime.of(2026, 3, 1, 10, 0);
LocalDateTime tenSecondsLater = base.plusSeconds(10);
LocalDateTime twoHoursLater = base.plusHours(2);
LocalDateTime afterCappedGap = twoHoursLater.plusSeconds(10);
LocalDateTime afterLongGap = twoHoursLater.plusSeconds(10);
SimulationClock clock = new SimulationClock(Arrays.asList(
base, tenSecondsLater, twoHoursLater, afterCappedGap), 100);
base, tenSecondsLater, twoHoursLater, afterLongGap), 100);
assertEquals(0L, clock.toSimulationMillis(base));
assertEquals(100L, clock.toSimulationMillis(tenSecondsLater));
assertEquals(18_100L, clock.toSimulationMillis(twoHoursLater));
assertEquals(18_200L, clock.toSimulationMillis(afterCappedGap));
assertEquals(72_000L, clock.toSimulationMillis(twoHoursLater));
assertEquals(72_100L, clock.toSimulationMillis(afterLongGap));
assertEquals(1_000L, clock.sourceDurationMillis(10L));
}