Generated on Sat Jul 29 2017 12:41:24 for Gecode by doxygen 1.8.13
count.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, 2005
8  *
9  * Last modified:
10  * $Date: 2015-09-11 16:29:45 +0200 (Fri, 11 Sep 2015) $ by $Author: schulte $
11  * $Revision: 14672 $
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 namespace Test { namespace Int {
41 
43  namespace Count {
44 
50  class IntInt : public Test {
52  protected:
55  public:
58  : Test("Count::Int::Int::"+str(irt0),4,-2,2), irt(irt0) {}
60  virtual bool solution(const Assignment& x) const {
61  int m = 0;
62  for (int i=x.size(); i--; )
63  if (x[i] == 0)
64  m++;
65  return cmp(m,irt,2);
66  }
68  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
69  Gecode::count(home, x, 0, irt, 2);
70  }
71  };
72 
74  class SetInt : public Test {
75  protected:
78  public:
81  : Test("Count::Set::Int::"+str(irt0),4,-2,2), irt(irt0) {}
83  virtual bool solution(const Assignment& x) const {
84  int m = 0;
85  for (int i=x.size(); i--; )
86  if ((x[i] >= -1) && (x[i] <= 1))
87  m++;
88  return cmp(m,irt,2);
89  }
91  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
92  Gecode::IntSet s(-1,1);
93  Gecode::count(home, x, s, irt, 2);
94  }
95  };
96 
98  class IntIntDup : public Test {
99  protected:
102  public:
105  : Test("Count::Int::Int::Dup::"+str(irt0),4,-2,2), irt(irt0) {}
107  virtual bool solution(const Assignment& x) const {
108  int m = 0;
109  for (int i=x.size(); i--; )
110  if (x[i] == 0)
111  m += 2;
112  return cmp(m,irt,4);
113  }
115  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
117  for (int i=x.size(); i--; )
118  y[i]=y[4+i]=x[i];
119  Gecode::count(home, y, 0, irt, 4);
120  }
121  };
122 
124  class IntVar : public Test {
125  protected:
128  public:
131  : Test("Count::Int::Var::"+str(irt0),5,-2,2), irt(irt0) {}
133  virtual bool solution(const Assignment& x) const {
134  int m = 0;
135  for (int i=0; i<4; i++)
136  if (x[i] == 0)
137  m++;
138  return cmp(m,irt,x[4]);
139  }
141  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
143  for (int i=0; i<4; i++)
144  y[i]=x[i];
145  Gecode::count(home, y, 0, irt, x[4]);
146  }
147  };
148 
150  class SetVar : public Test {
151  protected:
154  public:
157  : Test("Count::Set::Var::"+str(irt0),5,-2,2), irt(irt0) {}
159  virtual bool solution(const Assignment& x) const {
160  int m = 0;
161  for (int i=0; i<4; i++)
162  if ((x[i] >= -1) && (x[i] <= 1))
163  m++;
164  return cmp(m,irt,x[4]);
165  }
167  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
169  for (int i=0; i<4; i++)
170  y[i]=x[i];
171  Gecode::IntSet s(-1,1);
172  Gecode::count(home, y, s, irt, x[4]);
173  }
174  };
175 
176  Gecode::IntArgs ints(4, 1,0,3,2);
177 
179  class IntArrayInt : public Test {
180  protected:
183  public:
186  : Test("Count::IntArray::Int::"+str(irt0),5,-2,2), irt(irt0) {}
188  virtual bool solution(const Assignment& x) const {
189  int m = 0;
190  for (int i=0; i<4; i++)
191  if (x[i] == ints[i])
192  m++;
193  return cmp(m,irt,2);
194  }
196  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
198  for (int i=0; i<4; i++)
199  y[i]=x[i];
200  Gecode::count(home, y, ints, irt, 2);
201  }
202  };
203 
205  class IntArrayVar : public Test {
206  protected:
209  public:
212  : Test("Count::IntArray::Var::"+str(irt0),5,-2,2), irt(irt0) {}
214  virtual bool solution(const Assignment& x) const {
215  int m = 0;
216  for (int i=0; i<4; i++)
217  if (x[i] == ints[i])
218  m++;
219  return cmp(m,irt,x[4]);
220  }
222  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
224  for (int i=0; i<4; i++)
225  y[i]=x[i];
226  Gecode::count(home, y, ints, irt, x[4]);
227  }
228  };
229 
231  class IntVarShared : public Test {
232  protected:
235  public:
238  : Test("Count::Int::Var::Shared::"+str(irt0),4,-2,2), irt(irt0) {}
240  virtual bool solution(const Assignment& x) const {
241  int m = 0;
242  for (int i=0; i<4; i++)
243  if (x[i] == 0)
244  m++;
245  return cmp(m,irt,x[2]);
246  }
248  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
249  Gecode::count(home, x, 0, irt, x[2]);
250  }
251  };
252 
254  class VarVar : public Test {
255  protected:
258  public:
261  : Test("Count::Var::Var::"+str(irt0)+"::"+str(ipl),5,-2,2,false,ipl),
262  irt(irt0) {
263  contest = CTL_NONE;
264  }
266  virtual bool solution(const Assignment& x) const {
267  int m = 0;
268  for (int i=0; i<3; i++)
269  if (x[i] == x[3])
270  m++;
271  return cmp(m,irt,x[4]);
272  }
274  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
276  for (int i=0; i<3; i++)
277  y[i]=x[i];
278  Gecode::count(home, y, x[3], irt, x[4], ipl);
279  }
280  };
281 
283  class VarInt : public Test {
284  protected:
287  public:
290  : Test("Count::Var::Int::"+str(irt0)+"::"+str(ipl),4,-2,2,false,ipl),
291  irt(irt0) {
292  contest = CTL_NONE;
293  }
295  virtual bool solution(const Assignment& x) const {
296  int m = 0;
297  for (int i=0; i<3; i++)
298  if (x[i] == x[3])
299  m++;
300  return cmp(m,irt,2);
301  }
303  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
305  for (int i=0; i<3; i++)
306  y[i]=x[i];
307  Gecode::count(home, y, x[3], irt, 2, ipl);
308  }
309  };
310 
312  class VarVarSharedA : public Test {
313  protected:
316  public:
319  : Test("Count::Var::Var::Shared::A::"+str(irt0),5,-2,2), irt(irt0) {}
321  virtual bool solution(const Assignment& x) const {
322  int m = 0;
323  for (int i=0; i<4; i++)
324  if (x[i] == x[1])
325  m++;
326  return cmp(m,irt,x[4]);
327  }
329  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
331  for (int i=0; i<4; i++)
332  y[i]=x[i];
333  Gecode::count(home, y, x[1], irt, x[4]);
334  }
335  };
336 
338  class VarVarSharedB : public Test {
339  protected:
342  public:
345  : Test("Count::Var::Var::Shared::B::"+str(irt0),5,-2,2), irt(irt0) {}
347  virtual bool solution(const Assignment& x) const {
348  int m = 0;
349  for (int i=0; i<4; i++)
350  if (x[i] == x[4])
351  m++;
352  return cmp(m,irt,x[3]);
353  }
355  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
357  for (int i=0; i<4; i++)
358  y[i]=x[i];
359  Gecode::count(home, y, x[4], irt, x[3]);
360  }
361  };
362 
364  class VarVarSharedC : public Test {
365  protected:
368  public:
371  : Test("Count::Var::Var::Shared::C::"+str(irt0),4,-2,2), irt(irt0) {}
373  virtual bool solution(const Assignment& x) const {
374  int m = 0;
375  for (int i=0; i<4; i++)
376  if (x[i] == x[1])
377  m++;
378  return cmp(m,irt,x[3]);
379  }
381  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
382  Gecode::count(home, x, x[1], irt, x[3]);
383  }
384  };
385 
387  class Create {
388  public:
390  Create(void) {
391  for (IntRelTypes irts; irts(); ++irts) {
392  (void) new IntInt(irts.irt());
393  (void) new SetInt(irts.irt());
394  (void) new IntIntDup(irts.irt());
395  (void) new IntVar(irts.irt());
396  (void) new SetVar(irts.irt());
397  (void) new IntArrayInt(irts.irt());
398  (void) new IntArrayVar(irts.irt());
399  (void) new IntVarShared(irts.irt());
400  (void) new VarVar(irts.irt(), Gecode::IPL_BND);
401  (void) new VarVar(irts.irt(), Gecode::IPL_DOM);
402  (void) new VarInt(irts.irt(), Gecode::IPL_BND);
403  (void) new VarInt(irts.irt(), Gecode::IPL_DOM);
404  (void) new VarVarSharedA(irts.irt());
405  (void) new VarVarSharedB(irts.irt());
406  (void) new VarVarSharedC(irts.irt());
407  }
408  }
409  };
410 
413 
414  }
415 }}
416 
417 // STATISTICS: test-int
418 
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:329
VarVar(Gecode::IntRelType irt0, Gecode::IntPropLevel ipl)
Create and register test.
Definition: count.cpp:260
Bounds propagation.
Definition: int.hh:959
Test number of equal variables equal to integer variable with sharing
Definition: count.cpp:364
IntArrayVar(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:211
VarVarSharedA(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:318
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:212
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:141
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:381
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:222
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:60
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:341
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:248
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
Definition: count.cpp:44
Test number of several equal integers equal to integer
Definition: count.cpp:179
int size(void) const
Return number of variables.
Definition: int.hpp:50
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:153
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition: int.hpp:279
Test number of integers contained in an integer set equal to integer
Definition: count.cpp:74
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:188
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:347
Test number of equal integers equal to integer
Definition: count.cpp:51
Test number of equal variables equal to integer variable with sharing
Definition: count.cpp:338
VarVarSharedC(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:370
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:274
Integer variable array.
Definition: int.hh:744
Test number of several equal integers equal to integer variable
Definition: count.cpp:205
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:373
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:321
Test number of equal variables equal to integer
Definition: count.cpp:283
ConTestLevel contest
Whether to test for certain consistency.
Definition: int.hh:240
Computation spaces.
Definition: core.hpp:1748
Gecode::IntArgs ints(4, 1, 0, 3, 2)
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:367
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:315
SetVar(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:156
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:133
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:159
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:303
Help class to create and register tests.
Definition: count.cpp:387
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:214
Create(void)
Perform creation and registration.
Definition: count.cpp:390
No consistency-test.
Definition: int.hh:144
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:115
IntRelType
Relation types for integers.
Definition: int.hh:906
IntVarShared(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:237
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:234
IntIntDup(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:104
Iterator for integer relation types.
Definition: int.hh:370
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:107
Test number of equal integers equal to integer variable
Definition: count.cpp:124
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:77
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:257
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:208
Integer sets.
Definition: int.hh:174
IntArrayInt(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:185
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:238
Passing integer variables.
Definition: int.hh:639
Test number of integers contained in an integer set equal to integer variable
Definition: count.cpp:150
Passing integer arguments.
Definition: int.hh:610
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:68
General test support.
Definition: afc.cpp:43
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:955
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:295
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:83
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:266
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Test number of equal variables equal to integer variable
Definition: count.cpp:254
Base class for assignments
Definition: int.hh:63
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:127
Domain propagation Preferences: prefer speed or memory.
Definition: int.hh:960
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:54
Test number of equal integers equal to integer variable with sharing
Definition: count.cpp:231
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:167
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:196
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:182
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:286
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: count.cpp:240
VarVarSharedB(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:344
Gecode::IntRelType irt
Integer relation type to propagate.
Definition: count.cpp:101
SetInt(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:80
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:91
VarInt(Gecode::IntRelType irt0, Gecode::IntPropLevel ipl)
Create and register test.
Definition: count.cpp:289
IntVar(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:130
Test number of equal integers equal to integer with duplicate variables
Definition: count.cpp:98
IntInt(Gecode::IntRelType irt0)
Create and register test.
Definition: count.cpp:57
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: count.cpp:355
Test number of equal variables equal to integer variable with sharing
Definition: count.cpp:312