javaoptaplannertimefold

How to generate objects for planning entity in solving


I'm new to timefold and working on a Java project that assign different factories into groups (5 to 10 factories per group). The scoring part is working fine, I can manage to adjust different constraint for grouping. The problem is that it only works when if I submit both factory list and group list.

I want the solution to generate a new group when needed during the solve, instead of me submitting a list of empty group. Is it possible to do so?

Here's some of my code as reference

@PlanningSolution
public class GroupingProblem{

    @ProblemFactCollectionProperty
    @ValueRangeProvider(id = "factoryRange")
    private List<Factory> factoryList;

    @PlanningEntityCollectionProperty
    private List<Group> groupList;
}
@JsonIdentityInfo(scope = Group.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@PlanningEntity
public class Group {

    @PlanningId
    private String id;

    @JsonIdentityReference
    @PlanningListVariable(allowsUnassignedValues = true, valueRangeProviderRefs = "factoryRange")
    private List<Factory> factoryList;

}
@JsonIdentityInfo(scope = Factory.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Factory {
    @PlanningId
    private String id;

    // Other factory properties for scoring
}

Solution

  • No, this is not currently supported. It is recommended that you generate as many entities as you think you may need, and use unassigned values to make sure the solver only uses as many as necessary.