|
1 | | -# allocator: Optimally Allocate Geographically Distributed Tasks |
| 1 | +# allocator: Modern Geographic Task Allocation |
2 | 2 |
|
3 | 3 | [](https://pypi.python.org/pypi/allocator) |
4 | 4 | [](https://pepy.tech/project/allocator) |
5 | 5 | [](https://github.com/geosensing/allocator/actions/workflows/ci.yml) |
6 | 6 | [](https://geosensing.github.io/allocator/) |
7 | 7 |
|
8 | | -**Allocator v1.0** provides a modern, Pythonic API for geographic task allocation, clustering, and routing optimization. |
| 8 | +**Allocator v1.0** provides a modern, Pythonic API for geographic task allocation, clustering, and routing optimization. |
9 | 9 |
|
10 | | -How can we efficiently collect data from geographically distributed locations? Whether you're coordinating crowdsourced data collection, optimizing delivery routes, or planning field research, allocator provides the tools you need. |
| 10 | +> **📖 [Complete Documentation](https://geosensing.github.io/allocator/)** | **🚀 [Quick Start](https://geosensing.github.io/allocator/quickstart.html)** | **💡 [Examples](https://geosensing.github.io/allocator/examples/overview.html)** |
11 | 11 |
|
12 | | -## ✨ What's New in v1.0 |
| 12 | +## Key Features |
13 | 13 |
|
14 | | -- **🎯 Modern Python API** - Clean, intuitive interface with type hints |
15 | | -- **📦 Unified CLI** - Single command with subcommands (`allocator cluster`, `allocator route`, `allocator assign`) |
16 | | -- **🚀 Performance** - Optimized algorithms with NumPy and scikit-learn |
17 | | -- **📊 Rich Results** - Structured results with metadata and easy export |
18 | | -- **🔧 No Backward Compatibility** - Clean slate, standards-compliant design |
19 | | - |
20 | | -## Core Functionality |
21 | | - |
22 | | -**1. Clustering** 🎯 |
23 | | -Group geographic points into balanced clusters for task allocation. |
24 | | - |
25 | | -**2. Routing** 🛣️ |
26 | | -Find optimal paths through sets of locations (TSP solving). |
27 | | - |
28 | | -**3. Assignment** 📍 |
29 | | -Assign points to closest workers/centers with distance-based sorting. |
| 14 | +- **🎯 Clustering**: Group geographic points into balanced zones |
| 15 | +- **🛣️ Routing**: Find optimal paths through locations (TSP solving) |
| 16 | +- **📍 Assignment**: Connect points to closest workers/centers |
| 17 | +- **🚀 Performance**: Optimized algorithms with NumPy and scikit-learn |
| 18 | +- **📦 Modern API**: Clean Python interface + unified CLI |
30 | 19 |
|
31 | 20 | ## Quick Start |
32 | 21 |
|
33 | | -### Installation |
34 | | - |
35 | 22 | ```bash |
36 | 23 | pip install allocator |
37 | 24 | ``` |
38 | 25 |
|
39 | | -### Python API Example |
40 | | - |
41 | 26 | ```python |
42 | 27 | import allocator |
43 | 28 | import pandas as pd |
44 | 29 |
|
45 | | -# Load your geographic data |
46 | | -data = pd.DataFrame({ |
47 | | - 'longitude': [101.0, 101.1, 101.2, 101.3], |
48 | | - 'latitude': [13.0, 13.1, 13.2, 13.3], |
49 | | - 'location_id': ['A', 'B', 'C', 'D'] |
| 30 | +# Geographic locations |
| 31 | +locations = pd.DataFrame({ |
| 32 | + 'longitude': [100.5018, 100.5065, 100.5108], |
| 33 | + 'latitude': [13.7563, 13.7590, 13.7633] |
50 | 34 | }) |
51 | 35 |
|
52 | | -# Cluster locations into groups |
53 | | -result = allocator.cluster(data, n_clusters=2, method='kmeans') |
54 | | -print(f"Cluster labels: {result.labels}") |
55 | | -print(f"Centroids: {result.centroids}") |
| 36 | +# Group into zones |
| 37 | +clusters = allocator.cluster(locations, n_clusters=2) |
56 | 38 |
|
57 | | -# Find optimal route through locations |
58 | | -route = allocator.shortest_path(data, method='ortools') |
59 | | -print(f"Optimal route: {route.route}") |
60 | | -print(f"Total distance: {route.total_distance}") |
| 39 | +# Find optimal route |
| 40 | +route = allocator.shortest_path(locations) |
61 | 41 |
|
62 | | -# Assign points to closest centers |
| 42 | +# Assign to service centers |
63 | 43 | centers = pd.DataFrame({ |
64 | | - 'longitude': [101.05, 101.25], |
65 | | - 'latitude': [13.05, 13.25] |
| 44 | + 'longitude': [100.50, 100.52], |
| 45 | + 'latitude': [13.75, 13.77] |
66 | 46 | }) |
67 | | -assignments = allocator.assign_to_closest(data, centers) |
68 | | -print(assignments.data) |
69 | | -``` |
70 | | - |
71 | | -### CLI Example |
72 | | - |
73 | | -```bash |
74 | | -# Cluster geographic points |
75 | | -allocator cluster data.csv --clusters 3 --method kmeans --output clusters.csv |
76 | | - |
77 | | -# Find optimal route |
78 | | -allocator route locations.csv --method ortools --output route.csv |
79 | | - |
80 | | -# Assign points to centers |
81 | | -allocator assign points.csv centers.csv --output assignments.csv |
| 47 | +assignments = allocator.assign(locations, centers) |
82 | 48 | ``` |
83 | 49 |
|
84 | | -## Distance Metrics |
85 | | - |
86 | | -All functions support multiple distance calculation methods: |
87 | | - |
88 | | -- **euclidean** - Fast Euclidean distance (good for local areas) |
89 | | -- **haversine** - Great circle distance accounting for Earth's curvature |
90 | | -- **osrm** - Real road network distances via OSRM API |
91 | | -- **google** - Google Maps distance matrix (requires API key) |
92 | | - |
93 | | -## Algorithms |
94 | | - |
95 | | -**Clustering:** |
96 | | -- **K-means**: Fast, well-balanced clusters |
97 | | -- **KaHIP**: Graph partitioning for highly balanced clusters (requires external install) |
98 | | - |
99 | | -**Routing (TSP):** |
100 | | -- **OR-Tools**: Exact solutions for small problems, heuristics for larger ones |
101 | | -- **Christofides**: 1.5-approximation algorithm (requires external install) |
102 | | -- **OSRM**: Real-world routing via road networks |
103 | | -- **Google**: Google Maps Directions API |
104 | | - |
105 | | -## Data Format |
106 | | - |
107 | | -Input data must be pandas DataFrames or CSV files with these columns: |
108 | | - |
109 | | -- **longitude**: Geographic longitude (required) |
110 | | -- **latitude**: Geographic latitude (required) |
111 | | -- Additional columns are preserved in results |
112 | | - |
113 | | -## Examples and Use Cases |
114 | | - |
115 | | -- **Field Research**: Optimize survey routes for maximum efficiency |
116 | | -- **Delivery/Logistics**: Plan optimal delivery routes and territories |
117 | | -- **Crowdsourcing**: Assign tasks to workers based on geographic proximity |
118 | | -- **Emergency Response**: Allocate resources to incident locations |
119 | | -- **Urban Planning**: Analyze spatial patterns and optimize service locations |
120 | | - |
121 | | -## API Reference |
122 | | - |
123 | | -### Main Functions |
124 | | - |
125 | | -```python |
126 | | -# High-level functions |
127 | | -allocator.cluster(data, n_clusters=3, method='kmeans', distance='euclidean') |
128 | | -allocator.shortest_path(data, method='ortools', distance='euclidean') |
129 | | -allocator.assign_to_closest(points, workers, distance='euclidean') |
130 | | - |
131 | | -# Specific algorithms |
132 | | -allocator.kmeans(data, n_clusters=3, distance='euclidean') |
133 | | -allocator.kahip(data, n_clusters=3) # Requires KaHIP installation |
134 | | -allocator.tsp_ortools(data, distance='euclidean') |
135 | | -allocator.tsp_christofides(data) # Requires Christofides installation |
136 | | -``` |
137 | | - |
138 | | -### Result Types |
139 | | - |
140 | | -- `ClusterResult`: Labels, centroids, convergence info, metadata |
141 | | -- `RouteResult`: Route order, total distance, metadata |
142 | | -- `SortResult`: Sorted assignments with distances, metadata |
143 | | - |
144 | | -## Requirements |
145 | | - |
146 | | -- Python 3.11+ |
147 | | -- Core: pandas, numpy, matplotlib, networkx, scikit-learn |
148 | | -- CLI: click, rich |
149 | | -- Optional: ortools, googlemaps, requests (for OSRM) |
150 | | - |
151 | | -## Documentation |
152 | | - |
153 | | -Complete documentation: https://geosensing.github.io/allocator/ |
154 | | - |
155 | | -## Development |
156 | | - |
157 | | -This project uses modern Python development practices: |
158 | | - |
159 | | -- **uv** for dependency management |
160 | | -- **pytest** for testing |
161 | | -- **black** and **isort** for code formatting |
162 | | -- **ruff** for linting |
163 | | -- **GitHub Actions** for CI/CD |
164 | | - |
165 | | -## Contributing |
166 | | - |
167 | | -We welcome contributions! Please see our [Contributor Code of Conduct](http://contributor-covenant.org/version/1/0/0/). |
168 | | - |
169 | | -## Authors |
| 50 | +## Documentation & Examples |
170 | 51 |
|
171 | | -Suriyan Laohaprapanon and Gaurav Sood |
| 52 | +- **📖 [Full Documentation](https://geosensing.github.io/allocator/)** |
| 53 | +- **🚀 [Installation & Tutorial](https://geosensing.github.io/allocator/quickstart.html)** |
| 54 | +- **🔧 [API Reference](https://geosensing.github.io/allocator/api/clustering.html)** |
| 55 | +- **💡 [Real-World Examples](https://geosensing.github.io/allocator/examples/overview.html)** |
172 | 56 |
|
173 | | -## License |
| 57 | +## License & Contributing |
174 | 58 |
|
175 | | -MIT License - see [LICENSE](https://opensource.org/licenses/MIT) for details. |
| 59 | +MIT License. Contributions welcome - see [Contributing Guide](https://geosensing.github.io/allocator/contributing.html). |
0 commit comments