SPB Git

Repository Public BSD-3-Clause

README.md 11.6 KB 182 lines markdown

1# routing-builder (`orix-routing-build`)23Build-time tool (macOS only, never linked into the app): turns an OpenStreetMap `.osm.pbf` extract into one routing4graph file (`routing.orixgraph`) for `Packages/ORIXRouting`, and lets a person check routes from the command line.56- `ORIXRoutingBuildKit` (library): `TagInterpreter` (OSM tags → routing attributes), `GraphExtractor` (PBF → graph),7  `BenchmarkPlaces` (fixed origin–destination list).8- `orix-routing-build` (executable): `build`, `info`, `route`, `bench`.9- Depends on `Packages/ORIXRouting` (format writer and engine), `Packages/ORIXGeoCore`, `Infrastructure/ingestion/ORIXOSM`10  (the PBF reader). No third-party code.1112The file format is specified in `Packages/ORIXRouting/docs/ORIXGRAPH_FORMAT.md`; this package does not write bytes13itself, it feeds `RoutingGraphWriter`.1415## Commands1617```sh18cd Infrastructure/routing-builder19swift build -c release20B=.build/release/orix-routing-build21D=../../data2223# Build a graph (output under data/build/ only).24$B --pbf $D/quebec-latest.osm.pbf --region ca-qc --out $D/build/routing/quebec.orixgraph \25   [--bbox minLon,minLat,maxLon,maxLat] [--simplify 0.5] [--report $D/build/routing/quebec.report.json]2627# Metadata, counts, component sizes, builder counters; also times the full validation.28$B info --graph $D/build/routing/quebec.orixgraph2930# One route with its instructions (English or French), for checking by hand.31$B route --graph $D/build/routing/quebec.orixgraph --from 45.5048,-73.5772 --to 46.8087,-71.2140 \32   [--via lat,lon]… [--mode car|bicycle|pedestrian] [--avoid tolls,ferries,motorways,unpaved] [--alternatives 0…2] \33   [--lang en|fr] [--units metric|imperial] [--heading degrees] [--snap metres] [--dijkstra] \34   [--geojson $D/build/routing/route.geojson] [--json $D/build/routing/route.json]3536# Fixed list of origin–destination pairs per mode: distance, duration, compute time (median and best of n), settled37# states, search memory; --verify recomputes each pair with Dijkstra and exits with status 3 on any cost difference.38$B bench --graph $D/build/routing/montreal.orixgraph --set montreal [--modes car,bicycle,pedestrian] [--verify] [--repeat 5]39$B bench --graph $D/build/routing/quebec.orixgraph   --set province --verify --repeat 540```4142Example (`route --lang fr`, Plateau → Marché Jean-Talon by car, Montréal graph):4344```45route: 4,1 km (4.1 km), 11 min, cost 635 s, 126 points46  1. Dirigez-vous vers le sud-ouest sur l'avenue du Mont-Royal Est  [20 m]47  2. Tournez à droite sur la rue Rivard  [450 m]48  3. Tournez à gauche sur le boulevard Saint-Joseph Est  [600 m]49  4. Tournez à droite sur le boulevard Saint-Laurent  [2,5 km]50  5. Tournez à droite sur la rue Jean-Talon Est  [350 m]51  6. Tournez à droite sur l'avenue Henri-Julien  [150 m]52  7. Tournez à droite  [10 m]53  8. Vous êtes arrivé à destination, à votre droite54```5556## How the graph is built5758Two passes over the PBF with `OSMPBFReader`:59601. **Ways and relations.** Routable ways are kept with their node references; `type=restriction` relations are parsed.612. **Nodes.** Only the nodes referenced by routable ways are kept (coordinates in E7, barrier and signal tags): in the62   province 9.7 M of 139 M nodes. Node ids are mapped to dense indices through one sorted array (merge join with the63   file order), not a dictionary.6465Then: a node becomes a **graph node** when it is used by two ways (or twice by one), ends a way, carries a barrier66that blocks some mode, or is the via node of a restriction; ways are cut into edges at graph nodes; a loop that67returns to its own start is cut in two (no edge has the same node at both ends); intermediate points are simplified68(Douglas–Peucker, 0.5 m by default, `--simplify 0` keeps every point); restrictions are attached to the edges of69their from / to ways at the via node; the writer computes lengths, bearings, components, the spatial index and70renumbers everything along a Morton curve.7172With `--bbox`, only segments whose two ends are inside the box are kept and the box becomes the coverage of the graph.73Without it the coverage is the bounding box of the PBF header, or the extent of the data when the header has none.7475### Tag rules (`TagInterpreter`, unit-tested)7677- **Routable**: `highway` = motorway, trunk, primary, secondary, tertiary (and `_link`), unclassified, residential,78  living_street, service, track, pedestrian, footway, path, bridleway, cycleway, steps, road; and `route=ferry`.79  Everything else is dropped, including `construction`, `proposed`, `platform`, `corridor`, `bus_guideway`, `raceway`,80  and any way tagged `ice_road=yes` or `winter_road=yes`.81- **Default access**: motorway = cars only (also with `motorroad=yes`); footway and steps = pedestrians; path =82  pedestrians and bicycles (bridleway: pedestrians); cycleway and pedestrian streets = bicycles and pedestrians;83  other roads, tracks and ferries = everybody.84- **Access tags**, most specific first: car `motorcar` > `motor_vehicle` > `vehicle` > `access`; bicycle `bicycle` >85  `vehicle` > `access`; pedestrian `foot` > `access`. `no`-like values close; `private`, `destination`, `customers`,86  `delivery`, `permit`, `residents` keep the way routable with the *restricted* flag of the mode; `agricultural`,87  `forestry`, `psv`… close it to cars. A generic `access=yes` never opens a class to a mode it excludes by nature, and88  `vehicle=yes` never lets a car on foot or cycle infrastructure.89- **One-way**: `oneway=yes|-1|no`, implied by `junction=roundabout|circular` and by `highway=motorway`;90  `reversible` / `alternating` closes the way to cars. Bicycles follow the same rule unless `oneway:bicycle=no`,91  `cycleway*=opposite*` or `cycleway:*:oneway=-1` (contraflow); `oneway:bicycle=yes|-1` is honoured. Pedestrians ignore one-ways.92- **Speed**: `maxspeed` as an explicit number in km/h, mph or knots between 5 and 150 km/h; anything else ("signals",93  zones, "none") leaves the speed *assumed*. Ferries: speed = mapped length ÷ `duration`, accepted between 2 and 80 km/h.94- **Surface**: paved / unpaved lists from `surface`, else `tracktype` (grade1 = paved), else unpaved for tracks,95  else unknown.96- **Flags**: `toll`, `tunnel`, `bridge`, roundabout, link, cycle lane or track, minor service roads97  (`driveway`, `parking_aisle`, `drive-through`, `emergency_access`).98- **Nodes**: `highway=traffic_signals` (on a graph node, or flagged on the edge when it is an intermediate point);99  `barrier=*`: cars pass gates, lift gates, cattle grids, toll booths, border controls, kerbs and a few others100  unless `locked=yes`, and are blocked by everything else (bollards, blocks…); bicycles are blocked by stiles,101  turnstiles, jersey barriers and walls / fences / hedges; pedestrians by walls / fences / hedges. Access tags on the102  node override (`no` closes, `yes` opens; `private` and `destination` do not close).103- **Turn restrictions** with a via node: `no_left_turn`, `no_right_turn`, `no_straight_on`, `no_u_turn`, `no_entry`,104  `no_exit`, `only_left_turn`, `only_right_turn`, `only_straight_on`, `only_u_turn`. They apply to cars and bicycles;105  `except=` removes modes; `restriction:motorcar` / `:motor_vehicle` (car), `restriction:vehicle` (both),106  `restriction:bicycle` and the `type=restriction:<vehicle>` form are understood; restrictions for other vehicles107  (hgv, bus…) are ignored.108109Everything that is skipped is counted in the report and in the metadata of the file (`buildCounters`), never silently:110111| Counter (province build, 2026-11-25) | Value |112|---|---:|113| `restrictionRelations` (supported form, via node) | 12 967 |114| `restrictionsApplied` → `restrictionRecords` | 12 699 |115| `restrictionsOutsideGraph` (a member way is not routable or not in the extract) | 246 |116| `restrictionsAmbiguousSkipped` (the from or to way does not end at the via node) | 22 |117| `restrictionsViaWaySkipped` (**via way: not supported**) | 2 884 |118| `restrictionsConditionalIgnored` | 757 |119| `restrictionsInvalid` (missing members, unknown value) | 294 |120| `restrictionsOtherVehiclesIgnored` | 1 |121| `ferryWays` / `ferryWaysWithDuration` / `ferryDurationsRejected` | 100 / 29 / 4 |122| `routableWays` / `waysWithMaxspeed` | 1 252 493 / 161 925 |123| `shapePoints` kept / `shapePointsDropped` by the 0.5 m simplification | 5 685 853 / 2 133 132 |124125## Measured numbers126127Mac with 18 cores and 48 GB, macOS 27.0, Swift 6.4.2, release build, 2026-11-25, other jobs running on the machine.128Command: `/usr/bin/time -l $B --pbf <extract> --region <id> --out <file>`.129130| Extract | Size | Wall time | Peak resident memory | Peak memory footprint | Output |131|---|---:|---:|---:|---:|---:|132| `data/quebec-city.osm.pbf` | 22 MB | 0.46 s | 219.6 MB | 113.0 MB | 10.2 MB, 144 333 edges |133| `data/montreal.osm.pbf` | 97 MB | 4.60 s | 1 038 MB | 716 MB | 91.0 MB, 1 395 361 edges |134| `data/quebec-latest.osm.pbf` | 1 169 MB | 12.64 s | 2 994 MB | 1 413 MB | 184.6 MB, 2 467 372 edges |135136Province, by phase: pass 1 (ways, relations) 3.7 s, pass 2 (nodes) 4.2 s, graph construction 1.7 s, serialization137(components, spatial index, sections) 1.8 s. Other runs of the same build on the same day took 10.4 s and 15.7 s138depending on the load of the machine. The resident peak includes the memory-mapped PBF pages and the blocks decoded139in parallel by the reader; the footprint is the builder's own memory.140141File sizes, bytes per edge, routing times and the plausibility checks are in `Packages/ORIXRouting/README.md`.142143The Montréal and Québec City extracts carry no replication timestamp in their header: their graphs have no144`osmTimestamp` (shown as "unknown"). The province extract gives 2026-11-24T21:21:23Z.145146## Tests147148```sh149cd Infrastructure/routing-builder150swift test        # 11 tests151```152153Result on 2026-11-25: **11 passed, 0 failed**.154155- `TagInterpreterTests` (7): classes and default access, access hierarchy, one-ways and contraflow, attributes156  (`maxspeed`, surface, flags), ferries and durations, barriers and signals, restriction relations (each value,157  `except`, vehicle-specific forms, conditional, via way, broken relations).158- `ExtractorTests` (4): end to end on the Monaco extract that `ORIXOSM` ships as a test fixture (read in place):159  the graph passes full validation, every restriction relation is applied or counted, no edge has the same node at160  both ends, routes Casino → Palace for the three modes with A* = Dijkstra, builds are byte-for-byte deterministic for161  a fixed build date, simplification only removes shape points, `--bbox` clipping. The suite is skipped when the162  fixture is missing.163164## Known limits165166- The whole graph is assembled in memory before it is written (3 GB resident for the province). A country-sized167  extract would need a streaming writer.168- No incremental build: any change in the extract means a full rebuild (13 s for the province).169- Ways are followed as mapped: areas (`highway=pedestrian` + `area=yes`) are routed along their outline only.170- Places of the benchmark are landmarks typed by hand, not geocoded; they only need to be within 500 m of a road.171- `ORIXOSM` entities (`OSMNode`, `OSMWay`, `OSMRelation`) have no public initializer, so tests cannot build them;172  the restriction parser therefore also accepts plain tags and members (`TagInterpreter.interpret(restrictionID:tags:members:)`).173174## Not done175176- Via-way restrictions, conditional restrictions, direction-specific access and speed tags, seasonal closures,177  `destination` / exit numbers of motorway junctions, mini-roundabouts, lanes.178- Elevation: nothing is read (there is no elevation source in the project yet).179- No urban / rural classification for assumed speeds.180- No integration with the region package builder (`Infrastructure/package-builder`): this tool only writes the181  `.orixgraph` file; naming it `routing.orixgraph` inside a package and checksumming it belong to that tool.182
Files main
Menu

Theme