Search code examples
optaplanner

Unlimited vehicles in VRP


How to allow Optaplanner to use an unlimited or dynamic number of vehicles in the VRP problem?

The number of vehicles is minimized during score calculation, as each vehicle has a base cost. The solver should initialize as many vehicles as it thinks it is comvenient

@PlanningEntityCollectionProperty
@ValueRangeProvider(id = "vehicleRange")
public List<Vehicle> getVehicleList() {
    return vehicleList;
}

Currently I just initialize the vehicle list with a predefined number of vehicles, such as 100 000, but I am not sure about the performance implications of that, as the search space is much bigger than necessary.


Solution

  • Out-of-the-box, this is the only way. You figure out the minimum maximum number of vehicles for a dataset and use that to determine the number of vehicles. For one, the minimum maximum number of vehicles is never bigger than the number of visits. But usually you can prove it to be far less than that.

    That being said, the OptaPlanner architecture does support Move's that create or delete Vehicles, at least in theory. No out-of-the-box moves do that, so you'd need to build custom moves to do that - and it will get complex fast. One day we intend to support generic create/delete moves out-of-the-box.