Skip to content

Commit

Permalink
Check for duplicate variables in compact table, and unshare variables…
Browse files Browse the repository at this point in the history
… in the FlatZinc interface for table constraints. Fixes #167.
  • Loading branch information
guidotack committed Aug 31, 2023
1 parent 63330a7 commit 34adb07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ Date: 2020-??-??
[DESCRIPTION]
Let's see.

[ENTRY]
Module: int
What: bug
Issue: 167
Rank: minor
[DESCRIPTION]
Make extensional (compact-table) constraints check for duplicated variables.
Also fixes the FlatZinc interface to unshare arguments for extensional
constraints.

[ENTRY]
Module: support
What: change
Expand Down
6 changes: 6 additions & 0 deletions gecode/flatzinc/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,7 @@ namespace Gecode { namespace FlatZinc {
IntVarArgs x = s.arg2intvarargs(ce[0]);
IntArgs tuples = s.arg2intargs(ce[1]);
TupleSet ts = s.arg2tupleset(tuples,x.size());
unshare(s,x);
extensional(s,x,ts,s.ann2ipl(ann));
}

Expand All @@ -1259,6 +1260,7 @@ namespace Gecode { namespace FlatZinc {
IntVarArgs x = s.arg2intvarargs(ce[0]);
IntArgs tuples = s.arg2intargs(ce[1]);
TupleSet ts = s.arg2tupleset(tuples,x.size());
unshare(s,x);
extensional(s,x,ts,Reify(s.arg2BoolVar(ce[2]),RM_EQV),s.ann2ipl(ann));
}

Expand All @@ -1267,6 +1269,7 @@ namespace Gecode { namespace FlatZinc {
IntVarArgs x = s.arg2intvarargs(ce[0]);
IntArgs tuples = s.arg2intargs(ce[1]);
TupleSet ts = s.arg2tupleset(tuples,x.size());
unshare(s,x);
extensional(s,x,ts,Reify(s.arg2BoolVar(ce[2]),RM_IMP),s.ann2ipl(ann));
}

Expand All @@ -1275,6 +1278,7 @@ namespace Gecode { namespace FlatZinc {
BoolVarArgs x = s.arg2boolvarargs(ce[0]);
IntArgs tuples = s.arg2boolargs(ce[1]);
TupleSet ts = s.arg2tupleset(tuples,x.size());
unshare(s,x);
extensional(s,x,ts,s.ann2ipl(ann));
}

Expand All @@ -1283,6 +1287,7 @@ namespace Gecode { namespace FlatZinc {
BoolVarArgs x = s.arg2boolvarargs(ce[0]);
IntArgs tuples = s.arg2boolargs(ce[1]);
TupleSet ts = s.arg2tupleset(tuples,x.size());
unshare(s,x);
extensional(s,x,ts,Reify(s.arg2BoolVar(ce[2]),RM_EQV),s.ann2ipl(ann));
}

Expand All @@ -1291,6 +1296,7 @@ namespace Gecode { namespace FlatZinc {
BoolVarArgs x = s.arg2boolvarargs(ce[0]);
IntArgs tuples = s.arg2boolargs(ce[1]);
TupleSet ts = s.arg2tupleset(tuples,x.size());
unshare(s,x);
extensional(s,x,ts,Reify(s.arg2BoolVar(ce[2]),RM_IMP),s.ann2ipl(ann));
}

Expand Down
8 changes: 8 additions & 0 deletions gecode/int/extensional-tuple-set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace Gecode {
throw NotYetFinalized("Int::extensional");
if (t.arity() != x.size())
throw ArgumentSizeMismatch("Int::extensional");
if (same(x))
throw ArgumentSame("Int::extensional");
GECODE_POST;

ViewArray<IntView> xv(home,x);
Expand All @@ -65,6 +67,8 @@ namespace Gecode {
throw NotYetFinalized("Int::extensional");
if (t.arity() != x.size())
throw ArgumentSizeMismatch("Int::extensional");
if (same(x))
throw ArgumentSame("Int::extensional");
GECODE_POST;

ViewArray<IntView> xv(home,x);
Expand Down Expand Up @@ -114,6 +118,8 @@ namespace Gecode {
throw ArgumentSizeMismatch("Int::extensional");
if ((t.min() < 0) || (t.max() > 1))
throw NotZeroOne("Int::extensional");
if (same(x))
throw ArgumentSame("Int::extensional");
GECODE_POST;

ViewArray<BoolView> xv(home,x);
Expand All @@ -134,6 +140,8 @@ namespace Gecode {
throw ArgumentSizeMismatch("Int::extensional");
if ((t.min() < 0) || (t.max() > 1))
throw NotZeroOne("Int::extensional");
if (same(x))
throw ArgumentSame("Int::extensional");
GECODE_POST;

ViewArray<BoolView> xv(home,x);
Expand Down

0 comments on commit 34adb07

Please sign in to comment.