Where do I specify that certain planning entities are immutable?
-
13-11-2019 - |
Question
I am making a (2X2) Sudoku game and I need to complete a puzzle. That means that some digits are immutable (they cannot be moved out of place.
In a 2X2 game, there are 16 Digit
s. The problem facts are row
s, column
s and block
s (get it?). The row
is the only planning variable.
I specified boolean fixed
as attribute for Digit
. But (as per the user guide), I found no place to implement it.
What are the ways to actually make some planning entities immutable?
I find these methods:
- Implement a
moveFactory
that changes therow
only if it is immutable. This method is not documented. - If the
row
is not equal to afixed_row
, break a hard constraint. - Use
@ValueRangeFromPlanningProperty
. Let the immutable entities have avalue_range
of a single element, and the mutable entities have have a list that excludes the fixed rows. This seems unsustainable for anything larger than a Sudoku project, right? And there are (my?) alleged pitfalls that derail the solver?
Extra question: is method #3 the recommended way for something like a timetabling problem (allocate subject-teacher to a possible period)?
Solution
Option 4: The fixed digits are problem facts: instances of a class that does not have a @PlanningEntity annotation. The non-fixed digits are planning entities: instances of a class that does have a @PlanningEntity.
If you'd like to reuse the same class for both for design purposes:
- A custom MoveFactory would be the way. Writing a custom move factory is documented: it's just a matter adding an if statement to excluding moves that change a fixed digit.
- In that case it's not a build-in hard constraint but a normal hard constraint, I wouldn't recommend that for this use case. See manual info about "build-in hard constraints"
- Overkill, but it would work :)