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 Digits. The problem facts are rows, columns and blocks (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:

  1. Implement a moveFactory that changes the row only if it is immutable. This method is not documented.
  2. If the row is not equal to a fixed_row, break a hard constraint.
  3. Use @ValueRangeFromPlanningProperty. Let the immutable entities have a value_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)?

Was it helpful?

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:

  1. 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.
  2. 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"
  3. Overkill, but it would work :)

Option 5: https://issues.jboss.org/browse/JBRULES-3359

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top