20 - Graph Algorithms Route Planning¶
This example demonstrates a more realistic SQL-first graph algorithm workflow in the Python bindings. It builds a small directed multi-modal transport network and compares several pathfinding strategies over the same graph:
shortestPath(...)for minimum-hop routingdijkstra(...)for optimizing different edge propertiesastar(...)for weighted routing with an options map
The workflow covers:
- creating a route graph with
Cityvertices andRoad,Rail, andFerryedges - comparing minimum-hop routing against weighted routing over
distance,duration, andrisk - showing that
shortestPath(...)ignores the edge weight property - showing that
dijkstra(...)picks different paths when the business objective changes - cross-checking
astar(...)againstdijkstra(...)for multiple weighted objectives - using
directionto constrain shortest-path traversal - using
sqlscriptvariables with both vertex values and@ridinputs - printing segment-level route summaries instead of just raw RID lists
- verifying disconnected destinations do not produce a valid route
- reopening the database and rerunning weighted and constrained queries
Run¶
From bindings/python/examples:
With a custom database path:
Notes¶
- The example stays SQL-first on purpose. It does not introduce a Python-native graph algorithms wrapper.
shortestPath(...)is unweighted. It minimizes hops, notdistance,duration, orrisk.dijkstra(...)andastar(...)are the right fit when edge weights matter.- The example uses an
astar(...)options map to show the SQL shape for heuristics, direction, and tie-breaking. - The same graph is reused for several routing questions so you can see how objective
selection changes the chosen route and how
astar(...)compares withdijkstra(...). - If the packaged runtime does not include the graph algorithm SQL functions, the script prints a short explanation and exits.
Why This Example Exists¶
The Python bindings already expose the graph algorithm SQL functions, and the bindings test suite already covers them. This example turns that low-level coverage into a richer route planning lab so the examples set includes a dedicated pathfinding example that goes beyond a single shortest-path query and demonstrates realistic routing tradeoffs.