Route optimisation
Give us the stops and the riders; get back who goes where, in which order, and when they arrive.
On this page
A rider has twelve parcels for this afternoon; or three riders share forty. Route optimisation decides who takes which, in what order, for the least total time on the road, without overloading anyone.
Plan a batch
cURL
curl -X POST "https://nways.ng/maps/v1/routes/optimize?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"mode": "dispatch", "vehicles": [{"id": "bike-17", "start": {"lat": 6.5965, "lng": 3.3421}, "capacity": 8}], "stops": [{"id": "order-1", "location": {"lat": 6.6018, "lng": 3.3515}, "serviceS": 120}, {"id": "order-2", "location": {"lat": 6.6107, "lng": 3.3589}, "serviceS": 120}, {"id": "order-3", "location": {"lat": 6.5934, "lng": 3.3602}, "serviceS": 120}]}'JavaScript
import { createClient } from '@nways/maps'
const nways = createClient({ key: 'YOUR_API_KEY' })
const plan = await nways.optimize({
mode: 'dispatch',
vehicles: [{ id: 'bike-17', start: { lat: 6.5965, lng: 3.3421 }, capacity: 8 }],
stops: [
{ id: 'order-1', location: { lat: 6.6018, lng: 3.3515 }, serviceS: 120 },
{ id: 'order-2', location: { lat: 6.6107, lng: 3.3589 }, serviceS: 120 },
{ id: 'order-3', location: { lat: 6.5934, lng: 3.3602 }, serviceS: 120 },
],
})
for (const r of plan.routes) console.log(r.vehicle, r.stops.join(' → '), Math.round(r.durationS / 60), 'min')The request
| Field | Description |
|---|---|
stops | Required. 1 to 50, each with your id, its location (a point, { postcode }, { ghanaPost } or { plusCode }), its demand (room it takes, default 1) and serviceS (seconds spent there, up to 4 hours). |
vehicles | Required. 1 to 5, each with an id, a start, an optional end (else it ends at its last stop) and a capacity (0 for no limit). |
mode | drive (default), van, okada, keke and danfo (keeping to their bans, as Routes does), motorbike and dispatch (couriers’ bikes: only bans on every motorcycle apply), walk or bicycle. |
geometry | false to get the order and times only, without each vehicle’s route. |
lang | en or fr, for the routes’ instructions. |
The answer
routes: for each vehicle used, itsstopsin visiting order,arrivalsS(seconds from the start to each stop),durationS,distanceM,load, and itsroute(as from Routes), unlessgeometryisfalse.unassigned: stops no vehicle could take (over every capacity, or inside a ban area for the mode; those are also innotAllowed, with the ban).durationS: the whole plan’s driving and service time.
The answer is a good plan found in seconds, not a proven best one. Reference