Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.1
distinct.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.org>
5  *
6  * Copyright:
7  * Guido Tack, 2005
8  *
9  * Last modified:
10  * $Date: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $
11  * $Revision: 10684 $
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/set.hh"
39 
40 using namespace Gecode;
41 
42 namespace Test { namespace Set {
43 
45  namespace Distinct {
46 
52 
53  static IntSet ds_33(-2,2);
54  static IntSet ds_44(-4,4);
55 
57  class AtmostOne : public SetTest {
58  public:
60  AtmostOne(const char* t)
61  : SetTest(t,3,ds_33,false) {}
63  virtual bool solution(const SetAssignment& x) const {
64  {
65  CountableSetRanges xr0(x.lub, x[0]);
66  CountableSetRanges xr1(x.lub, x[1]);
68  i(xr0,xr1);
69  if (Iter::Ranges::size(i)>1)
70  return false;
71  }
72  {
73  CountableSetRanges xr0(x.lub, x[0]);
74  CountableSetRanges xr2(x.lub, x[2]);
76  i(xr0,xr2);
77  if (Iter::Ranges::size(i)>1)
78  return false;
79  }
80  {
81  CountableSetRanges xr1(x.lub, x[1]);
82  CountableSetRanges xr2(x.lub, x[2]);
84  i(xr1,xr2);
85  if (Iter::Ranges::size(i)>1)
86  return false;
87  }
88  {
89  CountableSetRanges xr0(x.lub, x[0]);
90  CountableSetRanges xr1(x.lub, x[1]);
91  CountableSetRanges xr2(x.lub, x[2]);
92  if (Iter::Ranges::size(xr0)!=3 ||
93  Iter::Ranges::size(xr1)!=3 ||
94  Iter::Ranges::size(xr2)!=3)
95  return false;
96  }
97  return true;
98  }
100  virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
101  SetVar s1(home, IntSet::empty, -2, 2, 0,1);
102  Gecode::rel(home, x[0], SOT_INTER, x[1], SRT_EQ, s1);
103  SetVar s2(home, IntSet::empty, -2, 2, 0,1);
104  Gecode::rel(home, x[0], SOT_INTER, x[2], SRT_EQ, s2);
105  SetVar s3(home, IntSet::empty, -2, 2, 0,1);
106  Gecode::rel(home, x[1], SOT_INTER, x[2], SRT_EQ, s3);
107  Gecode::atmostOne(home, x, 3);
108  }
109  };
110  AtmostOne _atmostone("Distinct::AtmostOne");
111 
113 
114 }}}
115 
116 // STATISTICS: test-set
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Propagator for negated equality
Definition: rel.hh:261
AtmostOne(const char *t)
Create and register test.
Definition: distinct.cpp:60
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition: distinct.cpp:100
Test for the atmostone propagator
Definition: distinct.cpp:57
AtmostOne _atmostone("Distinct::AtmostOne")
void atmostOne(Home home, const SetVarArgs &xa, unsigned int c)
Post propagator for and .
Definition: distinct.cpp:45
Integer variable array.
Definition: int.hh:741
Computation spaces.
Definition: core.hpp:1362
Gecode::IntArgs i(4, 1, 2, 3, 4)
Range iterator for computing intersection (binary)
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::IntSet lub
The common superset for all domains.
Definition: set.hh:170
Intersection
Definition: set.hh:664
Integer sets.
Definition: int.hh:171
static const IntSet empty
Empty set.
Definition: int.hh:262
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition: distinct.cpp:63
General test support.
Definition: afc.cpp:43
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
Base class for tests with set constraints
Definition: set.hh:271
Generate all set assignments.
Definition: set.hh:158
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
Range iterator producing subsets of an IntSet.
Definition: set.hh:114
Equality ( )
Definition: set.hh:645
Set variable array
Definition: set.hh:571
Gecode toplevel namespace