Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package fr.ufrsciencestech.badgef;
  7.  
  8. import org.chocosolver.solver.Model;
  9. import org.chocosolver.solver.Solution;
  10. import org.chocosolver.solver.variables.BoolVar;
  11. import org.chocosolver.solver.variables.IntVar;
  12.  
  13. /**
  14. *
  15. * @author sc364347
  16. */
  17. public class BadgeFV2
  18. {
  19. public static void main(String args[])
  20. {
  21.  
  22. int N = 4;
  23. int[] data = {2,2,2};
  24. int K=data.length;
  25.  
  26. IntVar[] posRow = new IntVar[K];
  27. IntVar[] posCol = new IntVar[K];
  28. Model model = new Model(2*K + "carre");
  29. for(int i=0; i<K ; i++)
  30. {
  31. posRow[i] = model.intVar("ligne du carré "+i+" ",0,N-data[i]);
  32. posCol[i] = model.intVar("colonne du carré "+i+" ",0,N-data[i]);
  33.  
  34. }
  35.  
  36.  
  37. BoolVar b1 = model.boolVar();
  38. BoolVar b2 = model.boolVar();
  39. for(int i=0 ; i<=K-2 ; i++)
  40. {
  41. for(int j=i+1 ; j<=K-1 ; j++){
  42.  
  43. IntVar rowMin = posRow[i];
  44. IntVar rowMinOther = posRow[j];
  45. IntVar rowMax = rowMin.add(data[i]).intVar();
  46. IntVar rowMaxOther = rowMinOther.add(data[j]).intVar();
  47.  
  48. IntVar colMin = posCol[i];
  49. IntVar colMinOther = posCol[j];
  50. IntVar colMax = colMin.add(data[i]).intVar();
  51. IntVar colMaxOther = colMinOther.add(data[j]).intVar();
  52.  
  53. b1 = model.arithm(colMax, "<=",colMinOther).reify();
  54. b2 = model.arithm(rowMax, "<=", rowMinOther).reify();
  55. b1 = model.or(b1,b2).reify();
  56.  
  57. b2 = model.arithm(rowMin,">=",rowMaxOther).reify();
  58. b1 = model.or(b1,b2).reify();
  59.  
  60. b2 = model.arithm(colMin,">=",colMaxOther).reify();
  61. model.or(b1,b2).post();
  62.  
  63.  
  64.  
  65. }
  66.  
  67.  
  68.  
  69.  
  70. }
  71. Solution solution = model.getSolver().findSolution();
  72. if(solution != null){
  73. System.out.println(solution.toString());
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement