Search code examples
droolsoptaplanner

OptaPlanner: Sequal construction heuristic with multiple planning variables that are either all null or all non-null


According to the docs, For more than one planning variable on my entity, i need to use sequential way in my construction heuristics so that it doesn't get out of hand. But according to the docs,

Sequential: One variable is assigned at a time....

This is a concern for me because i have a hard constraint that says A lecture cannot have a schedule but no room or vice versa but it is okay if it is left unassigned (overconstrained). What happens is nothing is assigned since that doesn't break any hard constraint only medium ones. Any way/pattern on solving this problem?


Solution

  • Ah, I understand it: because sequential first assigns a period and then does the score calc before trying to assign a room, it will choose not to assign that period because it breaks a hard constraint when period != null && room == null.

    Interesting. One workaround I can think of is to add a filter on the planning values for the period selector (which is the first one) in that sequential config. That filter filters out "null" values, which forces the CH to assign the period to a non-null value.

    Another approach is to play with a custom CH in a custom phase. Look for "Initializer" classes in the examples. Some of the older examples might still use one.