Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 namespace Gecode { namespace Int { namespace Branch {
35 
36  template<class View>
39  (Space& home, const ValBranch<ValSelMin<View>::Var>& vb)
40  : ValSel<View,int>(home,vb) {}
41  template<class View>
44  : ValSel<View,int>(home,vs) {}
45  template<class View>
46  forceinline int
47  ValSelMin<View>::val(const Space&, View x, int) {
48  return x.min();
49  }
50 
51  template<class View>
54  (Space& home, const ValBranch<ValSelMax<View>::Var>& vb)
55  : ValSel<View,int>(home,vb) {}
56  template<class View>
59  : ValSel<View,int>(home,vs) {}
60  template<class View>
61  forceinline int
62  ValSelMax<View>::val(const Space&, View x, int) {
63  return x.max();
64  }
65 
66  template<class View>
69  (Space& home, const ValBranch<ValSelMed<View>::Var>& vb)
70  : ValSel<View,int>(home,vb) {}
71  template<class View>
74  : ValSel<View,int>(home,vs) {}
75  template<class View>
76  forceinline int
77  ValSelMed<View>::val(const Space&, View x, int) {
78  return x.med();
79  }
80 
81  template<class View>
84  (Space& home, const ValBranch<ValSelAvg<View>::Var>& vb)
85  : ValSel<View,int>(home,vb) {}
86  template<class View>
89  : ValSel<View,int>(home,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  (Space& home, const ValBranch<ValSelRnd<View>::Var>& vb)
100  : ValSel<View,int>(home,vb), r(vb.rnd()) {}
101  template<class View>
104  : ValSel<View,int>(home,vs), r(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  (Space& home, const ValBranch<IntVar>& vb)
132  : ValSel<IntView,int>(home,vb) {}
135  : ValSel<IntView,int>(home,vs) {}
136  forceinline int
138  if (x.range()) {
139  return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
140  } else {
142  return r.max();
143  }
144  }
145 
148  : ValSel<IntView,int>(home,vb) {}
151  : ValSel<IntView,int>(home,vs) {}
152  forceinline int
154  if (x.range()) {
155  return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
156  } else {
157  int min;
159  do {
160  min = r.min(); ++r;
161  } while (r());
162  return min;
163  }
164  }
165 
166 }}}
167 
168 // STATISTICS: int-branch
169 
Post propagator for SetVar x
Definition: set.hh:767
ValSelRnd(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Value selection class for random value of view.
Definition: branch.hh:353
ValSelMed(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Base class for value selection.
Definition: val-sel.hpp:44
Value selection class for maximum of view.
Definition: branch.hh:299
ValSelAvg(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Computation spaces.
Definition: core.hpp:1742
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:77
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:108
View::VarType Var
Corresponding variable type.
Definition: val-sel.hpp:49
Gecode toplevel namespace
Range iterator for integer views.
Definition: view.hpp:54
Value selection class for maximum range of integer view.
Definition: branch.hh:393
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:125
Value selection class for median of view.
Definition: branch.hh:317
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
Value branching information.
Definition: val.hpp:41
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
ValSelMin(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Value selection class for average of view.
Definition: branch.hh:335
ValSelMax(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
int val(const Space &home, IntView x, int i)
Return value of integer view x at position i.
Definition: val-sel.hpp:153
Integer view for integer variables.
Definition: view.hpp:129
Range iterator for integer variable views
Definition: int.hpp:246
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:92
#define forceinline
Definition: config.hpp:185
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
ValSelRangeMax(Space &home, const ValBranch< IntVar > &vb)
Constructor for initialization.
Definition: val-sel.hpp:147
int val(const Space &home, IntView x, int i)
Return value of integer view x at position i.
Definition: val-sel.hpp:137
Value selection class for minimum range of integer view.
Definition: branch.hh:377
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:47
Gecode::IntArgs i({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:62
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Value selection class for mimimum of view.
Definition: branch.hh:281
ValSelRangeMin(Space &home, const ValBranch< IntVar > &vb)
Constructor for initialization.
Definition: val-sel.hpp:131