Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Model setupChoco(int nonetSize)
- {
- int gridSize = nonetSize * nonetSize;
- Model model = new Model("Killer Sodoku model");
- IntVar[][] variables = model.intVarMatrix("variables", nonetSize, nonetSize, 1, nonetSize, false);
- // Rows
- for (int i = 0; i < nonetSize; i++)
- {
- model.allDifferent(variables[i]);
- }
- // Cols
- for (int col = 0; col < nonetSize; col++)
- {
- for (int row = 0; row < nonetSize; row++)
- {
- for (int otherRows = row+1; otherRows < nonetSize; otherRows++)
- {
- model.arithm(variables[row][col], "!=", variables[otherRows][col]).post();
- }
- }
- }
- // Nonets
- int nSize = nonetSize/3;
- for (int i = 0; i < nonetSize; i+=3)
- {
- for (int j = 0; j < nonetSize; j+=3)
- {
- for (int row = 0; row < nSize; row++)
- {
- for (int col = 0; col < nSize; col++)
- {
- for (int row2 = row; row2 < nSize; row2++)
- {
- for (int col2 = col; col2 < nSize; col2++)
- {
- if (!(row == row2 && col == col2)) {
- model.arithm(variables[i+row][j+col], "!=", variables[i+row2][j+col2]).post();
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement