23 System.loadLibrary(
"jniortools");
28 public VarArraySolutionPrinter(
IntVar[] variables) {
29 variableArray = variables;
33 public void onSolutionCallback() {
34 System.out.printf(
"Solution #%d: time = %.02f s%n", solutionCount, wallTime());
35 for (
IntVar v : variableArray) {
36 System.out.printf(
" %s = %d%n", v.getName(), value(v));
41 public int getSolutionCount() {
45 private int solutionCount;
46 private final IntVar[] variableArray;
50 public static void main(String[] args)
throws Exception {
73 VarArraySolutionPrinter cb =
new VarArraySolutionPrinter(
new IntVar[] {x, y, z});
77 System.out.println(cb.getSolutionCount() +
" solutions found.");
Code sample that solves a model and displays all solutions.
static void main(String[] args)