Repository navigation
nValues: java.lang.Exception with the condition (gt,1) or (ge,2) on two variables (notAllEqual) #18
Description
The constraint nValues with the condition (gt,1) or (ge,2) (that is to say, notAllEqual) fails when its list contains only two variables.
<instance format="XCSP3" type="CSP">
<variables>
<array id="x" size="[2]"> 0..2 </array>
</variables>
<constraints>
<nValues>
<list> x[0] x[1] </list>
<condition> (gt,1) </condition>
</nValues>
</constraints>
</instance>Observed: ! ERROR: and no solution, and with -ev:
java.lang.Exception
at utility.Kit.control(Kit.java:173)
at utility.Kit.control(Kit.java:183)
at constraints.global.NotAllEqual.<init>(NotAllEqual.java:49)
at constraints.global.NValues$NValuesCst.buildFrom(NValues.java:134)
at problem.Problem.nValues(Problem.java:2948)
at problem.XCSP3.buildCtrNValues(XCSP3.java:613)
at problem.XCSP3.buildCtrNotAllEqual(XCSP3.java:628)
The constructor of NotAllEqual controls scp.length > 2 (this control is still in the current source), whereas NValuesCst.buildFrom() builds a NotAllEqual for the conditions (gt,1) and (ge,2) whatever the number of variables.
Expected: the 6 solutions where x[0] != x[1]. With the condition (eq,2), or with three variables, ACE finds the expected solutions.
Results of the three solvers
| Instance | Expected (brute force) | ACE | CHOCO | cosoco |
|---|---|---|---|---|
the instance above: x[0] x[1] with (gt,1) |
6 solutions | fails: ! ERROR: (java.lang.Exception with -ev) |
correct: 6 solutions | correct: 6 solutions |
x[0] x[1] with (ge,2) |
6 solutions | fails: ! ERROR: (java.lang.Exception with -ev) |
correct: 6 solutions | correct: 6 solutions |
x[0] x[1] with (eq,2) |
6 solutions | correct: 6 solutions | correct: 6 solutions | correct: 6 solutions |
x[0] x[1] x[2] with (gt,1) (x of size 3) |
24 solutions | correct: 24 solutions | correct: 24 solutions | correct: 24 solutions |
with (ACE 2.6 and CHOCO (choco-parsers-4.10.15-beta), embedded in PyCSP3, and cosoco 2.6.1, from pip: the versions used by PyCSP3):
- ACE:
java -jar ACE-2.6.jar model.xml -s=all -xe -xc=false - CHOCO:
java -cp choco-parsers-4.10.15-beta.jar org.chocosolver.parser.xcsp.ChocoXCSP model.xml -a -f -flt - cosoco:
cosoco model.xml -model=2 -nbsols=0
Tests
Found by the unit tests of PyCSP3 (branch tests-notallequal, xcsp3team/pycsp3#130), where the following tests are marked as expected failures with ACE, in test_constraints_global_notallequal.py:
test_notallequal_sizeswith two variables (2 parameters), whose model is
x = VarArray(size=2, dom=range(2))
satisfy(
NotAllEqual(x)
)test_notallequal_on_rows(NotAllEqual(row)on rows of two variables);test_notallequal_with_integersforNotAllEqual(x[0], 5)(the integer is replaced by an auxiliary variable);test_notallequal_on_expressionsandtest_notallequal_on_expressions_with_option_miniforNotAllEqual(Sum(x[0], x[1]), x[2] + x[3])(two terms).
This issue was found by the unit tests of PyCSP3: xcsp3team/pycsp3#130
Activity
Give the issues of the known bugs in the marks of the tests of NotAll…
Expect the terms given several times to NotAllEqual() to be kept once
szczepanskiNicolas commentedon Sep 29, 2026
Fixed by 3a6cd59 (
control(scp.length >= 2)inNotAllEqual). Checked with ACE built from 3a6cd59 (gradle build), withjava -jar ACE-2.6.jar model.xml -s=all -xe -xc=false:x[0] x[1]with(gt,1)(the instance of this issue)! ERROR:x[0] x[1]with(ge,2)! ERROR:x[0] x[1]with(eq,2)x[0] x[1] x[2]with(gt,1)With this JAR in place of the one embedded in PyCSP3, the 6 tests of
test_constraints_global_notallequal.pymarked with this issue pass (XPASS), and the file gives 150 passed, 11 skipped and 14 expected failures (other issues) once these marks are removed. The marks are kept in xcsp3team/pycsp3#130 as long as PyCSP3 embeds ACE 2.6.