Search code examples
javaoptaplannertimefold

Is it possible to get multi solutions in timefold?


I try to use timefold to get list of proposals to schedulea delivery for a client by an available delivery person. I would like to have five shifts to schedule the delivery and not just one

In the bellow my model:

    @PlanningEntity
    public class Delivery {
        @InverseRelationShadowVariable(sourceVariableName="assignedDelivery")
        private List<Order> orders;
    }

    @PlanningEntity
    public class Order {
        @PlanningVariable(valueRangeProviderRefs = {"deliveryRange"}, nullable = true)
        private Delivery assignedDelivery;
    }

    @PlanningSolution
    public class PlanningSolution {
        @ValueRangeProvider
        @PlanningEntityCollectionProperty
        List<Order> orders;

        @ValueRangeProvider(id="deliveryRange")
        @ProblemFactCollectionProperty
        List<Delivery> deliveryList;

        Shift shift;
    }

Using this model, the solver return only the best solution, should I use a specific pattern or update my model to get multi proposals/solutions, then I choose one of them and save it ?


Solution

  • If it's just to assign one delivery, take a look at SolutionManager.recommendFit(), new in Timefold Solver 1.5.0. It's build for when you have a customer on the phone and you need to answer right away with the best possible options to pick from, for example time windows (with or without fixing the vehicle and arrival time too).

    If it's to optimize multiple deliveries and give the planner a lot of options, it's called pareto optimization and it's a PITA because you can easily end up with millions of solutions, while showing even one big solution to the user is difficult. We don't support it well yet either, but you could hack BestSolutionRecaller.

    But you probably don't want pareto optimization. You want to give different schedule stakeholders (operations, financial, etc) a way to negotiate about the best schedule. This isn't the way. They'd have to negotiate every day. The way is constraint weights (see docs) and a proper simulation infrastructure (stay tuned) to negotiate only when the business goals change.