The algorithm starts with a quick plan and keeps improving it: it removes crossings, moves stops between vehicles and swaps entire route segments.
The task is called the traveling salesperson problem: find the shortest round trip that visits every stop exactly once. When vehicles with different capacities are added, it becomes a delivery task with multiple vehicles (the Vehicle Routing Problem).
Exact methods, such as linear programming with cutting planes, can prove that the route found is the shortest. For large problems with many constraints, however, they can take a very long time.
In practice, heuristics are therefore used. They start with a quick plan, for example using the nearest-stop rule or the savings method. On its own, however, the nearest-stop rule gives routes about 25% longer than the optimum on average for randomly placed stops. Heuristics therefore keep improving the plan: they remove crossings, move stops between vehicles and swap entire route segments.
Metaheuristics such as simulated annealing, tabu search or repeated “ruin and recreate” help escape from plans that can no longer be improved by a small change. That is also how the algorithm in the game works.