Skip to content

nValues: java.lang.Exception with the condition (gt,1) or (ge,2) on two variables (notAllEqual) #18

Closed

Description

@szczepanskiNicolas

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_sizes with 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_integers for NotAllEqual(x[0], 5) (the integer is replaced by an auxiliary variable);
  • test_notallequal_on_expressions and test_notallequal_on_expressions_with_option_mini for NotAllEqual(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

  1. szczepanskiNicolas commented on Sep 29, 2026

    @szczepanskiNicolas
    CollaboratorAuthor

    Fixed by 3a6cd59 (control(scp.length >= 2) in NotAllEqual). Checked with ACE built from 3a6cd59 (gradle build), with java -jar ACE-2.6.jar model.xml -s=all -xe -xc=false:

    Instance Expected (brute force) ACE 2.6 (embedded in PyCSP3) ACE built from 3a6cd59
    x[0] x[1] with (gt,1) (the instance of this issue) 6 solutions fails: ! ERROR: correct: 6 solutions
    x[0] x[1] with (ge,2) 6 solutions fails: ! ERROR: correct: 6 solutions
    x[0] x[1] with (eq,2) 6 solutions correct: 6 solutions correct: 6 solutions
    x[0] x[1] x[2] with (gt,1) 24 solutions correct: 24 solutions correct: 24 solutions

    With this JAR in place of the one embedded in PyCSP3, the 6 tests of test_constraints_global_notallequal.py marked 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Constraints (Global)Section Constraints (Global) of the APIbugSomething isn't workingnValuesunit-testsFound by the unit tests of pycsp3 (pycsp3/tests)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions