Nearest warehouse and delivery zones
Each order should go out from the closest depot, and each van should get a fair share of stops. Both questions start from the same geocoded list.
New Places and zones Command line Logistics, field work Retail, e-commerce
What you have
The orders with addresses, and the depots with their points (a column of addresses works too).
order,address 1001,"233 S Wacker Dr, Chicago, IL 60606" 1002,"600 N Michigan Ave, Chicago, IL 60611" 1003,"200 E Randolph St, Chicago, IL 60601" 1004,"2100 S Halsted St, Chicago, IL 60608" 1005,"3600 N Clark St, Chicago, IL 60613" 1006,"1060 W Addison St, Chicago, IL 60613"
id,name,lat,lon D1,Depot North,41.9484,-87.6553 D2,Depot South,41.8517,-87.6466
Steps
1. Geocode the orders and give each the nearest depot:
$ gridpin nearest orders.csv depots.csv --sheet usa.bin -o near.csv 0 of 6 rows have no answer (0 without a point)
2. Read the result:
$ cat near.csv
order | gp_precision | nearest_id | nearest_distance_m |
|---|---|---|---|
| 1001 | house | D2 | 3126.5 |
| 1002 | house | D2 | 4924.2 |
| 1003 | house | D2 | 4273.1 |
| 1004 | near | D2 | 266.8 |
| 1005 | near | D1 | 183.4 |
| 1006 | house | D1 | 123.5 |
3. cluster reads columns named lat and lon, so rename the two answer columns first:
$ sed '1s/gp_lat/lat/;1s/gp_lon/lon/' near.csv > stops.csv
4. Split the stops into two zones of at most four stops:
$ gridpin cluster stops.csv --k 2 --max-size 4 -o zones.csv 6 points in 2 zones
$ cat zones.csv
order | nearest_id | gp_cluster | gp_cluster_size |
|---|---|---|---|
| 1001 | D2 | 1 | 4 |
| 1002 | D2 | 1 | 4 |
| 1003 | D2 | 1 | 4 |
| 1004 | D2 | 1 | 4 |
| 1005 | D1 | 2 | 2 |
| 1006 | D1 | 2 | 2 |
What you get
nearest_id and nearest_distance_m name the depot and how far it is in a straight line; gp_cluster is the zone, with its centre and size. --geojson zones.geojson also writes the outline of each zone for a map.
Why it works
nearest geocodes the rows that have no point and measures to every point of the second file. cluster groups points by distance (k-means from a fixed seed, so the same input gives the same zones) and moves stops out of a zone that is over --max-size.
Limits
- Distances are in a straight line, not by road: a river without a bridge is not seen.
- Zones are even in count, not in driving time.
- Rows answered only at
nearor street level are placed less precisely: checkgp_precisionbefore you plan a route.
All its keys: nearest, cluster. The functions: nearest and join, delivery zones.
More
- Field service: check the address, cut the rounds
- Your own place names: HQ, depot 3, store 117
- School enrolment: home address to zone
- Clinical trials: patients to sites, privately
- Find duplicate addresses in a customer list
- Where GridPin works and where it does not
- All guides and countries
- Documentation