How a Dispatcher Keeps Four Delivery Plans Open Until the Van Leaves
Route planning for a delivery van usually happens once, early, on the information there is at 07:30. Then the morning changes it. A late order comes in and a lane closes on the ring road; the ferry stops taking bookings at 08:20. A plan made at 07:30 doesn’t know any of that, and a planner that recomputes from scratch each time loses track of what it already ruled out and why.
examples/routing keeps four plans open as branches until the dispatcher locks one. Each plan carries the conditions it depends on, and the morning’s news goes to all of them at once. The numbers below are from its recorded output.
Each plan’s probability at each step, from the recorded run.
Four Plans, Each With What It Depends On
The day’s load goes on the trunk: 18 parcels, 640 kg. The planner forks four plans with starting weights of 0.35, 0.30, 0.20 and 0.15. Three use the big van, which takes 900 kg, and one uses the small electric van, which takes 700. Each van’s capacity is a constraint on the load:
s.Fork("small-van", mv.Trunk, 0.15)
s.Constrain("small-van", mv.AtMost("load_kg", 700))
The ring-road plan also needs the ring road open, and the city-centre plan needs the centre free of restrictions. The river-ferry plan has to be booked on the ferry by 08:20, so that’s its deadline.
The Morning’s News
At 07:45 a late order adds a 120 kg pallet. The load is the same whichever plan wins, so it goes in as a fact for every branch. The load is now 760 kg and the small van can’t carry it, so its plan dies.
At 07:55 a traffic report says a lane is closed at junction 4 with about 25 minutes of delay. The road is open, so the ring-road plan’s constraint holds, but it’s now less likely to be the fastest. The planner rates the report at 0.3 for the ring-road plan and 0.9 for the rest:
s.Observe(mv.Evidence{
Facts: []mv.Fact{{Key: "road/ring", Value: []byte("lane closed at J4")}},
Likelihoods: map[string]float64{"ring-road": 0.3},
Rest: mv.Likelihood(0.9),
})
The city centre takes the lead at 48.6%, the ferry has 32.4% and the ring road falls to 18.9%.
Locking the Plan After the Cut-Off
The depot manager signs off at 08:25, five minutes after the ferry’s cut-off. Nothing had to record the ferry plan’s death. Any read after 08:20 already shows it as expired, so the dispatcher never sees a plan that can’t happen any more. Between the two plans left, the city centre has 72.0% and the ring road 28.0%.
The dispatcher promotes the city-centre plan. The trunk now holds its route and the big van, with the 760 kg load and the 19 parcels from the late order already there. The ring-road plan is dropped, and the history shows how each of the four ended. Run it with go run ./examples/routing.