Assert.assertNotNull(c);
}
@Test(groups = {"1s"})
public void testNQueen() {
Solver s = new Solver();
int n = 8;
IntVar[] vars = new IntVar[n];
for (int i = 0; i < vars.length; i++) {
vars[i] = VariableFactory.enumerated("Q_" + i, 1, n, s);
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
int k = j - i;
Constraint neq = IntConstraintFactory.arithm(vars[i], "!=", vars[j]);
s.post(neq);
s.post(IntConstraintFactory.arithm(vars[i], "!=", vars[j], "+", -k));
s.post(IntConstraintFactory.arithm(vars[i], "!=", vars[j], "+", k));
}
}
File file = null;
try {
file = write(s);
} catch (IOException e) {
e.printStackTrace();
}
s = null;
try {
s = (Solver) read(file);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
Assert.assertNotNull(s);
s.findAllSolutions();
Assert.assertEquals(s.getMeasures().getSolutionCount(), 92, "nb sol incorrect");
}