Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
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 
38 namespace Test { namespace Int {
39 
41  namespace Channel {
42 
48  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("Channel::Full::"+str(xoff0)+"::"+str(yoff0)+"::"+str(ipl),
57  8,0,3,false,ipl),
58  xoff(xoff0), yoff(yoff0) {
59  contest = CTL_NONE;
60  }
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  }
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("Channel::Half::"+str(ipl),6,0,5,false,ipl) {
98  contest = CTL_NONE;
99  }
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  }
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("Channel::Shared::"+str(ipl),6,0,5,false,ipl) {
128  contest = CTL_NONE;
129  }
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  }
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("Channel::Bool::Single",2,-1,2) {
150  contest = CTL_NONE;
151  }
153  virtual bool solution(const Assignment& x) const {
154  return ((x[0]==0) || (x[0]==1)) && (x[0]==x[1]);
155  }
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(const std::string& s, int min, int max, int o0)
172  : Test("Channel::Bool::Multi::"+s,7,min,max), o(o0) {
173  }
175  virtual bool solution(const Assignment& x) const {
176  int n = x.size()-1;
177  for (int i=n; i--; )
178  if ((x[i] != 0) && (x[i] != 1))
179  return false;
180  int k=x[n]-o;
181  if ((k<0) || (k>=n))
182  return false;
183  for (int i=0; i<k; i++)
184  if (x[i] != 0)
185  return false;
186  for (int i=k+1; i<n; i++)
187  if (x[i] != 0)
188  return false;
189  return x[k] == 1;
190  }
192  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
193  using namespace Gecode;
194  int n=x.size()-1;
196  for (int i=n; i--; )
197  b[i]=channel(home,x[i]);
198  channel(home, b, x[n], o);
199  }
200  };
201 
202 
203 
206 
209 
212 
215 
218 
220 
221  ChannelLinkMulti clma("A", 0, 5, 0);
222  ChannelLinkMulti clmb("B", 1, 6, 1);
223  ChannelLinkMulti clmc("C",-1, 4,-1);
225 
226  }
227 }}
228 
229 // STATISTICS: test-int
230 
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
ChannelLinkMulti clmb("B", 1, 6, 1)
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
ChannelFull cfd35(3, 5, Gecode::IPL_DOM)
ConTestLevel contest
Whether to test for certain consistency.
Definition: int.hh:236
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:153
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:234
Passing integer variables.
Definition: int.hh:656
ChannelShared(Gecode::IntPropLevel ipl)
Construct and register test.
Definition: channel.cpp:126
@ CTL_NONE
No consistency-test.
Definition: int.hh:140
Test channel between integer and Boolean variable
Definition: channel.cpp:145
@ IPL_VAL
Value propagation.
Definition: int.hh:977
const FloatNum min
Smallest allowed float value.
Definition: float.hh:846
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
Computation spaces.
Definition: core.hpp:1742
ChannelShared csd(Gecode::IPL_DOM)
ChannelLinkSingle cls
Definition: channel.cpp:219
Integer variable array.
Definition: int.hh:763
Simple test for channel (testing single set of variables)
Definition: channel.cpp:93
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:62
ChannelFull cfd11(1, 1, Gecode::IPL_DOM)
Gecode toplevel namespace
ChannelHalf chd(Gecode::IPL_DOM)
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:138
Passing Boolean variables.
Definition: int.hh:712
ChannelLinkMulti clmc("C",-1, 4,-1)
ChannelLinkMulti(const std::string &s, int min, int max, int o0)
Construct and register test.
Definition: channel.cpp:171
Boolean integer variables.
Definition: int.hh:512
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:979
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Simple test for channel (testing all variables)
Definition: channel.cpp:49
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:175
Integer variables.
Definition: int.hh:371
ChannelFull cfv35(3, 5, Gecode::IPL_VAL)
Test channel with shared variables
Definition: channel.cpp:123
ChannelFull cfv11(1, 1, Gecode::IPL_VAL)
ChannelHalf chv(Gecode::IPL_VAL)
ChannelShared csv(Gecode::IPL_VAL)
Base class for assignments
Definition: int.hh:59
ChannelHalf(Gecode::IntPropLevel ipl)
Construct and register test.
Definition: channel.cpp:96
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
Test channel between integer variable and array of Boolean variables
Definition: channel.cpp:166
General test support.
Definition: afc.cpp:39
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:131
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:109
@ IRT_EQ
Equality ( )
Definition: int.hh:926
ChannelFull(int xoff0, int yoff0, Gecode::IntPropLevel ipl)
Construct and register test.
Definition: channel.cpp:55
ChannelFull cfd(0, 0, Gecode::IPL_DOM)
virtual bool solution(const Assignment &x) const
Check whether x is solution.
Definition: channel.cpp:101
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: channel.cpp:192
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
const FloatNum max
Largest allowed float value.
Definition: float.hh:844
ChannelLinkMulti clma("A", 0, 5, 0)
ChannelFull cfv(0, 0, Gecode::IPL_VAL)
void channel(Home home, const SetVarArgs &x, const SetVarArgs &y)
Definition: channel.cpp:72
Gecode::IntSet dom
Domain of variables.
Definition: int.hh:228
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:209