Generated on Thu Jul 25 2019 00:00:00 for Gecode by doxygen 1.8.15
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: 2017-03-10 16:52:37 +0100 (Fri, 10 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15569 $
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
108  ValSelRnd<View>::val(const Space&, View x, 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 {
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 }}}
166 
167 // STATISTICS: int-branch
168 
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:92
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:125
Rnd r
The used random number generator.
Definition: branch.hh:357
Range iterator for integer variable views
Definition: int.hpp:236
Computation spaces.
Definition: core.hpp:1748
Range iterator for integer views.
Definition: view.hpp:54
Value selection class for mimimum of view.
Definition: branch.hh:281
Value selection class for average of view.
Definition: branch.hh:335
Value selection class for random value of view.
Definition: branch.hh:353
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
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:377
ValSelMax(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:56
Value selection class for maximum of view.
Definition: branch.hh:299
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:120
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:78
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:71
void update(Space &home, bool share, SharedHandle &sh)
Updating during cloning.
Definition: core.hpp:3127
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:45
Value selection class for median of view.
Definition: branch.hh:317
int val(const Space &home, IntView x, int i)
Return value of integer view x at position i.
Definition: val-sel.hpp:152
ValSelRnd(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:98
ValSelAvg(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:84
#define forceinline
Definition: config.hpp:173
ValSelMin(Space &home, const ValBranch< Var > &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:108
Post propagator for SetVar x
Definition: set.hh:784
ValSelMed(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:70
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
ValSelRangeMax(Space &home, const ValBranch< IntVar > &vb)
Constructor for initialization.
Definition: val-sel.hpp:146
Gecode toplevel namespace
Value selection class for maximum range of integer view.
Definition: branch.hh:393
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
ValSelRangeMin(Space &home, const ValBranch< IntVar > &vb)
Constructor for initialization.
Definition: val-sel.hpp:130
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