Skip to content

Repository files navigation

allocator

PyPI versionDownloadsCIDocumentation

Field teams, delivery services, and survey organizations waste time and money on inefficient routes. When you have 100+ locations to visit, manual planning fails. Allocator solves this.

What It Does

  • Cluster: Divide locations into balanced work zones
  • Route: Find the shortest path through locations (TSP)
  • Assign: Match locations to nearest workers or depots
  • Random Walk: Generate survey itineraries on road networks
  • Distance Matrix: Calculate travel times/distances via OSRM or Google Routes API

Install

pip install allocator

Python API

Cluster locations into zones

importallocatorimportpandasaspdlocations=pd.DataFrame({
'longitude': [100.501, 100.506, 100.510, 100.515, 100.520],
'latitude': [13.756, 13.759, 13.763, 13.768, 13.772]
})
result=allocator.cluster(locations, n_clusters=2)
print(result.labels) # [0 0 0 1 1]

Find shortest route

route=allocator.shortest_path(locations, method='ortools')
print(route.route) # [0, 1, 2, 4, 3, 0]

Assign to nearest depot

depots=pd.DataFrame({
'longitude': [100.50, 100.52],
'latitude': [13.75, 13.77]
})
assignments=allocator.assign_to_closest(locations, depots)
print(assignments.data['assigned_worker'].tolist()) # [0, 0, 1, 1, 1]

Generate random walk itineraries

importnetworkxasnx# Load road network graph (from OSMnx or similar)G=nx.read_graphml("road_network.graphml")
result=allocator.random_walk(G, n_walks=10, walk_length_m=5000)
print(result.data) # DataFrame with waypoints

Calculate distance matrix

fromallocator.distancesimportget_distance_matriximportnumpyasnppoints=np.array([
[-122.4194, 37.7749], # SF downtown
[-122.4089, 37.7855], # North Beach
])
# Local calculation (fast, no API)dist=get_distance_matrix(points, method="haversine")
# OSRM (free, real driving times)dist=get_distance_matrix(points, method="osrm")
# Google Routes API (requires service account)dist=get_distance_matrix(
points,
method="google_routes",
credentials_file="/path/to/service-account.json"
)

CLI

allocator cluster kmeans locations.csv -n 5 -o zones.csv
allocator route tsp locations.csv --method ortools -o route.csv
allocator sort locations.csv --workers depots.csv -o assignments.csv
allocator random-walk road_network.graphml -n 10 -l 5000 -o waypoints.csv

Documentation

License

MIT

About

Efficiently collect data from geographically distributed locations

Topics

Resources

Stars

7 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages