Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 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 = 7;
  23. int[] data = {4,3,3,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+" de dimension "+data[i]+" ",0,N-1-data[i]);
  32. posCol[i] = model.intVar("colonne du carré "+i+" de dimension "+data[i]+" ",0,N-1-data[i]);
  33.  
  34. }
  35.  
  36.  
  37. BoolVar b1 = model.boolVar();
  38. BoolVar b2 = model.boolVar();
  39. for(int i=0 ; i<K-1 ; i++)
  40. {
  41. for(int j=0 ; j<K-1 ; j++){
  42. if(i!=j){
  43. IntVar row = posRow[i];
  44. IntVar row1 = posRow[j];
  45. IntVar row2 = row.add(data[j]).intVar();
  46. IntVar row21 = row1.add(data[j]).intVar();
  47.  
  48. IntVar col = posCol[i];
  49. IntVar col1 = posCol[j];
  50. IntVar col2 = col.add(data[j]).intVar();
  51. IntVar col21 = col1.add(data[j]).intVar();
  52.  
  53. b1 = model.arithm(col2, "<=",col1).reify();
  54. b2 = model.arithm(row, "<=", row1).reify();
  55. b1 = model.or(b1,b2).reify();
  56.  
  57. b2 = model.arithm(row,">=",row21).reify();
  58. b1 = model.or(b1,b2).reify();
  59.  
  60. b2 = model.arithm(col,">=",col21).reify();
  61. model.or(b1,b2).post();
  62.  
  63. }
  64.  
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71. }
  72. Solution solution = model.getSolver().findSolution();
  73.  
  74. System.out.println(solution.toString());
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement