3
* Guido Tack <tack@gecode.org>
9
* $Date: 2005-11-01 16:01:21 +0100 (Tue, 01 Nov 2005) $ by $Author: zayenz $
12
* This file is part of Gecode, the generic constraint
13
* development environment:
14
* http://www.gecode.org
16
* See the file "LICENSE" for information on usage and
17
* redistribution of this file, and for a
18
* DISCLAIMER OF ALL WARRANTIES.
22
#include "test/set.hh"
24
static IntSet ds_012(-1,2);
26
class SelectUnion : public SetTest {
28
SelectUnion(const char* t)
29
: SetTest(t,5,ds_012,false) {}
30
virtual bool solution(const SetAssignment& x) const {
32
for (CountableSetValues sel2(x.lub, x[3]); sel2(); ++sel2, selected++);
33
CountableSetValues x4v(x.lub, x[4]);
36
GECODE_AUTOARRAY(CountableSetRanges, sel, selected);
37
CountableSetValues selector(x.lub, x[3]);
38
for (int i=selected; i--;++selector) {
39
if (selector.val()>=3 || selector.val()<0)
41
sel[i].init(x.lub, x[selector.val()]);
43
Iter::Ranges::NaryUnion<CountableSetRanges> u(sel, selected);
45
CountableSetRanges z(x.lub, x[4]);
46
return Iter::Ranges::equal(u, z);
48
virtual void post(Space* home, SetVarArray& x, IntVarArray&) {
49
SetVarArgs xs(x.size()-2);
50
for (int i=x.size()-2; i--;)
52
Gecode::selectUnion(home, xs, x[x.size()-2], x[x.size()-1]);
55
SelectUnion _selectunion("Select::Union");
57
class SelectInter : public SetTest {
59
SelectInter(const char* t)
60
: SetTest(t,5,ds_012,false) {}
61
virtual bool solution(const SetAssignment& x) const {
63
for (CountableSetValues sel2(x.lub, x[3]); sel2(); ++sel2, selected++);
64
CountableSetRanges x4r(x.lub, x[4]);
66
return Iter::Ranges::size(x4r)==Limits::Set::card_max;
67
GECODE_AUTOARRAY(CountableSetRanges, sel, selected);
68
CountableSetValues selector(x.lub, x[3]);
69
for (int i=selected; i--;++selector) {
70
if (selector.val()>=3 || selector.val()<0)
72
sel[i].init(x.lub, x[selector.val()]);
74
Iter::Ranges::NaryInter<CountableSetRanges> u(sel, selected);
76
CountableSetRanges z(x.lub, x[4]);
77
return Iter::Ranges::equal(u, z);
79
virtual void post(Space* home, SetVarArray& x, IntVarArray&) {
80
SetVarArgs xs(x.size()-2);
81
for (int i=x.size()-2; i--;)
83
Gecode::selectInter(home, xs, x[x.size()-2], x[x.size()-1]);
86
SelectInter _selectinter("Select::Inter");
88
class SelectSets : public SetTest {
90
SelectSets(const char* t)
91
: SetTest(t,4,ds_012,false,true) {}
92
virtual bool solution(const SetAssignment& x) const {
93
if (x.intval() < 0 || x.intval() > 2)
95
CountableSetRanges z(x.lub, x[3]);
96
CountableSetRanges y(x.lub, x[x.intval()]);
97
return Iter::Ranges::equal(y, z);
99
virtual void post(Space* home, SetVarArray& x, IntVarArray& y) {
100
SetVarArgs xs(x.size()-1);
101
for (int i=x.size()-1; i--;)
103
Gecode::selectSets(home, xs, y[0], x[x.size()-1]);
106
SelectSets _selectsets("Select::Sets");
108
// STATISTICS: test-set