Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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$ by $Author$
11  * $Revision$
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,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,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,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,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,vs), r(vs.r) {
104  }
105  template<class View>
106  forceinline int
108  unsigned int p = r(x.size());
109  for (ViewRanges<View> i(x); i(); ++i) {
110  if (i.width() > p)
111  return i.min() + static_cast<int>(p);
112  p -= i.width();
113  }
114  GECODE_NEVER;
115  return 0;
116  }
117  template<class View>
118  forceinline bool
120  return true;
121  }
122  template<class View>
123  forceinline void
125  r.~Rnd();
126  }
127 
130  : ValSel<IntView,int>(home,vb) {}
133  : ValSel<IntView,int>(home,vs) {}
134  forceinline int
136  if (x.range()) {
137  return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
138  } else {
139  ViewRanges<View> r(x);
140  return r.max();
141  }
142  }
143 
146  : ValSel<IntView,int>(home,vb) {}
149  : ValSel<IntView,int>(home,vs) {}
150  forceinline int
152  if (x.range()) {
153  return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
154  } else {
155  int min;
157  do {
158  min = r.min(); ++r;
159  } while (r());
160  return min;
161  }
162  }
163 
164 }}}
165 
166 // STATISTICS: int-branch
167 
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:92
View View
View type.
Definition: val-sel.hpp:51
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:124
int min(void) const
Return smallest value of range.
Definition: int.hpp:450
Rnd r
The used random number generator.
Definition: branch.hh:357
Range iterator for integer variable views
Definition: int.hpp:240
#define forceinline
Definition: config.hpp:182
Computation spaces.
Definition: core.hpp:1668
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
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:119
bool range(void) const
Test whether domain is a range.
Definition: int.hpp:97
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:78
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: int.hpp:79
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:71
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: 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:151
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
ValSelMin(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:42
int max(void) const
Return largest value of range.
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:107
Post propagator for SetVar x
Definition: set.hh:769
ValSelMed(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:70
ValSelRangeMax(Space &home, const ValBranch< IntVar > &vb)
Constructor for initialization.
Definition: val-sel.hpp:145
Gecode toplevel namespace
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
Value selection class for maximum range of integer view.
Definition: branch.hh:393
~Rnd(void)
Destructor.
Definition: rnd.cpp:72
#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:129
Base class for value selection.
Definition: val-sel.hpp:48
int val(const Space &home, IntView x, int i)
Return value of integer view x at position i.
Definition: val-sel.hpp:135