I am trying to solve Sudoku as a problem of satisfying the constraints for a homework job. I have already created restrictions for all elements of a single row, as well as columns. I am trying to build constraints for elements in a separate area, and I am facing some problems.
The general idea of ββmy current algorithm is to add to the list all the variables that are in the subregion (for example, a 3x3 field for a 9x9 grid), and then rearrange all the values ββin this list to build NotEqualConstraints between each variable. The code below works correctly for the 1st sub-region of the NxN grid, but I'm not sure how to change this to iterate over the rest of the grid.
int incSize = (int)Math.sqrt(svars.length); ArrayList<Variable> subBox = new ArrayList<Variable>(); for (int ind = 0; ind < incSize; ind++) { for (int ind2 = 0; ind2 < incSize; ind2++) { subBox.add(svars[ind][ind2]); } } for (int i = 0; i < subBox.size(); i++) { for (int j = i + 1; j < subBox.size(); j++) { NotEqualConstraint row = new NotEqualConstraint(subBox.get(i), subBox.get(j)); constraints.add(row); } }
Can someone lead me in the right direction about how I can change the code to get into each subregion, and not just the upper left?
edit: I can also try any algorithm that works, there is no need to add all the values ββto the ArrayList for each subregion. If you see a better way, please read the understanding.
source share