#8 Bug in the constraint XexpYeqZ

closed-fixed
nobody
None
5
2011-05-04
2011-04-19
No

Hello,

There seems to be a bug in the consistency method of the constraint XexpYeqZ.
This happens when the domain of some variables given in argument contains the value 0.
Here's a small piece of code that can be used to reproduce the bad behaviour:

Store store = new Store();
IntVar[] vars = new IntVar[3];
IntVar v1 = new IntVar(store, "v1", 0, 0);
vars[0] = v1;
IntVar v2 = new IntVar(store, "v2", 2, 2);
vars[1] = v2;
IntVar v3 = new IntVar(store, "v3", 0, 0);
vars[2] = v3;

XexpYeqZ ex = new XexpYeqZ(v1, v2, v3);
store.impose(ex);

boolean result = store.consistency();

assert result == true: "incorrect";

When executing this piece of code, the consistency method of the constraint will call the method aLog(double a, double x) with x as 0.0.
This results in a division by 0, and a load of not caught JaCoP.core.FailException will follow when calling domain.in() in consistency().

Discussion

  • kris

    kris - 2011-04-19
    • status: open --> closed-works-for-me
     
  • kris

    kris - 2011-04-19

    Hi!

    I do not see the problem. I have executed your program and got the following print-out:

    $ java -ea -cp .:.. Exp
    Exception in thread "main" java.lang.AssertionError: incorrect
    at Exp.example(Exp.java:44)
    at Exp.main(Exp.java:22)

    It means that the solver found out inconsistency (there is no solution for this values) and returned false.

    Best regards,
    /Kris

     
  • kris

    kris - 2011-04-19
    • status: closed-works-for-me --> closed-accepted
     
  • kris

    kris - 2011-04-19

    Hi!

    Sorry. I was in harry and did not grasp your problem. Yes, it is wrong. You need to replace lines 127-128 with the following lines.

    if (x.max()==0 || z.min()==0)
    yMin = y.min();
    else
    yMin = Math.max(aLog(x.max(), z.min()), y.min());
    if (x.min()==0 || z.max()==0)
    yMax = y.max();
    else
    yMax = Math.min(aLog(x.min(), z.max()), y.max());

    I will test it a little bit more and will update the svn later.

    Thank you for your report.

    /Kris

     
  • kris

    kris - 2011-05-04
    • status: closed-accepted --> closed-fixed