Generated on Sat Feb 7 2015 02:01:20 for Gecode by doxygen 1.8.9.1
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.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2006
8  *
9  * Last modified:
10  * $Date: 2011-10-31 13:01:40 +0100 (Mon, 31 Oct 2011) $ by $Author: schulte $
11  * $Revision: 12449 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include "test/int.hh"
39 
40 #include <gecode/minimodel.hh>
41 
42 namespace Test { namespace Int {
43 
45  namespace Channel {
46 
52  class ChannelFull : public Test {
54  private:
55  int xoff; //< Offset for the x variables
56  int yoff; //< Offset for the y variables
57  public:
59  ChannelFull(int xoff0, int yoff0, Gecode::IntConLevel icl)
60  : Test("Channel::Full::"+str(xoff0)+"::"+str(yoff0)+"::"+str(icl),
61  8,0,3,false,icl),
62  xoff(xoff0), yoff(yoff0) {
63  contest = CTL_NONE;
64  }
66  virtual bool solution(const Assignment& x) const {
67  for (int i=0; i<4; i++)
68  if (x[4+x[i]] != i)
69  return false;
70  return true;
71  }
73  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
74  using namespace Gecode;
75  IntVarArgs xa(4); IntVarArgs ya(4);
76  for (int i=4; i--; ) {
77  if (xoff != 0) {
78  IntVar xo(home, xoff, 3+xoff);
79  Gecode::rel(home, x[i] == xo-xoff);
80  xa[i] = xo;
81  } else {
82  xa[i] = x[i];
83  }
84  if (yoff != 0) {
85  IntVar yo(home, yoff, 3+yoff);
86  Gecode::rel(home, x[4+i] == yo-yoff);
87  ya[i] = yo;
88  } else {
89  ya[i] = x[4+i];
90  }
91  }
92  channel(home, xa, xoff, ya, yoff, icl);
93  }
94  };
95 
97  class ChannelHalf : public Test {
98  public:
101  : Test("Channel::Half::"+str(icl),6,0,5,false,icl) {
102  contest = CTL_NONE;
103  }
105  virtual bool solution(const Assignment& x) const {
106  for (int i=0; i<6; i++)
107  for (int j=i+1; j<6; j++)
108  if (x[i] == x[j])
109  return false;
110  return true;
111  }
113  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
114  using namespace Gecode;
115  Gecode::IntVarArgs y(home,6,dom);
116  for (int i=0; i<6; i++)
117  for (int j=0; j<6; j++) {
118  Gecode::BoolVar b(home,0,1);
119  rel(home, x[i], Gecode::IRT_EQ, j, b);
120  rel(home, y[j], Gecode::IRT_EQ, i, b);
121  }
122  channel(home, x, y, icl);
123  }
124  };
125 
127  class ChannelShared : public Test {
128  public:
131  : Test("Channel::Shared::"+str(icl),6,0,5,false,icl) {
132  contest = CTL_NONE;
133  }
135  virtual bool solution(const Assignment& x) const {
136  for (int i=0; i<6; i++)
137  if (x[x[i]] != i)
138  return false;
139  return true;
140  }
142  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
143  using namespace Gecode;
144  channel(home, x, x, icl);
145  }
146  };
147 
149  class ChannelLinkSingle : public Test {
150  public:
153  : Test("Channel::Bool::Single",2,-1,2) {
154  contest = CTL_NONE;
155  }
157  virtual bool solution(const Assignment& x) const {
158  return ((x[0]==0) || (x[0]==1)) && (x[0]==x[1]);
159  }
161  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
162  using namespace Gecode;
163  Gecode::BoolVar b(home,0,1);
164  channel(home, x[0], b);
165  channel(home, x[1], b);
166  }
167  };
168 
170  class ChannelLinkMulti : public Test {
171  private:
172  int o;
173  public:
175  ChannelLinkMulti(const std::string& s, int min, int max, int o0)
176  : Test("Channel::Bool::Multi::"+s,7,min,max), o(o0) {
177  }
179  virtual bool solution(const Assignment& x) const {
180  int n = x.size()-1;
181  for (int i=n; i--; )
182  if ((x[i] != 0) && (x[i] != 1))
183  return false;
184  int k=x[n]-o;
185  if ((k<0) || (k>=n))
186  return false;
187  for (int i=0; i<k; i++)
188  if (x[i] != 0)
189  return false;
190  for (int i=k+1; i<n; i++)
191  if (x[i] != 0)
192  return false;
193  return x[k] == 1;
194  }
196  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
197  using namespace Gecode;
198  int n=x.size()-1;
200  for (int i=n; i--; )
201  b[i]=channel(home,x[i]);
202  channel(home, b, x[n], o);
203  }
204  };
205 
206 
207 
210 
213 
216 
217  ChannelHalf chd(Gecode::ICL_DOM);
218  ChannelHalf chv(Gecode::ICL_VAL);
219 
220  ChannelShared csd(Gecode::ICL_DOM);
221  ChannelShared csv(Gecode::ICL_VAL);
222 
224 
225  ChannelLinkMulti clma("A", 0, 5, 0);
226  ChannelLinkMulti clmb("B", 1, 6, 1);
227  ChannelLinkMulti clmc("C",-1, 4,-1);
229 
230  }
231 }}
232 
233 // STATISTICS: test-int
234 
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:179
Simple test for channel (testing single set of variables)
Definition: channel.cpp:97
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:66
ChannelFull cfd35(3, 5, Gecode::ICL_DOM)
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
ChannelFull cfv(0, 0, Gecode::ICL_VAL)
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:135
Value propagation or consistency (naive)
Definition: int.hh:938
Test channel between integer variable and array of Boolean variables
Definition: channel.cpp:170
ChannelShared(Gecode::IntConLevel icl)
Construct and register test.
Definition: channel.cpp:130
Gecode::IntSet dom
Domain of variables.
Definition: int.hh:220
Integer variable array.
Definition: int.hh:741
Simple test for channel (testing all variables)
Definition: channel.cpp:53
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:196
ConTestLevel contest
Whether to test for certain consistency.
Definition: int.hh:228
Computation spaces.
Definition: core.hpp:1362
ChannelShared csv(Gecode::ICL_VAL)
static std::string str(Gecode::ExtensionalPropKind epk)
Map extensional propagation kind to string.
Definition: int.hpp:212
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:142
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Equality ( )
Definition: int.hh:904
No consistency-test.
Definition: int.hh:144
ChannelLinkSingle cls
Definition: channel.cpp:223
Gecode::IntConLevel icl
Consistency level.
Definition: int.hh:226
ChannelFull cfd11(1, 1, Gecode::ICL_DOM)
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:157
ChannelFull cfv35(3, 5, Gecode::ICL_VAL)
ChannelFull cfv11(1, 1, Gecode::ICL_VAL)
ChannelLinkMulti clmb("B", 1, 6, 1)
Test channel with shared variables
Definition: channel.cpp:127
ChannelLinkMulti clmc("C",-1, 4,-1)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:73
Passing integer variables.
Definition: int.hh:636
Passing Boolean variables.
Definition: int.hh:690
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:161
Boolean integer variables.
Definition: int.hh:491
General test support.
Definition: afc.cpp:43
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:113
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ChannelLinkMulti clma("A", 0, 5, 0)
Base class for assignments
Definition: int.hh:63
Integer variables.
Definition: int.hh:350
ChannelHalf(Gecode::IntConLevel icl)
Construct and register test.
Definition: channel.cpp:100
void channel(Home home, const SetVarArgs &x, const SetVarArgs &y)
Post propagator for .
Definition: channel.cpp:76
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:105
ChannelHalf chd(Gecode::ICL_DOM)
ChannelFull cfd(0, 0, Gecode::ICL_DOM)
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
ChannelShared csd(Gecode::ICL_DOM)
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
ChannelLinkSingle(void)
Construct and register test.
Definition: channel.cpp:152
ChannelFull(int xoff0, int yoff0, Gecode::IntConLevel icl)
Construct and register test.
Definition: channel.cpp:59
int size(void) const
Return number of variables.
Definition: int.hpp:50
Test channel between integer and Boolean variable
Definition: channel.cpp:149
Domain propagation or consistency.
Definition: int.hh:940
ChannelLinkMulti(const std::string &s, int min, int max, int o0)
Construct and register test.
Definition: channel.cpp:175
ChannelHalf chv(Gecode::ICL_VAL)