Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package fr.ufrsciencestech.badgef;
- import org.chocosolver.solver.Model;
- import org.chocosolver.solver.Solution;
- import org.chocosolver.solver.variables.BoolVar;
- import org.chocosolver.solver.variables.IntVar;
- /**
- *
- * @author sc364347
- */
- public class BadgeFV2
- {
- public static void main(String args[])
- {
- int N = 4;
- int[] data = {2,2,2};
- int K=data.length;
- IntVar[] posRow = new IntVar[K];
- IntVar[] posCol = new IntVar[K];
- Model model = new Model(2*K + "carre");
- for(int i=0; i<K ; i++)
- {
- posRow[i] = model.intVar("ligne du carré "+i+" ",0,N-data[i]);
- posCol[i] = model.intVar("colonne du carré "+i+" ",0,N-data[i]);
- }
- BoolVar b1 = model.boolVar();
- BoolVar b2 = model.boolVar();
- for(int i=0 ; i<=K-2 ; i++)
- {
- for(int j=i+1 ; j<=K-1 ; j++){
- IntVar rowMin = posRow[i];
- IntVar rowMinOther = posRow[j];
- IntVar rowMax = rowMin.add(data[i]).intVar();
- IntVar rowMaxOther = rowMinOther.add(data[j]).intVar();
- IntVar colMin = posCol[i];
- IntVar colMinOther = posCol[j];
- IntVar colMax = colMin.add(data[i]).intVar();
- IntVar colMaxOther = colMinOther.add(data[j]).intVar();
- b1 = model.arithm(colMax, "<=",colMinOther).reify();
- b2 = model.arithm(rowMax, "<=", rowMinOther).reify();
- b1 = model.or(b1,b2).reify();
- b2 = model.arithm(rowMin,">=",rowMaxOther).reify();
- b1 = model.or(b1,b2).reify();
- b2 = model.arithm(colMin,">=",colMaxOther).reify();
- model.or(b1,b2).post();
- }
- }
- Solution solution = model.getSolver().findSolution();
- if(solution != null){
- System.out.println(solution.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement