Search code examples
optaplanner

optaplanner - disable PlanningVariable at runntime


In my course-curriculum project I have 2 planning variables: timeslot and room. Now I want the user to be able to choose whether he wants to plan them both at once (which is happening now) or whether he wants to plan only the timeslot or only the room thus disabling one of the two as planning variable.

I now use 2 annotations:

@PlanningVariable(valueRangeProviderRefs = {"roomRange"})
public Room getRoom() 
 ..
@PlanningVariable(valueRangeProviderRefs = {"timeslotRange"})
public Timeslot getTimeslot() 

but how can I disable one of them at runtime?


Solution

  • OptaPlanner's @PlanningPin etc doesn't support this out the box yet. Vote for https://issues.redhat.com/browse/PLANNER-124

    Workaround proposals:

    A) Add a hard constraint that if one variable of the planning entity is pinned that penalizes it if it's assigned to something different. Not the most efficient.

    B) Proposal A with custom move selection (= deep rabbit hole)