chocoteam / choco-solver

An open-source Java library for Constraint Programming
http://choco-solver.org/
BSD 4-Clause "Original" or "Old" License
690 stars 143 forks source link

[BUG] Unexpected behaviour when using neg() intvar in arithm #1115

Open ArthurGodet opened 1 week ago

ArthurGodet commented 1 week ago

The following test fails :

@Test(groups = "1s", timeOut = 60000)
public void testWithViews() {
    Model model = new Model();
    IntVar start = model.intVar("start", 0, 57);
    IntVar duration = model.intVar("duration", 6, 6);
    IntVar end = start.getModel().offset(start, duration.getValue());
    model.arithm(start, "+", duration, "=", end).post();
    model.arithm(end.neg().intVar(), "+", duration, "=", start.neg().intVar()).post();
    model.getSolver().findAllSolutions();
    Assert.assertTrue(model.getSolver().getSolutionCount() > 0);
}

It fails because of the model.arithm(end.neg().intVar(), "+", duration, "=", start.neg().intVar()).post(); constraint, but it is exactly the same as model.arithm(start, "+", duration, "=", end).post();. Therefore, it should not fail.

My guess is that the faulty behaviour is coming from lines 123-124 in IntLinCombFactory : RESULT should be updated before NCOEFFS[i]