fix(javaTest): align simulation time semantics

This commit is contained in:
zgw
2026-07-31 15:28:40 +08:00
parent c31153dc86
commit 8112e30691
5 changed files with 19 additions and 10 deletions

View File

@@ -100,7 +100,8 @@ public final class HistoricalDispatchSimulator {
events, traversedEdges);
verifyLedger(ledger, invariants);
boolean awaitingFutureArrival = active.isEmpty() && clearanceMoves.isEmpty()
boolean awaitingFutureArrival = queue.size() > 0
&& active.isEmpty() && clearanceMoves.isEmpty()
&& queue.readyAt(now).isEmpty();
if (watchdog.observe(terminal.size(),
businessProgress || clearanceProgress.moved || awaitingFutureArrival,
@@ -461,7 +462,7 @@ public final class HistoricalDispatchSimulator {
ResourceKey edge = ResourceKey.edge(from, to);
List<ResourceKey> resources = Arrays.asList(
ResourceKey.node(from), edge, ResourceKey.node(to));
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

@@ -27,15 +27,10 @@ public final class SimulationClock {
Collections.sort(ordered);
LinkedHashMap<LocalDateTime, Long> converted =
new LinkedHashMap<LocalDateTime, Long>();
long simulationMillis = 0L;
LocalDateTime previous = null;
LocalDateTime first = ordered.get(0);
for (LocalDateTime arrival : ordered) {
if (previous != null) {
long sourceGap = Duration.between(previous, arrival).toMillis();
simulationMillis += sourceGap / acceleration;
}
long simulationMillis = Duration.between(first, arrival).toMillis() / acceleration;
converted.put(arrival, simulationMillis);
previous = arrival;
}
this.arrivals = Collections.unmodifiableMap(converted);
}