Generated on for Gecode by doxygen 1.17.0
rel.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.dev>
5 *
6 * Copyright:
7 * Guido Tack, 2005
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <gecode/minimodel.hh>
35
36#include "test/set.hh"
37
38using namespace Gecode;
39
40namespace Test { namespace Set {
41
43 namespace Rel {
44
50
51 static IntSet ds_33(-3,3);
52 static IntSet ds_03(0,3);
53
55 class RelBin : public SetTest {
56 private:
58 bool shared;
59 public:
61 RelBin(Gecode::SetRelType srt0, bool shared0)
62 : SetTest((srt0 == Gecode::SRT_CMPL) && !shared0
64 "Rel::Bin::"+str(srt0)+"::S"+(shared0 ? "1":"0"),
65 shared0 ? 1 : 2,ds_33,true)
66 , srt(srt0), shared(shared0){}
67 int minSymDiff(const SetAssignment& x) const {
68 int x1 = shared ? x[0] : x[1];
70 CountableSetRanges xr00(x.lub, x[0]);
71 CountableSetRanges xr10(x.lub, x1);
72 Diff a(xr00,xr10);
73 CountableSetRanges xr01(x.lub, x[0]);
74 CountableSetRanges xr11(x.lub, x1);
75 Diff b(xr11,xr01);
77 return u() ? u.min() : Gecode::Set::Limits::max+1;
78 }
79 bool in(int i, CountableSetRanges& c, bool eq=false) const {
80 if (eq && i==Gecode::Set::Limits::max+1)
81 return true;
83 return Iter::Ranges::subset(s,c);
84 }
85
86 bool solution(const SetAssignment& x) const {
87 int x1 = shared ? x[0] : x[1];
88 CountableSetRanges xr0(x.lub, x[0]);
89 CountableSetRanges xr1(x.lub, x1);
90 switch (srt) {
91 case SRT_EQ: return Iter::Ranges::equal(xr0, xr1);
92 case SRT_NQ: return !Iter::Ranges::equal(xr0, xr1);
93
94 case SRT_LQ: return (!xr0()) || in(minSymDiff(x),xr1,true);
95 case SRT_LE: return xr0() ? in(minSymDiff(x),xr1) : xr1();
96 case SRT_GQ: return (!xr1()) || in(minSymDiff(x),xr0,true);
97 case SRT_GR: return xr1() ? in(minSymDiff(x),xr0) : xr0();
98
99 case SRT_SUB: return Iter::Ranges::subset(xr0, xr1);
100 case SRT_SUP: return Iter::Ranges::subset(xr1, xr0);
101 case SRT_DISJ:
102 {
104 inter(xr0,xr1);
105 return !inter();
106 }
107 case SRT_CMPL:
108 {
110 return Iter::Ranges::equal(rc,xr1);
111 }
112 default:
114 }
116 return false;
117 }
118
119 void post(Space& home, SetVarArray& x, IntVarArray&) {
120 if (!shared)
121 Gecode::rel(home, x[0], srt, x[1]);
122 else
123 Gecode::rel(home, x[0], srt, x[0]);
124 }
125
127 if (!shared)
128 Gecode::rel(home, x[0], srt, x[1], r);
129 else
130 Gecode::rel(home, x[0], srt, x[0], r);
131 }
132 };
133
135 class ITE : public SetTest {
136 public:
138 ITE(void)
139 : SetTest("ITE",3,ds_03,false,1) {}
140
141 virtual bool solution(const SetAssignment& x) const {
142 if ((x.intval() < 0) || (x.intval() > 1))
143 return false;
144 if (x.intval() == 1) {
145 CountableSetRanges xr0(x.lub, x[0]);
146 CountableSetRanges xr2(x.lub, x[2]);
147 return Iter::Ranges::equal(xr0,xr2);
148 } else {
149 CountableSetRanges xr1(x.lub, x[1]);
150 CountableSetRanges xr2(x.lub, x[2]);
151 return Iter::Ranges::equal(xr1,xr2);
152 }
153 }
154
155 void post(Space& home, SetVarArray& x, IntVarArray& y) {
156 Gecode::ite(home, Gecode::channel(home,y[0]), x[0], x[1], x[2]);
157 }
158 };
159
180
183
184}}}
185
186// STATISTICS: test-set
Integer sets.
Definition int.hh:179
Integer variable array.
Definition int.hh:792
Range iterator for computing set difference.
Range iterator for computing intersection (binary).
int min(void) const
Return smallest value of range.
Range iterator for singleton range.
Range iterator for computing union (binary).
Reification specification.
Definition int.hh:1176
Set variable array
Definition set.hh:575
A complement iterator spezialized for the BndSet limits.
Definition var-imp.hpp:293
Computation spaces.
Definition core.hpp:1787
Range iterator producing subsets of an IntSet.
Definition set.hh:113
Test for if-then-else-constraint
Definition rel.cpp:135
ITE(void)
Construct and register test.
Definition rel.cpp:138
void post(Space &home, SetVarArray &x, IntVarArray &y)
Post constraint on x and y.
Definition rel.cpp:155
virtual bool solution(const SetAssignment &x) const
Check whether x is a solution.
Definition rel.cpp:141
Test for binary set relation constraint
Definition rel.cpp:55
bool in(int i, CountableSetRanges &c, bool eq=false) const
Definition rel.cpp:79
int minSymDiff(const SetAssignment &x) const
Definition rel.cpp:67
void post(Space &home, SetVarArray &x, IntVarArray &, Reify r)
Post reified constraint on x for b.
Definition rel.cpp:126
void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition rel.cpp:119
bool solution(const SetAssignment &x) const
Test whether x is solution
Definition rel.cpp:86
RelBin(Gecode::SetRelType srt0, bool shared0)
Create and register test.
Definition rel.cpp:61
Generate all set assignments.
Definition set.hh:156
int intval(void) const
Return value for first integer variable.
Definition set.hh:183
Gecode::IntSet lub
The common superset for all domains.
Definition set.hh:168
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition set.hpp:46
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition set.hh:312
Set of test tags.
Definition test.hh:105
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
void ite(Home home, BoolVar b, FloatVar x, FloatVar y, FloatVar z)
Post propagator for if-then-else constraint.
Definition bool.cpp:39
SetRelType
Common relation types for sets.
Definition set.hh:650
@ SRT_GQ
Greater or equal ( ).
Definition set.hh:659
@ SRT_CMPL
Complement.
Definition set.hh:656
@ SRT_GR
Greater ( ).
Definition set.hh:660
@ SRT_LQ
Less or equal ( ).
Definition set.hh:657
@ SRT_NQ
Disequality ( ).
Definition set.hh:652
@ SRT_LE
Less ( ).
Definition set.hh:658
@ SRT_EQ
Equality ( ).
Definition set.hh:651
@ SRT_SUP
Superset ( ).
Definition set.hh:654
@ SRT_DISJ
Disjoint ( ).
Definition set.hh:655
@ SRT_SUB
Subset ( ).
Definition set.hh:653
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
const int max
Largest allowed integer in integer set.
Definition set.hh:97
Gecode toplevel namespace
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
SetExpr inter(const SetVarArgs &)
Intersection of set variables.
Definition set-expr.cpp:696
Tests for relation constraints
Definition rel.cpp:43
RelBin _relbin_shared_nq(Gecode::SRT_NQ, true)
RelBin _relbin_shared_cmpl(Gecode::SRT_CMPL, true)
RelBin _relbin_shared_le(Gecode::SRT_LE, true)
RelBin _relbin_shared_gq(Gecode::SRT_GQ, true)
RelBin _relbin_gr(Gecode::SRT_GR, false)
RelBin _relbin_shared_disj(Gecode::SRT_DISJ, true)
RelBin _relbin_disj(Gecode::SRT_DISJ, false)
RelBin _relbin_le(Gecode::SRT_LE, false)
RelBin _relbin_eq(Gecode::SRT_EQ, false)
RelBin _relbin_shared_gr(Gecode::SRT_GR, true)
RelBin _relbin_cmpl(Gecode::SRT_CMPL, false)
RelBin _relbin_shared_eq(Gecode::SRT_EQ, true)
RelBin _relbin_shared_sub(Gecode::SRT_SUB, true)
RelBin _relbin_gq(Gecode::SRT_GQ, false)
RelBin _relbin_sub(Gecode::SRT_SUB, false)
RelBin _relbin_lq(Gecode::SRT_LQ, false)
RelBin _relbin_shared_sup(Gecode::SRT_SUP, true)
RelBin _relbin_shared_lq(Gecode::SRT_LQ, true)
RelBin _relbin_nq(Gecode::SRT_NQ, false)
RelBin _relbin_sup(Gecode::SRT_SUP, false)
Testing finite sets.
Definition set.cpp:42
General test support.
Definition afc.cpp:41
Region r
Definition region.cpp:65
@ standard
Standard test suite.
Definition test.hh:100
@ sweep
Really heavy sweep tests.
Definition test.hh:101
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56