Generated on Sat Feb 7 2015 02:01:15 for Gecode by doxygen 1.8.9.1
val-sel.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, 2012
8  *
9  * Last modified:
10  * $Date: 2013-03-05 20:51:24 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
11  * $Revision: 13438 $
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  : ValSel<View,int>(home,vb) {}
44  template<class View>
47  : ValSel<View,int>(home,shared,vs) {}
48  template<class View>
49  forceinline int
50  ValSelMin<View>::val(const Space&, View x, int) {
51  return x.min();
52  }
53 
54  template<class View>
57  : ValSel<View,int>(home,vb) {}
58  template<class View>
61  : ValSel<View,int>(home,shared,vs) {}
62  template<class View>
63  forceinline int
64  ValSelMax<View>::val(const Space&, View x, int) {
65  return x.max();
66  }
67 
68  template<class View>
71  : ValSel<View,int>(home,vb) {}
72  template<class View>
75  : ValSel<View,int>(home,shared,vs) {}
76  template<class View>
77  forceinline int
78  ValSelMed<View>::val(const Space&, View x, int) {
79  return x.med();
80  }
81 
82  template<class View>
85  : ValSel<View,int>(home,vb) {}
86  template<class View>
89  : ValSel<View,int>(home,shared,vs) {}
90  template<class View>
91  forceinline int
92  ValSelAvg<View>::val(const Space&, View x, int) {
93  return (x.width() == 2U) ? x.min() : ((x.min()+x.max()) / 2);
94  }
95 
96  template<class View>
99  : ValSel<View,int>(home,vb), r(vb.rnd()) {}
100  template<class View>
103  : ValSel<View,int>(home,shared,vs) {
104  r.update(home,shared,vs.r);
105  }
106  template<class View>
107  forceinline int
109  unsigned int p = r(x.size());
110  for (ViewRanges<View> i(x); i(); ++i) {
111  if (i.width() > p)
112  return i.min() + static_cast<int>(p);
113  p -= i.width();
114  }
115  GECODE_NEVER;
116  return 0;
117  }
118  template<class View>
119  forceinline bool
121  return true;
122  }
123  template<class View>
124  forceinline void
126  r.~Rnd();
127  }
128 
131  : ValSel<IntView,int>(home,vb) {}
134  : ValSel<IntView,int>(home,shared,vs) {}
135  forceinline int
137  if (x.range()) {
138  return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
139  } else {
140  ViewRanges<View> r(x);
141  return r.max();
142  }
143  }
144 
147  : ValSel<IntView,int>(home,vb) {}
150  : ValSel<IntView,int>(home,shared,vs) {}
151  forceinline int
153  if (x.range()) {
154  return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
155  } else {
156  int min;
158  do {
159  min = r.min(); ++r;
160  } while (r());
161  return min;
162  }
163  }
164 
165  template<class View, bool min>
168  const ValBranch& vb)
169  : ValSel<View,int>(home,vb),
170  c(static_cast<const IntValBranch&>(vb).values()) {}
171  template<class View, bool min>
174  ValSelNearMinMax& vs)
175  : ValSel<View,int>(home,shared,vs) {
176  c.update(home,shared,vs.c);
177  }
178  template<class View, bool min>
179  forceinline int
181  int n = c[i];
182  if (x.max() <= n) return x.max();
183  if (x.min() >= n) return x.min();
184  if (x.range()) return n;
185  ViewRanges<View> r(x);
186  int pmax;
187  do {
188  pmax=r.max(); ++r;
189  } while (r.max() < n);
190  assert(r());
191  if ((pmax >= n) || (r.min() <= n))
192  return n;
193  assert((pmax < n) && (n < r.min()));
194  unsigned int dmin = static_cast<unsigned int>(n - pmax);
195  unsigned int dmax = static_cast<unsigned int>(r.min() - n);
196  if (dmin == dmax)
197  return min ? pmax : r.min();
198  else if (dmin < dmax)
199  return pmax;
200  else
201  return r.min();
202  }
203  template<class View, bool min>
204  forceinline bool
206  return true;
207  }
208  template<class View, bool min>
209  forceinline void
211  c.~IntSharedArray();
212  }
213 
214  template<class View, bool inc>
217  const ValBranch& vb)
218  : ValSel<View,int>(home,vb),
219  c(static_cast<const IntValBranch&>(vb).values()) {}
220  template<class View, bool inc>
223  ValSelNearIncDec& vs)
224  : ValSel<View,int>(home,shared,vs) {
225  c.update(home,shared,vs.c);
226  }
227  template<class View, bool inc>
228  forceinline int
230  int n = c[i];
231  if (x.max() <= n) return x.max();
232  if (x.min() >= n) return x.min();
233  if (x.range()) return n;
234  if (inc) {
235  ViewRanges<View> r(x);
236  while (r.max() < n)
237  ++r;
238  assert(r());
239  return (r.min() <= n) ? n : r.min();
240  } else {
241  ViewRanges<View> r(x);
242  int pmax;
243  do {
244  pmax=r.max(); ++r;
245  } while (r.max() < n);
246  assert(r());
247  return (r.min() <= n) ? n : pmax;
248  }
249  }
250  template<class View, bool inc>
251  forceinline bool
253  return true;
254  }
255  template<class View, bool inc>
256  forceinline void
258  c.~IntSharedArray();
259  }
260 
261 }}}
262 
263 // STATISTICS: int-branch
264 
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:92
ValSelRnd(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:98
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:125
Value selection class for nearest value.
Definition: branch.hh:396
Which values to select for branching first.
Definition: int.hh:3981
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:180
Rnd r
The used random number generator.
Definition: branch.hh:319
Range iterator for integer variable views
Definition: int.hpp:236
Computation spaces.
Definition: core.hpp:1362
ValSelMed(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:70
IntSharedArray c
The used values.
Definition: branch.hh:399
Range iterator for integer views.
Definition: view.hpp:54
Value selection class for mimimum of view.
Definition: branch.hh:248
Value selection class for average of view.
Definition: branch.hh:299
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
Value selection class for random value of view.
Definition: branch.hh:316
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
int min(void) const
Return smallest value of range.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:50
Value selection class for minimum range of integer view.
Definition: branch.hh:339
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Value selection class for maximum of view.
Definition: branch.hh:265
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
int min(void) const
Return smallest value of range.
Definition: int.hpp:446
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:210
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:120
ValSelRangeMin(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:130
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:78
ValSelMin(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:42
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:229
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
void update(Space &home, bool share, SharedHandle &sh)
Updating during cloning.
Definition: core.hpp:2656
void values(Home home, const IntVarArgs &x, IntSet y, IntConLevel icl=ICL_DEF)
Post constraint .
Definition: minimodel.hh:1869
Integer view for integer variables.
Definition: view.hpp:129
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:64
Value branching information.
Definition: branch-val.hpp:44
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ValSelRangeMax(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:146
IntSharedArray c
The used values.
Definition: branch.hh:375
Value selection class for median of view.
Definition: branch.hh:282
int val(const Space &home, IntView x, int i)
Return value of integer view x at position i.
Definition: val-sel.hpp:152
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:257
ValSelNearMinMax(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:167
ValSelNearIncDec(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:216
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: int.hpp:79
#define forceinline
Definition: config.hpp:132
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:108
bool range(void) const
Test whether domain is a range.
Definition: int.hpp:97
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
Value selection class for nearest value.
Definition: branch.hh:372
int max(void) const
Return largest value of range.
Gecode toplevel namespace
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:205
Value selection class for maximum range of integer view.
Definition: branch.hh:355
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:390
ValSelMax(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:56
ValSelAvg(Space &home, const ValBranch &vb)
Constructor for initialization.
Definition: val-sel.hpp:84
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:402
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:252
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Base class for value selection.
int val(const Space &home, IntView x, int i)
Return value of integer view x at position i.
Definition: val-sel.hpp:136