// // how many solutions are there for the equation x + y + z = 11 // where x, y and z are positive integers? // import java.io.*; import java.util.*; import org.chocosolver.solver.Model; import org.chocosolver.solver.Solver; import org.chocosolver.solver.variables.IntVar; import org.chocosolver.solver.constraints.IIntConstraintFactory.*; 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("first: "+ v1 +" "+ v2 +" "+ v3 +" "+ v4); 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("before: "+ v1 +" "+ v2 +" "+ v3 +" "+ v4); solver.propagate(); System.out.println("after: "+ v1 +" "+ v2 +" "+ v3 +" "+ v4); while(solver.solve()); System.out.println("solution: "+ v1 +" "+ v2 +" "+ v3 +" "+ v4); System.out.println(solver.getMeasures()); } }