// // The AC example in lectures and AR33 notes // import org.chocosolver.solver.Model; import org.chocosolver.solver.Solver; import org.chocosolver.solver.variables.IntVar; import org.chocosolver.solver.exception.ContradictionException; public class ACLecture { public static void main(String args[]) throws ContradictionException { Model model = new Model("AC lecture"); Solver solver = model.getSolver(); IntVar v1 = model.intVar("v1",1,5); IntVar v2 = model.intVar("v2",1,5); IntVar v3 = model.intVar("v3",1,5); IntVar v4 = model.intVar("v4",1,5); System.out.println(model); model.arithm(v4,"-",v1,">=",1).post(); // v1 <= v4 - 1 model.arithm(v4,"<",v3).post(); // v4 < v3 model.arithm(v1,"<",v2).post(); // v1 < v2 model.arithm(v2,"+",v3,">",6).post(); // v2 + v3 > 6 model.arithm(v4,"+",v2,"=",5); // v4 + v2 = 5 System.out.println(model); solver.propagate(); System.out.println(model); //while(solver.solve()) solver.solve(); System.out.println("solution: "+ v1 +" "+ v2 +" "+ v3 +" "+ v4); System.out.println(solver.getMeasures()); } }