Skip to content

XCSP3: handle reified constraints (#1248) - #1257

Merged
cprudhom merged 1 commit into
developfrom
fix/1248-reified-by
Oct 13, 2026
Merged

cprudhom merged 1 commit into
developfrom
fix/1248-reified-by

Conversation

@cprudhom

Copy link
Copy Markdown
Member

XCSP3: handle reified constraints

Closes #1248 (item 10, the last one: the other items were fixed by #1254 and #1255).

Problem

The attributes reifiedBy, hreifiedFrom and hreifiedTo were ignored: the constraint was posted alone. XParser reads them, but xcsp3-tools 2.5 does not pass them to any callback.

On the instance of the issue (element with a list and a value, reifiedBy="r"), this gave 38 assignments, 19 of them wrong, instead of the 27 expected ones.

How it works

XCSPParser overrides loadCtr. For a reified constraint:

  1. The reification is stored in a field before the callback of the constraint is called.
  2. A callback may deal with it itself, by calling reify(BoolVar) with the truth value of the constraint.
  3. Otherwise, the constraints posted by the callback are unposted and reified (reifyWith, impliedBy or implies).

Step 3 is refused with a ParserException when it would be wrong: the callback introduced an auxiliary variable (views and constants are fine), added clauses, or posted nothing. So a reification is never silently ignored.

Semantics, as in the XCSP3 specifications: reifiedBy is r ⇔ c, hreifiedFrom is r ⇒ c, hreifiedTo is r ⇐ c.

Coverage

Constraints
Dealt with by the callback intension, sum, count, nValues, minimum, maximum, atLeast, atMost, with any kind of condition (relation with a constant or a variable, interval, set)
Reified from what the callback posts allDifferent, allEqual, extension, ordered, lex, element, cardinality, channel, noOverlap (tested); other constraints as long as the guard above holds
Refused with an explicit message regular, slide and logic meta-constraints (and, or, not...), and any callback that relies on auxiliary variables without calling reify

For the callbacks of the first row, the result of the function goes into a fresh variable, posted as usual, and the condition on this result is reified (resultVar).

Other change

element with a list and a condition on a constant is now stated on Boolean views ("at least one variable satisfies the condition"), instead of an element constraint with a free index variable. This makes it reifiable.

Tests

In XCSPParserTest, against brute force (same solutions, each found once):

  • each reifiable constraint with the three kinds of reification;
  • the refused cases, which must raise a ParserException;
  • element with a condition, not reified;
  • n-ary iff and xor in an intension, reified or not (parser-level test for Fix n-ary iff and xor expressions (#1248) #1255).

The xcsp group passes: 154 tests, no failure.

Limits

  • The tests use three variables with domain 0..2.
  • Reified slide and logic meta-constraints are refused, not handled.
  • The status line printed on a refused instance is s UNKNOWN unless the log level is INFO, where it is s UNSUPPORTED.

- reifiedBy, hreifiedFrom and hreifiedTo are no longer ignored
- a callback can deal with the reification itself: this is done for
  intension, sum, count, nValues, minimum, maximum, atLeast and atMost
- otherwise, the constraints posted by the callback are reified,
  unless they rely on auxiliary variables or clauses: then, the
  reification is refused
- the reification of slide and logic meta-constraints is refused
- element with a list and a constant condition is stated on views
@cprudhom cprudhom added this to the 6.0.3 milestone Oct 13, 2026
@cprudhom cprudhom self-assigned this Oct 13, 2026
@cprudhom cprudhom added the bug label Oct 13, 2026
@mergify

mergify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants