Generated on Mon Aug 27 2012 17:15:38 for Gecode by doxygen 1.8.1.2
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  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2002
8  *
9  * Last modified:
10  * $Date: 2011-05-11 20:44:17 +1000 (Wed, 11 May 2011) $ by $Author: tack $
11  * $Revision: 12001 $
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 namespace Gecode { namespace Int { namespace Branch {
39 
40  template<class View>
43  template<class View>
46  : ValSelBase<View,int>(home,vbo) {}
47  template<class View>
48  forceinline int
50  return x.min();
51  }
52  template<class View>
54  ValMin<View>::tell(Space& home, unsigned int a, View x, int n) {
55  return (a == 0) ? x.eq(home,n) : x.gr(home,n);
56  }
57 
58  template<class View>
61  template<class View>
64  : ValSelBase<View,int>(home,vbo) {}
65  template<class View>
66  forceinline int
68  return x.med();
69  }
70  template<class View>
72  ValMed<View>::tell(Space& home, unsigned int a, View x, int n) {
73  return (a == 0) ? x.eq(home,n) : x.nq(home,n);
74  }
75 
76 
77  template<class View>
80  template<class View>
83  : r(vbo.seed) {}
84  template<class View>
85  forceinline int
87  unsigned int p = r(x.size());
88  for (ViewRanges<View> i(x); i(); ++i) {
89  if (i.width() > p)
90  return i.min() + static_cast<int>(p);
91  p -= i.width();
92  }
94  return 0;
95  }
96  template<class View>
98  ValRnd<View>::tell(Space& home, unsigned int a, View x, int n) {
99  return (a == 0) ? x.eq(home,n) : x.nq(home,n);
100  }
101  template<class View>
104  return r;
105  }
106  template<class View>
109  return Choice(e.get());
110  }
111  template<class View>
112  forceinline void
113  ValRnd<View>::commit(Space&, const Choice& c, unsigned int) {
114  r = c;
115  }
116  template<class View>
117  forceinline void
119  r = vr.r;
120  }
121  template<class View>
122  forceinline void
124 
125 
126  template<class View>
129  template<class View>
132  const ValBranchOptions& vbo)
133  : ValSelBase<View,int>(home,vbo) {}
134  template<class View>
135  forceinline int
137  return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2);
138  }
139  template<class View>
141  ValSplitMin<View>::tell(Space& home, unsigned int a, View x, int n) {
142  return (a == 0) ? x.lq(home,n) : x.gr(home,n);
143  }
144 
145 
146  template<class View>
149  template<class View>
152  const ValBranchOptions& vbo)
153  : ValSelBase<View,int>(home,vbo) {}
154  template<class View>
155  forceinline int
157  if (x.range()) {
158  return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2);
159  } else {
160  ViewRanges<View> r(x);
161  return r.max();
162  }
163  }
164  template<class View>
166  ValRangeMin<View>::tell(Space& home, unsigned int a, View x, int n) {
167  return (a == 0) ? x.lq(home,n) : x.gr(home,n);
168  }
169 
170 
171  template<class View>
174  template<class View>
177  : ValSelBase<View,NoValue>(home,vbo) {}
178  template<class View>
181  NoValue n; return n;
182  }
183  template<class View>
185  ValZeroOne<View>::tell(Space& home, unsigned int a, View x, NoValue) {
186  return (a == 0) ? x.zero(home) : x.one(home);
187  }
188 
189 
190  template<class View>
193  template<class View>
196  : ValMin<View>(home,vbo) {}
197 
198 
199  template<class View>
202  template<class View>
205  : ValMed<View>(home,vbo) {}
206 
207 
208  template<class View>
211  template<class View>
214  : ValRnd<View>(home,vbo) {}
215 
216 
217  template<class View>
220  template<class View>
223  const ValBranchOptions& vbo)
224  : ValZeroOne<View>(home,vbo) {}
225 
226 }}}
227 
228 // STATISTICS: int-branch
229