Generated on Wed Sep 5 2012 18:51: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  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2002
8  *
9  * Last modified:
10  * $Date: 2009-10-14 06:12:58 +1100 (Wed, 14 Oct 2009) $ by $Author: schulte $
11  * $Revision: 9897 $
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  // Select variable with smallest min
42  ByMinMin::ByMinMin(void) : min(0) {}
45  : ViewSelBase<IntView>(home,vbo), min(0) {}
48  min = x.min();
49  return VSS_BETTER;
50  }
53  if (x.min() < min) {
54  min = x.min(); return VSS_BETTER;
55  } else if (x.min() > min) {
56  return VSS_WORSE;
57  } else {
58  return VSS_TIE;
59  }
60  }
61 
62  // Select variable with largest min
64  ByMinMax::ByMinMax(void) : min(0) {}
67  : ViewSelBase<IntView>(home,vbo), min(0) {}
70  min = x.min();
71  return VSS_BETTER;
72  }
75  if (x.min() > min) {
76  min = x.min(); return VSS_BETTER;
77  } else if (x.min() < min) {
78  return VSS_WORSE;
79  } else {
80  return VSS_TIE;
81  }
82  }
83 
84  // Select variable with smallest max
86  ByMaxMin::ByMaxMin(void) : max(0) {}
89  : ViewSelBase<IntView>(home,vbo), max(0) {}
92  max = x.max();
93  return VSS_BETTER;
94  }
97  if (x.max() < max) {
98  max = x.max(); return VSS_BETTER;
99  } else if (x.max() > max) {
100  return VSS_WORSE;
101  } else {
102  return VSS_TIE;
103  }
104  }
105 
106  // Select variable with largest max
108  ByMaxMax::ByMaxMax(void) : max(0) {}
111  : ViewSelBase<IntView>(home,vbo), max(0) {}
114  max = x.max();
115  return VSS_BETTER;
116  }
119  if (x.max() > max) {
120  max = x.max(); return VSS_BETTER;
121  } else if (x.max() < max) {
122  return VSS_WORSE;
123  } else {
124  return VSS_TIE;
125  }
126  }
127 
128  // Select variable with smallest size
130  BySizeMin::BySizeMin(void) : size(0U) {}
133  : ViewSelBase<IntView>(home,vbo), size(0U) {}
136  size = x.size();
137  return (size == 2) ? VSS_BEST : VSS_BETTER;
138  }
141  if (x.size() < size) {
142  size = x.size();
143  return (size == 2) ? VSS_BEST : VSS_BETTER;
144  } else if (x.size() > size) {
145  return VSS_WORSE;
146  } else {
147  return VSS_TIE;
148  }
149  }
150 
151  // Select variable with largest size
153  BySizeMax::BySizeMax(void) : size(0U) {}
156  : ViewSelBase<IntView>(home,vbo), size(0U) {}
159  size = x.size();
160  return VSS_BETTER;
161  }
164  if (x.size() > size) {
165  size = x.size();
166  return VSS_BETTER;
167  } else if (x.size() < size) {
168  return VSS_WORSE;
169  } else {
170  return VSS_TIE;
171  }
172  }
173 
174  // Select variable with smallest size/degree
176  BySizeDegreeMin::BySizeDegreeMin(void) : sizedegree(0) {}
179  : ViewSelBase<IntView>(home,vbo), sizedegree(0) {}
182  sizedegree =
183  static_cast<double>(x.size())/static_cast<double>(x.degree());
184  return VSS_BETTER;
185  }
188  double sd =
189  static_cast<double>(x.size())/static_cast<double>(x.degree());
190  if (sd < sizedegree) {
191  sizedegree = sd; return VSS_BETTER;
192  } else if (sd > sizedegree) {
193  return VSS_WORSE;
194  } else {
195  return VSS_TIE;
196  }
197  }
198 
199  // Select variable with largest size/degree
201  BySizeDegreeMax::BySizeDegreeMax(void) : sizedegree(0) {}
204  : ViewSelBase<IntView>(home,vbo), sizedegree(0) {}
207  sizedegree =
208  static_cast<double>(x.size())/static_cast<double>(x.degree());
209  return VSS_BETTER;
210  }
213  double sd =
214  static_cast<double>(x.size())/static_cast<double>(x.degree());
215  if (sd > sizedegree) {
216  sizedegree = sd; return VSS_BETTER;
217  } else if (sd < sizedegree) {
218  return VSS_WORSE;
219  } else {
220  return VSS_TIE;
221  }
222  }
223 
224  // Select variable with smallest size/afc
226  BySizeAfcMin::BySizeAfcMin(void) : sizeafc(0) {}
229  : ViewSelBase<IntView>(home,vbo), sizeafc(0) {}
232  sizeafc = static_cast<double>(x.size())/x.afc();
233  return VSS_BETTER;
234  }
237  double sa = static_cast<double>(x.size())/x.afc();
238  if (sa < sizeafc) {
239  sizeafc = sa; return VSS_BETTER;
240  } else if (sa > sizeafc) {
241  return VSS_WORSE;
242  } else {
243  return VSS_TIE;
244  }
245  }
246 
247  // Select variable with largest size/afc
249  BySizeAfcMax::BySizeAfcMax(void) : sizeafc(0) {}
252  : ViewSelBase<IntView>(home,vbo), sizeafc(0) {}
255  sizeafc = static_cast<double>(x.size())/x.afc();
256  return VSS_BETTER;
257  }
260  double sa = static_cast<double>(x.size())/x.afc();
261  if (sa > sizeafc) {
262  sizeafc = sa; return VSS_BETTER;
263  } else if (sa < sizeafc) {
264  return VSS_WORSE;
265  } else {
266  return VSS_TIE;
267  }
268  }
269 
270  // Select variable with smallest min-regret
272  ByRegretMinMin::ByRegretMinMin(void) : regret(0U) {}
275  : ViewSelBase<IntView>(home,vbo), regret(0U) {}
278  regret = x.regret_min();
279  return (regret == 1) ? VSS_BEST : VSS_BETTER;
280  }
283  if (x.regret_min() < regret) {
284  regret = x.regret_min();
285  return (regret == 1) ? VSS_BEST : VSS_BETTER;
286  } else if (x.regret_min() > regret) {
287  return VSS_WORSE;
288  } else {
289  return VSS_TIE;
290  }
291  }
292 
293  // Select variable with largest min-regret
295  ByRegretMinMax::ByRegretMinMax(void) : regret(0U) {}
298  : ViewSelBase<IntView>(home,vbo), regret(0U) {}
301  regret = x.regret_min();
302  return VSS_BETTER;
303  }
306  if (x.regret_min() > regret) {
307  regret = x.regret_min();
308  return VSS_BETTER;
309  } else if (x.regret_min() < regret) {
310  return VSS_WORSE;
311  } else {
312  return VSS_TIE;
313  }
314  }
315 
316  // Select variable with smallest max-regret
318  ByRegretMaxMin::ByRegretMaxMin(void) : regret(0U) {}
321  : ViewSelBase<IntView>(home,vbo), regret(0U) {}
324  regret = x.regret_max();
325  return (regret == 1) ? VSS_BEST : VSS_BETTER;
326  }
329  if (x.regret_max() < regret) {
330  regret = x.regret_max();
331  return (regret == 1) ? VSS_BEST : VSS_BETTER;
332  } else if (x.regret_max() > regret) {
333  return VSS_WORSE;
334  } else {
335  return VSS_TIE;
336  }
337  }
338 
339  // Select variable with largest max-regret
341  ByRegretMaxMax::ByRegretMaxMax(void) : regret(0U) {}
344  : ViewSelBase<IntView>(home,vbo), regret(0U) {}
347  regret = x.regret_max();
348  return VSS_BETTER;
349  }
352  if (x.regret_max() > regret) {
353  regret = x.regret_max();
354  return VSS_BETTER;
355  } else if (x.regret_max() < regret) {
356  return VSS_WORSE;
357  } else {
358  return VSS_TIE;
359  }
360  }
361 
362 }}}
363 
364 // STATISTICS: int-branch