Generated on Tue Mar 5 2013 22:37:17 for Gecode by doxygen 1.8.3.1
select-val.hpp
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  * Christian Schulte <schulte@gecode.org>
6  *
7  * Contributing authors:
8  * Gabor Szokoli <szokoli@gecode.org>
9  *
10  * Copyright:
11  * Guido Tack, 2004
12  * Christian Schulte, 2004
13  * Gabor Szokoli, 2004
14  *
15  * Last modified:
16  * $Date: 2011-05-11 20:44:17 +1000 (Wed, 11 May 2011) $ by $Author: tack $
17  * $Revision: 12001 $
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 namespace Gecode { namespace Set { namespace Branch {
45 
46  template<bool inc>
49  template<bool inc>
52  : ValSelBase<SetView,int>(home,vbo) {}
53  template<bool inc>
54  forceinline int
57  return u.min();
58  }
59  template<bool inc>
61  ValMin<inc>::tell(Space& home, unsigned int a, SetView x, int v) {
62  return ((a == 0) == inc) ? x.include(home,v) : x.exclude(home,v);
63  }
64 
65 
66  template<bool inc>
69  template<bool inc>
72  : ValSelBase<SetView,int>(home,vbo) {}
73  template<bool inc>
74  forceinline int
77  unsigned int i = Iter::Ranges::size(u1) / 2;
79  int med = (u2.min()+u2.max()) / 2;
80  ++u2;
81  if (!u2()) {
82  return med;
83  }
85  while (i >= u3.width()) {
86  i -= u3.width();
87  ++u3;
88  }
89  return u3.min() + static_cast<int>(i);
90  }
91  template<bool inc>
93  ValMed<inc>::tell(Space& home, unsigned int a, SetView x, int v) {
94  return ((a == 0) == inc) ? x.include(home,v) : x.exclude(home,v);
95  }
96 
97  template<bool inc>
100  template<bool inc>
103  : ValSelBase<SetView,int>(home,vbo) {}
104  template<bool inc>
105  forceinline int
107  int max = 0;
108  for (UnknownRanges<SetView> u(x); u(); ++u)
109  max = u.max();
110  return max;
111  }
112  template<bool inc>
114  ValMax<inc>::tell(Space& home, unsigned int a, SetView x, int v) {
115  return ((a == 0) == inc) ? x.include(home,v) : x.exclude(home,v);
116  }
117 
118 
119  template<bool inc>
122  template<bool inc>
125  : r(vbo.seed) {}
126  template<bool inc>
127  forceinline int
130  unsigned int p = r(Iter::Ranges::size(u));
131  for (UnknownRanges<SetView> i(x); i(); ++i) {
132  if (i.width() > p)
133  return i.min() + static_cast<int>(p);
134  p -= i.width();
135  }
136  GECODE_NEVER;
137  return 0;
138  }
139  template<bool inc>
141  ValRnd<inc>::tell(Space& home, unsigned int a, SetView x, int v) {
142  return ((a == 0) == inc) ? x.include(home,v) : x.exclude(home,v);
143  }
144  template<bool inc>
147  return r;
148  }
149  template<bool inc>
152  return Choice(e.get());
153  }
154  template<bool inc>
155  forceinline void
157  unsigned int) {
158  r = c;
159  }
160  template<bool inc>
161  forceinline void
163  r = vr.r;
164  }
165  template<bool inc>
166  forceinline void
168 
169 
170  template<bool inc>
173  template<bool inc>
176  : ValMin<inc>(home,vbo) {}
177 
178  template<bool inc>
181  template<bool inc>
184  : ValMed<inc>(home,vbo) {}
185 
186  template<bool inc>
189  template<bool inc>
192  : ValMax<inc>(home,vbo) {}
193 
194  template<bool inc>
197  template<bool inc>
200  : ValRnd<inc>(home,vbo) {}
201 
202 }}}
203 
204 // STATISTICS: set-branch