Skip to content

Add balanced service area partitioning (#939)#943

Merged
brendancol merged 5 commits into
masterfrom
issue-939
Mar 4, 2026
Merged

Add balanced service area partitioning (#939)#943
brendancol merged 5 commits into
masterfrom
issue-939

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Adds balanced_allocation() which partitions a cost surface into territories of roughly equal cost-weighted area
  • Runs cost_distance per source, then iteratively adjusts additive biases until territory weights converge
  • All four backends work (NumPy, CuPy, Dask+NumPy, Dask+CuPy) -- the balancing loop is just argmin + masked sums on top of cost_distance, no custom kernels

Closes #939

What changed

  • xrspatial/balanced_allocation.py -- new module with the balanced_allocation function
  • xrspatial/__init__.py -- export
  • xrspatial/tests/test_balanced_allocation.py -- 12 tests (two/three/single/no sources, NaN barriers, asymmetric friction, target_values, validation errors)
  • docs/source/reference/proximity.rst -- API docs entry
  • examples/user_guide/15_Balanced_Allocation.ipynb -- user guide notebook
  • README.md -- feature matrix row

Test plan

  • pytest xrspatial/tests/test_balanced_allocation.py -k "not cupy" -- 12/12 pass
  • GPU tests (need CuPy environment)
  • Run the notebook end to end

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Mar 4, 2026
Per-source cost-distance with iterative bias adjustment to produce
territories of roughly equal cost-weighted area.
Covers two-source, three-source, single-source, no-source, NaN barrier,
asymmetric friction, target_values, and validation errors.
Covers standard vs balanced comparison, asymmetric friction,
three sources, tolerance tuning, and barriers.
@brendancol brendancol merged commit fc9d832 into master Mar 4, 2026
11 checks passed
@brendancol brendancol deleted the issue-939 branch May 4, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add balanced service area partitioning

1 participant