Re-plan a shift without us storing the shift
A dispatch day drifts. Two drops land, a customer cancels, an urgent job arrives, a van breaks down, and the morning plan is fiction by eleven. POST /optimise/replan re-plans what is left without disturbing what has already happened, and it does it while MapMap holds no dispatch state at all: no plan, no vehicle position, no completion log, nothing that records where a named driver was at a named time. You send the day back to us on each request.
Why not keep the plan on the server?
Because the obvious design has a cost that nobody quotes you. Keep the plan server-side, hand back a request_id, take deltas against it, and you have created an object that can go stale, can leak, can be subpoenaed and can fall out of step with the telematics platform that actually owns the truth. Every one of those is a problem you then own forever.
So there is no id to quote back at us. A re-plan carries the day's POST /optimise body plus what has been done and what has changed. That costs you bandwidth. What it buys is that a re-plan is reproducible, because the same body always reduces to the same problem, and that there is nothing on our side to go wrong. POST /route/progress set the precedent: a live position is computed and thrown away, never written, so progress and an ETA are available without any vehicle position ever being stored.
What goes in the request?
The day's POST /optimise body plus two fields. At least one progress entry or one change is required; without either this is POST /optimise with more typing, and you get a 400 saying so.
One thing follows from holding no state: a re-plan has no clock. progress says which stops are done and where a vehicle is, not what time it is or how long anyone has driven. Time windows are solved from the start of each vehicle's time_window, and max_tasks, max_travel_time, breaks and capacity apply to the remaining route as written. So send what each vehicle has left: a time_window that starts now, and limits and capacity reduced by what has been used. replan.notes names every such field a request carries.
| Field | Shape | Meaning |
|---|---|---|
progress[] | {vehicle, completed_stop_ids[], current_position{lat,lon}, unavailable} | One entry per vehicle that has done something, with the completed ids in the order they were served |
changes.cancel_job_ids[] | job ids | Work that no longer needs doing |
changes.add_jobs[] | jobs[] objects | New single-stop work, in the shape /optimise already takes |
changes.add_shipments[] | shipments[] objects | New pickup and delivery pairs, likewise |
A worked case: the morning plan was two vans out of a London depot with three drops. By 11:00 van 1 has served jobs 10 and 11 and is sitting in Manchester, job 12 has been cancelled, and job 20 has just come in for York.
curl -fsS -X POST "https://api.mapmap.ai/optimise/replan" \
-H "Authorization: Bearer $MAPMAP_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"vehicles": [
{"id": 1, "start": {"lat": 51.5074, "lon": -0.1278},
"end": {"lat": 51.5074, "lon": -0.1278}},
{"id": 2, "start": {"lat": 52.4862, "lon": -1.8904}}
],
"jobs": [
{"id": 10, "location": {"lat": 52.4862, "lon": -1.8904}, "service_s": 300},
{"id": 11, "location": {"lat": 53.4808, "lon": -2.2426}, "service_s": 300},
{"id": 12, "location": {"lat": 53.8008, "lon": -1.5491}, "service_s": 300}
],
"costing": "auto",
"progress": [
{"vehicle": 1, "completed_stop_ids": [10, 11],
"current_position": {"lat": 53.4808, "lon": -2.2426}}
],
"changes": {
"cancel_job_ids": [12],
"add_jobs": [{"id": 20, "location": {"lat": 53.9599, "lon": -1.0873}, "service_s": 600}]
}
}'
Van 1 re-plans from Manchester, not from the depot.
What does "locked" actually mean?
It means the completed stops are not in the problem, so no solver can move them. The guarantee is by construction rather than by asking the solver nicely:
- every completed task is removed from the problem, because a stop already served is not work anybody may schedule again;
- each reporting vehicle's
startbecomes itscurrent_position, or the location of its last completed stop if you sent no position; - what is left is solved through exactly the
/optimisepipeline; - the prefix that was locked is reported back per vehicle.
VROOM does have a per-vehicle steps array and it is tempting to read that as forced steps. It is not a prefix lock. Its own documentation gives it two meanings: plan mode, where the steps describe the whole route and nothing is optimised, and ordinary solving, where they are a search starting point the solver is free to tear up. Neither pins a prefix and optimises the tail, so we do not pretend otherwise.
The consequence is visible in the response. routes[] covers the remaining work only, and the locked prefix appears in replan.locked_stops_per_vehicle rather than being re-emitted as route steps, because those arrival times already happened and inventing them would be worse than omitting them.
"replan": {
"mechanism": "locked-prefix elision",
"locked_stops_per_vehicle": [
{ "vehicle": 1, "stops": [10, 11], "unavailable": false,
"start_basis": "current_position",
"start_from": { "lat": 53.4808, "lon": -2.2426 } }
],
"released_stops": [],
"changes_applied": {
"cancelled_jobs": [12], "added_jobs": [20],
"added_shipments": [], "vehicles_unavailable": [], "completed_stops": 2
},
"notes": []
}
Jobs 10 and 11 are neither in routes[] nor in unassigned. They are done, and stops: [10, 11] is the receipt.
What does it cost to re-plan?
The ordinary /optimise formula applied to the remaining problem, not to the morning plan you had to resend. Ten units of its price class per started 2,500-pair block of internal matrix, with a floor of one block. Locked prefixes are not re-solved, so they are not billed: a 200-stop day with 150 stops done is billed as the 50-stop problem it is. If every stop is complete you get a valid answer with an empty routes[], and no engine work is commissioned at all.
What it will not do
It will not pretend an instruction was carried out. replan.notes[] names every one that could not be. Cancelling a job that has already been served says so, in as many words: a cancellation cannot un-drive a stop. Cancelling an id that is not in the problem says so. A completed_stop_ids entry that matches nothing says so, and is not counted as locked.
Two cases are hard errors rather than notes, because only you can resolve them: two vehicles claiming the same stop is a 400, and an add_jobs id that is already a task in the problem is a 400, since a re-plan addresses stops by id and duplicates would make every later completed_stop_ids ambiguous.
Multi-trip rounds are refused outright. A vehicle carrying reloads, the tipping round that returns to a depot, reloads and goes back out, is a 400 here. A completion in progress does not say which trip it belongs to, so re-planning one would have to guess. Send the outstanding work to POST /optimise with the trips and shift the fleet has left.
The 200-location cap still applies, counted on the remaining problem. Beyond that, POST /v1/jobs/replan takes the same body on the asynchronous lane at 2,000 remaining locations, with the same metering and the same full refund on failure.
Try it
Re-planning composes with the other two things a fleet with fixed rounds asks for on day one. territories confines a vehicle to the rounds its driver already knows, as a hard solver constraint rather than a preference, and it changes nothing about what a request bills. POST /v1/cluster groups a day too big for one optimisation into balanced rounds that each fit, at one call per started block of 100 locations. Both are documented in the optimisation guide, the request and response shapes are in the re-planning reference, and the same surface reaches agents through the MCP server as replan_routes and cluster.
