Generated on for Gecode by doxygen 1.17.0
channel.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2006
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 "test/int.hh"
35
36#include <gecode/minimodel.hh>
37
38namespace Test { namespace Int {
39
41 namespace Channel {
42
48
49 class ChannelFull : public Test {
50 private:
51 int xoff; //< Offset for the x variables
52 int yoff; //< Offset for the y variables
53 public:
55 ChannelFull(int xoff0, int yoff0, Gecode::IntPropLevel ipl)
56 : Test(TestTags::sweep(),"Channel::Full::"+str(xoff0)+"::"+str(yoff0)+"::"+str(ipl),
57 8,0,3,false,ipl),
58 xoff(xoff0), yoff(yoff0) {
60 }
61
62 virtual bool solution(const Assignment& x) const {
63 for (int i=0; i<4; i++)
64 if (x[4+x[i]] != i)
65 return false;
66 return true;
67 }
68
69 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
70 using namespace Gecode;
71 IntVarArgs xa(4); IntVarArgs ya(4);
72 for (int i=4; i--; ) {
73 if (xoff != 0) {
74 IntVar xo(home, xoff, 3+xoff);
75 Gecode::rel(home, x[i] == xo-xoff);
76 xa[i] = xo;
77 } else {
78 xa[i] = x[i];
79 }
80 if (yoff != 0) {
81 IntVar yo(home, yoff, 3+yoff);
82 Gecode::rel(home, x[4+i] == yo-yoff);
83 ya[i] = yo;
84 } else {
85 ya[i] = x[4+i];
86 }
87 }
88 channel(home, xa, xoff, ya, yoff, ipl);
89 }
90 };
91
93 class ChannelHalf : public Test {
94 public:
97 : Test(TestTags::sweep(),"Channel::Half::"+str(ipl),6,0,5,false,ipl) {
99 }
100
101 virtual bool solution(const Assignment& x) const {
102 for (int i=0; i<6; i++)
103 for (int j=i+1; j<6; j++)
104 if (x[i] == x[j])
105 return false;
106 return true;
107 }
108
109 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
110 using namespace Gecode;
111 Gecode::IntVarArgs y(home,6,dom);
112 for (int i=0; i<6; i++)
113 for (int j=0; j<6; j++) {
114 Gecode::BoolVar b(home,0,1);
115 rel(home, x[i], Gecode::IRT_EQ, j, b);
116 rel(home, y[j], Gecode::IRT_EQ, i, b);
117 }
118 channel(home, x, y, ipl);
119 }
120 };
121
123 class ChannelShared : public Test {
124 public:
127 : Test(TestTags::sweep(),"Channel::Shared::"+str(ipl),6,0,5,false,ipl) {
129 }
130
131 virtual bool solution(const Assignment& x) const {
132 for (int i=0; i<6; i++)
133 if (x[x[i]] != i)
134 return false;
135 return true;
136 }
137
138 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
139 using namespace Gecode;
140 channel(home, x, x, ipl);
141 }
142 };
143
145 class ChannelLinkSingle : public Test {
146 public:
149 : Test(TestTags::sweep(),"Channel::Bool::Single",2,-1,2) {
151 }
152
153 virtual bool solution(const Assignment& x) const {
154 return ((x[0]==0) || (x[0]==1)) && (x[0]==x[1]);
155 }
156
157 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
158 using namespace Gecode;
159 Gecode::BoolVar b(home,0,1);
160 channel(home, x[0], b);
161 channel(home, x[1], b);
162 }
163 };
164
166 class ChannelLinkMulti : public Test {
167 private:
168 int o;
169 public:
171 ChannelLinkMulti(TestTags tags, const std::string& s,
172 int min, int max, int o0)
173 : Test(tags,"Channel::Bool::Multi::"+s,7,min,max), o(o0) {
174 }
175
176 virtual bool solution(const Assignment& x) const {
177 int n = x.size()-1;
178 for (int i=n; i--; )
179 if ((x[i] != 0) && (x[i] != 1))
180 return false;
181 int k=x[n]-o;
182 if ((k<0) || (k>=n))
183 return false;
184 for (int i=0; i<k; i++)
185 if (x[i] != 0)
186 return false;
187 for (int i=k+1; i<n; i++)
188 if (x[i] != 0)
189 return false;
190 return x[k] == 1;
191 }
192
193 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
194 using namespace Gecode;
195 int n=x.size()-1;
197 for (int i=n; i--; )
198 b[i]=channel(home,x[i]);
199 channel(home, b, x[n], o);
200 }
201 };
202
203
204
207
210
213
216
219
221
226
227 }
228}}
229
230// STATISTICS: test-int
Passing Boolean variables.
Definition int.hh:739
Boolean integer variables.
Definition int.hh:534
Passing integer variables.
Definition int.hh:681
Integer variable array.
Definition int.hh:792
Integer variables.
Definition int.hh:390
Computation spaces.
Definition core.hpp:1787
int size(void) const
Return size of array (number of elements).
Definition array.hpp:945
TestTags tags(void) const
Return tags for test.
Definition test.hpp:95
Base class for assignments
Definition int.hh:73
int size(void) const
Return number of variables.
Definition int.hpp:46
Simple test for channel (testing all variables).
Definition channel.cpp:49
ChannelFull(int xoff0, int yoff0, Gecode::IntPropLevel ipl)
Construct and register test.
Definition channel.cpp:55
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition channel.cpp:69
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition channel.cpp:62
Simple test for channel (testing single set of variables).
Definition channel.cpp:93
ChannelHalf(Gecode::IntPropLevel ipl)
Construct and register test.
Definition channel.cpp:96
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition channel.cpp:109
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition channel.cpp:101
Test channel between integer variable and array of Boolean variables
Definition channel.cpp:166
ChannelLinkMulti(TestTags tags, const std::string &s, int min, int max, int o0)
Construct and register test.
Definition channel.cpp:171
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition channel.cpp:193
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition channel.cpp:176
Test channel between integer and Boolean variable
Definition channel.cpp:145
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition channel.cpp:153
ChannelLinkSingle(void)
Construct and register test.
Definition channel.cpp:148
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition channel.cpp:157
Test channel with shared variables
Definition channel.cpp:123
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition channel.cpp:138
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition channel.cpp:131
ChannelShared(Gecode::IntPropLevel ipl)
Construct and register test.
Definition channel.cpp:126
static std::string str(bool b)
Map bool to string.
Definition int.hpp:278
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:281
Gecode::IntSet dom
Domain of variables.
Definition int.hh:275
ConTestLevel contest
Whether to test for certain consistency.
Definition int.hh:283
Set of test tags.
Definition test.hh:105
static TestTags sweep(void)
Expensive parameter sweeps.
Definition test.hpp:59
static TestTags standard(void)
Standard suite without expensive sweeps.
Definition test.hpp:55
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1274
@ IRT_EQ
Equality ( ).
Definition int.hh:1226
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:1279
@ IPL_VAL
Value propagation.
Definition int.hh:1277
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
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Tests for channel constraints
Definition channel.cpp:41
ChannelFull cfd11(1, 1, Gecode::IPL_DOM)
ChannelFull cfd35(3, 5, Gecode::IPL_DOM)
ChannelLinkSingle cls
Definition channel.cpp:220
ChannelLinkMulti clmc(TestTags::sweep(),"C",-1, 4,-1)
ChannelFull cfv(0, 0, Gecode::IPL_VAL)
ChannelFull cfd(0, 0, Gecode::IPL_DOM)
ChannelLinkMulti clma(TestTags::standard(),"A", 0, 5, 0)
ChannelFull cfv35(3, 5, Gecode::IPL_VAL)
ChannelFull cfv11(1, 1, Gecode::IPL_VAL)
ChannelShared csd(Gecode::IPL_DOM)
ChannelHalf chd(Gecode::IPL_DOM)
ChannelHalf chv(Gecode::IPL_VAL)
ChannelLinkMulti clmb(TestTags::sweep(),"B", 1, 6, 1)
ChannelShared csv(Gecode::IPL_VAL)
Testing finite domain integers.
Definition int.cpp:41
@ CTL_NONE
No consistency-test.
Definition int.hh:154
General test support.
Definition afc.cpp:41
@ sweep
Really heavy sweep tests.
Definition test.hh:101