Package: allocator
How can we efficiently collect data from geographically distributed locations? If the data
collection is being crowd-sourced, then we may want to exploit the fact that workers
are geographically distributed. One simple heuristic to do so is to order the locations by
distance for each worker (with some task registration backend). If you have hired
workers (or rented drones) who you can send to different locations, then you must split the tasks
across workers (drones), and plan the ‘shortest’ routes for each, ala the Traveling Salesman
Problem (TSP). This is a problem that companies like Fedex etc. solve all the time. Since there
are no computationally feasible solutions for solving for the global minimum, one heuristic solution
is to split the locations into clusters of points that are close to each other (ideally,
we want the clusters to be ‘balanced’), and then to estimate a TSP solution for each cluster.The package provides a simple way to implement these solutions. Broadly, it provides three kinds of functions:Sort by Distance:Produces an ordered list of workers for each point or an ordered list of pointsfor each worker.Cluster the Points:Clusters the points inton_workergroups.Shortest Path:Order points within a cluster (or any small number of points) into a path or itinerary.The package also provides access to three different kinds of distance functions for calculating the distance matrices
that underlie these functions:Euclidean Distance:use option-deuclidean; similar to the Haversine distance within the sameUTM zone)Haversine Distance:use option-dhaversine.OSRM Distance:use option-dosrm. Neither Haversine nor Euclidean distance take account of the actual road network or the traffic. To use actual travel time, useOpen Source Routing Machine APIA maximum number of 100 points can be passed to the function if we use the public server. However, you can set up your own private OSRM server with--max-table-sizeto specific the maximum number of points.Google Distance Matrix API:. use option-dgoogle. This option available insort_by_distaneandcluster_kahiponly due to Google Distance Matrix API has very usage limits. Please look at the limitationshere.Related PackageTo sample locations randomly on the streets, check outgeo_sampling.ApplicationMissing Women on the streets of Delhi. Seewomen countInstallpip install allocatorFunctionsSort By DistanceClusterCluster data collection locations using k-means (clustering) or KaHIP (graph partitioning). To check which of the algorithms produces more cohesive, balanced clusters,
runCompare K-means to KaHIPk-meansExamples:python -m allocator.cluster_kmeans -n 10 allocator/examples/chonburi-roads-1k.csv --plotKaHIP allocatorShortest PathThese function can be used find the estimated shortest path across all the locations in a cluster. We expose three different ways of getting the ‘shortest’ path, a) via MST (Christofides algorithm), b) via Google OR-Tools, b) Google Maps Directions API.Approximate TSP using MSTGoogle OR Tools TSP solver Shortest pathGoogle Maps Directions API Shortest pathOSRM Trip API Shortest pathDocumentationDocumentation available at:https://allocator.readthedocs.io/en/latest/AuthorsSuriyan Laohaprapanon and Gaurav SoodContributor Code of ConductThe project welcomes contributions from everyone! In fact, it depends on
it. To maintain this welcoming atmosphere, and to collaborate in a fun
and productive way, we expect contributors to the project to abide by
theContributor Code of
Conduct.LicenseThe package is released under theMIT
License.