24 System.loadLibrary(
"jniortools");
29 public VarArraySolutionPrinterWithObjective(
IntVar[] variables) {
30 variableArray = variables;
34 public void onSolutionCallback() {
35 System.out.printf(
"Solution #%d: time = %.02f s%n", solutionCount, wallTime());
36 System.out.printf(
" objective value = %f%n", objectiveValue());
37 for (
IntVar v : variableArray) {
38 System.out.printf(
" %s = %d%n", v.getName(), value(v));
43 public int getSolutionCount() {
47 private int solutionCount;
48 private final IntVar[] variableArray;
52 public static void main(String[] args)
throws Exception {
80 VarArraySolutionPrinterWithObjective cb =
81 new VarArraySolutionPrinterWithObjective(
new IntVar[] {x, y, z});
85 System.out.println(cb.getSolutionCount() +
" solutions found.");