-
Notifications
You must be signed in to change notification settings - Fork 98
Description
Problem
Pandana builds a contraction hierarchy (CH) in the C++ backend when you create a Network. Only the graph is persisted: save_hdf5() saves nodes and edges, but not the CH. So every from_hdf5() rebuilds the contraction hierarchy from scratch, which can take a long time on large networks.
Proposed solution
Add the ability to save and load the precomputed CH so that reloading a network can skip the contraction step.
New/updated API:
network.save_ch(base_path)— write the CH to binary files (base_path_0.bin,base_path_1.bin, … for each impedance).Network.from_hdf5(filename, ch_path=base_path)— load the graph from HDF5 and, whench_pathis given, load the CH from those files instead of running contraction.
Example:
# After building a network once
network.save_hdf5("graph.h5")
network.save_ch("ch")
# Later: load without re-contracting
network = pandana.Network.from_hdf5("graph.h5", ch_path="ch")Optional extension: make Network picklable (__getstate__ / __setstate__) so the full network (graph + CH) can be serialized with pickle.dump / pickle.load.
Implementation notes
- CH lives in the C++ layer (
ContractionHierarchiesinlibch). The change addsSaveContractedEdges(path)andLoadPreprocessing(path)there, plus Python/Cython wiring and thesave_ch/from_hdf5(ch_path=)API. - Binary format: header (node count, edge count) plus one record per contracted edge (source, target, distance, direction flags, etc.). No version field in the format yet.
I have a working prototype (patch + tests + design doc) and can open a PR against dev if this direction fits the project. Happy to adjust the API or scope based on maintainer feedback.