Skip to content

Commit 5c8993c

Browse files
Copilotsteffenaxer
andauthored
Handle no-path edge case in routeCost export; add backwards-compat comment
Agent-Logs-Url: https://github.com/steffenaxer/matsim-libs/sessions/facab8bc-3da3-42ec-9057-355df02c7305 Co-authored-by: steffenaxer <26229392+steffenaxer@users.noreply.github.com>
1 parent 859e372 commit 5c8993c

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

matsim/src/main/java/org/matsim/core/router/speedy/CHQueryExporter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,14 @@ private static void exportJSON(SpeedyGraph graph, CHGraph chGraph, SpeedyALTData
273273
}
274274
pw.println(" ],");
275275

276-
// Route cost and link count
277-
pw.printf(Locale.US, " \"routeCost\": %.4f,%n", chResult.routeCost);
278-
pw.printf(" \"routeLinks\": %d,%n", chResult.pathLinks.size());
276+
// Route cost and link count (null when no path found)
277+
if (Double.isFinite(chResult.routeCost) && !chResult.pathLinks.isEmpty()) {
278+
pw.printf(Locale.US, " \"routeCost\": %.4f,%n", chResult.routeCost);
279+
pw.printf(" \"routeLinks\": %d,%n", chResult.pathLinks.size());
280+
} else {
281+
pw.println(" \"routeCost\": null,");
282+
pw.println(" \"routeLinks\": 0,");
283+
}
279284

280285
// Shortcut tree (for first CH edge only if available)
281286
pw.print(" \"shortcutTree\": ");

matsim/tools/ch-viz/ch-visualization.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ <h2>Search Space Comparison</h2>
10761076
document.getElementById('ch-total').textContent = chN.toLocaleString();
10771077
document.getElementById('ch-times').textContent = times;
10781078
// Route result info
1079+
// Route result info (routeLinks/routeCost added in latest exporter; fall back to pathLinks for older JSON)
10791080
const links = query.routeLinks ?? (query.pathLinks ? query.pathLinks.length : '-');
10801081
const cost = query.routeCost != null ? query.routeCost.toFixed(1) + 's' : '-';
10811082
document.getElementById('route-links').textContent = links.toLocaleString ? links.toLocaleString() : links;

0 commit comments

Comments
 (0)