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 = 7;
- int[] data = {4,3,3,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+" de dimension "+data[i]+" ",0,N-1-data[i]);
- posCol[i] = model.intVar("colonne du carré "+i+" de dimension "+data[i]+" ",0,N-1-data[i]);
- }
- BoolVar b1 = model.boolVar();
- BoolVar b2 = model.boolVar();
- for(int i=0 ; i<K-1 ; i++)
- {
- for(int j=0 ; j<K-1 ; j++){
- if(i!=j){
- IntVar row = posRow[i];
- IntVar row1 = posRow[j];
- IntVar row2 = row.add(data[j]).intVar();
- IntVar row21 = row1.add(data[j]).intVar();
- IntVar col = posCol[i];
- IntVar col1 = posCol[j];
- IntVar col2 = col.add(data[j]).intVar();
- IntVar col21 = col1.add(data[j]).intVar();
- b1 = model.arithm(col2, "<=",col1).reify();
- b2 = model.arithm(row, "<=", row1).reify();
- b1 = model.or(b1,b2).reify();
- b2 = model.arithm(row,">=",row21).reify();
- b1 = model.or(b1,b2).reify();
- b2 = model.arithm(col,">=",col21).reify();
- model.or(b1,b2).post();
- }
- }
- }
- Solution solution = model.getSolver().findSolution();
- System.out.println(solution.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement