Generated on Mon Sep 17 2012 22:20:41 for Gecode by doxygen 1.8.1.1
rel.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: 2011-08-25 00:34:16 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $
11  * $Revision: 12346 $
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 Rel {
46 
52 
53  static IntSet ds_33(-3,3);
54 
56  class RelBin : public SetTest {
57  private:
59  bool shared;
60  public:
62  RelBin(Gecode::SetRelType srt0, bool shared0)
63  : SetTest("Rel::Bin::"+str(srt0)+"::S"+(shared0 ? "1":"0"),
64  shared ? 1 : 2,ds_33,true)
65  , srt(srt0), shared(shared0){}
66  int minSymDiff(const SetAssignment& x) const {
67  int x1 = shared ? x[0] : x[1];
69  CountableSetRanges xr00(x.lub, x[0]);
70  CountableSetRanges xr10(x.lub, x1);
71  Diff a(xr00,xr10);
72  CountableSetRanges xr01(x.lub, x[0]);
73  CountableSetRanges xr11(x.lub, x1);
74  Diff b(xr11,xr01);
76  return u() ? u.min() : Gecode::Set::Limits::max+1;
77  }
78  bool in(int i, CountableSetRanges& c, bool eq=false) const {
79  if (eq && i==Gecode::Set::Limits::max+1)
80  return true;
82  return Iter::Ranges::subset(s,c);
83  }
85  bool solution(const SetAssignment& x) const {
86  int x1 = shared ? x[0] : x[1];
87  CountableSetRanges xr0(x.lub, x[0]);
88  CountableSetRanges xr1(x.lub, x1);
89  switch (srt) {
90  case SRT_EQ: return Iter::Ranges::equal(xr0, xr1);
91  case SRT_NQ: return !Iter::Ranges::equal(xr0, xr1);
92 
93  case SRT_LQ: return (!xr0()) || in(minSymDiff(x),xr1,true);
94  case SRT_LE: return xr0() ? in(minSymDiff(x),xr1) : xr1();
95  case SRT_GQ: return (!xr1()) || in(minSymDiff(x),xr0,true);
96  case SRT_GR: return xr1() ? in(minSymDiff(x),xr0) : xr0();
97 
98  case SRT_SUB: return Iter::Ranges::subset(xr0, xr1);
99  case SRT_SUP: return Iter::Ranges::subset(xr1, xr0);
100  case SRT_DISJ:
101  {
103  inter(xr0,xr1);
104  return !inter();
105  }
106  case SRT_CMPL:
107  {
109  return Iter::Ranges::equal(rc,xr1);
110  }
111  default:
112  GECODE_NEVER;
113  }
114  GECODE_NEVER;
115  return false;
116  }
118  void post(Space& home, SetVarArray& x, IntVarArray&) {
119  if (!shared)
120  Gecode::rel(home, x[0], srt, x[1]);
121  else
122  Gecode::rel(home, x[0], srt, x[0]);
123  }
125  void post(Space& home, SetVarArray& x, IntVarArray&, BoolVar b) {
126  if (!shared)
127  Gecode::rel(home, x[0], srt, x[1], b);
128  else
129  Gecode::rel(home, x[0], srt, x[0], b);
130  }
131  };
132  RelBin _relbin_eq(Gecode::SRT_EQ,false);
133  RelBin _relbin_lq(Gecode::SRT_LQ,false);
134  RelBin _relbin_le(Gecode::SRT_LE,false);
135  RelBin _relbin_gq(Gecode::SRT_GQ,false);
136  RelBin _relbin_gr(Gecode::SRT_GR,false);
137  RelBin _relbin_nq(Gecode::SRT_NQ,false);
138  RelBin _relbin_sub(Gecode::SRT_SUB,false);
139  RelBin _relbin_sup(Gecode::SRT_SUP,false);
140  RelBin _relbin_disj(Gecode::SRT_DISJ,false);
141  RelBin _relbin_cmpl(Gecode::SRT_CMPL,false);
142  RelBin _relbin_shared_eq(Gecode::SRT_EQ,true);
143  RelBin _relbin_shared_lq(Gecode::SRT_LQ,true);
144  RelBin _relbin_shared_le(Gecode::SRT_LE,true);
145  RelBin _relbin_shared_gq(Gecode::SRT_GQ,true);
146  RelBin _relbin_shared_gr(Gecode::SRT_GR,true);
147  RelBin _relbin_shared_nq(Gecode::SRT_NQ,true);
148  RelBin _relbin_shared_sub(Gecode::SRT_SUB,true);
149  RelBin _relbin_shared_sup(Gecode::SRT_SUP,true);
152 
154 
155 }}}
156 
157 // STATISTICS: test-set