Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. private static Model setupChoco(int nonetSize)
  2. {
  3. int gridSize = nonetSize * nonetSize;
  4.  
  5.  
  6. Model model = new Model("Killer Sodoku model");
  7. IntVar[][] variables = model.intVarMatrix("variables", nonetSize, nonetSize, 1, nonetSize, false);
  8.  
  9. // Rows
  10. for (int i = 0; i < nonetSize; i++)
  11. {
  12. model.allDifferent(variables[i]);
  13. }
  14.  
  15. // Cols
  16. for (int col = 0; col < nonetSize; col++)
  17. {
  18. for (int row = 0; row < nonetSize; row++)
  19. {
  20. for (int otherRows = row+1; otherRows < nonetSize; otherRows++)
  21. {
  22. model.arithm(variables[row][col], "!=", variables[otherRows][col]).post();
  23. }
  24. }
  25. }
  26.  
  27. // Nonets
  28. int nSize = nonetSize/3;
  29.  
  30. for (int i = 0; i < nonetSize; i+=3)
  31. {
  32. for (int j = 0; j < nonetSize; j+=3)
  33. {
  34. for (int row = 0; row < nSize; row++)
  35. {
  36. for (int col = 0; col < nSize; col++)
  37. {
  38. for (int row2 = row; row2 < nSize; row2++)
  39. {
  40. for (int col2 = col; col2 < nSize; col2++)
  41. {
  42. if (!(row == row2 && col == col2)) {
  43. model.arithm(variables[i+row][j+col], "!=", variables[i+row2][j+col2]).post();
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement