Loading solver…

Routing - Dispatch Map

Problem: assign pallet deliveries to trucks from multiple depots while respecting truck capacity and route length.

Show code
import {
  FirstSolutionStrategy,
  RoutingIndexManager,
  RoutingModel,
} from 'or-tools-wasm/routing';


const starts = [0, 1, 2, 3];
const manager = new RoutingIndexManager(stops.length, starts.length, starts, starts);
const routing = new RoutingModel(manager);
const transit = routing.registerTransitCallback((from, to) => {
  const a = stops[manager.indexToNode(from)];
  const b = stops[manager.indexToNode(to)];
  return Math.round(Math.hypot(a.x - b.x, a.y - b.y));
});
routing.setArcCostEvaluatorOfAllVehicles(transit);

const demand = routing.registerUnaryTransitCallback((from) =>
  stops[manager.indexToNode(from)].demand,
);
routing.addDimensionWithVehicleCapacity(demand, 0, vehicleCapacities, true, 'load');
routing.addDimension(transit, 0, routeDistanceCap, true, 'distance');

deliveryNodes.forEach((node) => {
  routing.addDisjunction([manager.nodeToIndex(node)], dropPenaltyFor(node));
});

const result = await routing.solve({
  firstSolutionStrategy: FirstSolutionStrategy.PATH_CHEAPEST_ARC,
  solutionLimit: 1,
  executor: 'worker',
});
console.log(result.status, result.assignment?.objectiveValue());
  • Several trucks start and end at separate depots.
  • Each delivery has a random pallet demand and priority.
  • Delivery border color shows priority: gray is standard, amber is express, and red is critical.
  • Each truck has the same pallet capacity and a route distance cap.
  • Drop penalties allow impossible or inefficient deliveries to be left unserved, with critical stops penalized most.
  • Before solving, the map shows generated depots and deliveries; after solving, each color is one truck route.

Routes

Run the solver to animate dispatch routes.

Status / Response: