Generated on Sun Aug 26 2012 08:42:46 for Gecode by doxygen 1.8.1.1
select-view.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: 2009-10-14 06:12:58 +1100 (Wed, 14 Oct 2009) $ by $Author: schulte $
17  * $Revision: 9897 $
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 
47  BySizeMin::BySizeMin(void) : size(0U) {}
50  : ViewSelBase<SetView>(home,vbo), size(0U) {}
53  size = x.unknownSize();
54  return (size == 1) ? VSS_BEST : VSS_BETTER;
55  }
58  unsigned int us = x.unknownSize();
59  if (us < size) {
60  size = us;
61  return (size == 1) ? VSS_BEST : VSS_BETTER;
62  } else if (us > size) {
63  return VSS_WORSE;
64  } else {
65  return VSS_TIE;
66  }
67  }
68 
69 
71  BySizeMax::BySizeMax(void) : size(0U) {}
74  : ViewSelBase<SetView>(home,vbo), size(0U) {}
77  size = x.unknownSize();
78  return VSS_BETTER;
79  }
82  unsigned int us = x.unknownSize();
83  if (us > size) {
84  size = us;
85  return VSS_BETTER;
86  } else if (us < size) {
87  return VSS_WORSE;
88  } else {
89  return VSS_TIE;
90  }
91  }
92 
93 
95  ByMinMin::ByMinMin(void) : min(0) {}
98  : ViewSelBase<SetView>(home,vbo), min(0) {}
102  min = u.min();
103  return VSS_BETTER;
104  }
108  if (u.min() < min) {
109  min = u.min(); return VSS_BETTER;
110  } else if (u.min() > min) {
111  return VSS_WORSE;
112  } else {
113  return VSS_TIE;
114  }
115  }
116 
117 
119  ByMinMax::ByMinMax(void) : min(0) {}
122  : ViewSelBase<SetView>(home,vbo), min(0) {}
126  min = u.min();
127  return VSS_BETTER;
128  }
132  if (u.min() > min) {
133  min = u.min(); return VSS_BETTER;
134  } else if (u.min() < min) {
135  return VSS_WORSE;
136  } else {
137  return VSS_TIE;
138  }
139  }
140 
141 
143  ByMaxMin::ByMaxMin(void) : max(0) {}
146  : ViewSelBase<SetView>(home,vbo), max(0) {}
149  for (UnknownRanges<SetView> u(x); u(); ++u)
150  max = u.max();
151  return VSS_BETTER;
152  }
155  int um = 0;
156  for (UnknownRanges<SetView> u(x); u(); ++u)
157  um = u.max();
158  if (um < max) {
159  max = um; return VSS_BETTER;
160  } else if (um > max) {
161  return VSS_WORSE;
162  } else {
163  return VSS_TIE;
164  }
165  }
166 
167 
169  ByMaxMax::ByMaxMax(void) : max(0) {}
172  : ViewSelBase<SetView>(home,vbo), max(0) {}
175  for (UnknownRanges<SetView> u(x); u(); ++u)
176  max = u.max();
177  return VSS_BETTER;
178  }
181  int um = 0;
182  for (UnknownRanges<SetView> u(x); u(); ++u)
183  um = u.max();
184  if (um > max) {
185  max = um; return VSS_BETTER;
186  } else if (um < max) {
187  return VSS_WORSE;
188  } else {
189  return VSS_TIE;
190  }
191  }
192 
193 
194  // Select variable with smallest size/degree
196  BySizeDegreeMin::BySizeDegreeMin(void) : sizedegree(0) {}
199  : ViewSelBase<SetView>(home,vbo), sizedegree(0) {}
203  sizedegree =
204  static_cast<double>(Iter::Ranges::size(u))/
205  static_cast<double>(x.degree());
206  return VSS_BETTER;
207  }
211  double sd =
212  static_cast<double>(Iter::Ranges::size(u))/
213  static_cast<double>(x.degree());
214  if (sd < sizedegree) {
215  sizedegree = sd; return VSS_BETTER;
216  } else if (sd > sizedegree) {
217  return VSS_WORSE;
218  } else {
219  return VSS_TIE;
220  }
221  }
222 
223 
224  // Select variable with largest size/degree
226  BySizeDegreeMax::BySizeDegreeMax(void) : sizedegree(0) {}
229  : ViewSelBase<SetView>(home,vbo), sizedegree(0) {}
233  sizedegree =
234  static_cast<double>(Iter::Ranges::size(u))/
235  static_cast<double>(x.degree());
236  return VSS_BETTER;
237  }
241  double sd =
242  static_cast<double>(Iter::Ranges::size(u))/
243  static_cast<double>(x.degree());
244  if (sd > sizedegree) {
245  sizedegree = sd; return VSS_BETTER;
246  } else if (sd < sizedegree) {
247  return VSS_WORSE;
248  } else {
249  return VSS_TIE;
250  }
251  }
252 
253  // Select variable with smallest size/afc
255  BySizeAfcMin::BySizeAfcMin(void) : sizeafc(0) {}
258  : ViewSelBase<SetView>(home,vbo), sizeafc(0) {}
262  sizeafc = static_cast<double>(Iter::Ranges::size(u))/x.afc();
263  return VSS_BETTER;
264  }
268  double sa = static_cast<double>(Iter::Ranges::size(u))/x.afc();
269  if (sa < sizeafc) {
270  sizeafc = sa; return VSS_BETTER;
271  } else if (sa > sizeafc) {
272  return VSS_WORSE;
273  } else {
274  return VSS_TIE;
275  }
276  }
277 
278 
279  // Select variable with largest size/afc
281  BySizeAfcMax::BySizeAfcMax(void) : sizeafc(0) {}
284  : ViewSelBase<SetView>(home,vbo), sizeafc(0) {}
288  sizeafc = static_cast<double>(Iter::Ranges::size(u))/x.afc();
289  return VSS_BETTER;
290  }
294  double sa = static_cast<double>(Iter::Ranges::size(u))/x.afc();
295  if (sa > sizeafc) {
296  sizeafc = sa; return VSS_BETTER;
297  } else if (sa < sizeafc) {
298  return VSS_WORSE;
299  } else {
300  return VSS_TIE;
301  }
302  }
303 
304 }}}
305 
306 // STATISTICS: set-branch