Generated on Sat Jan 12 2019 20:58:51 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  * 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  : ValSel<View,int>(home,vb) {}
40  template<class View>
43  : ValSel<View,int>(home,vs) {}
44  template<class View>
45  forceinline int
46  ValSelMin<View>::val(const Space&, View x, int) {
47  return x.min();
48  }
49 
50  template<class View>
53  : ValSel<View,int>(home,vb) {}
54  template<class View>
57  : ValSel<View,int>(home,vs) {}
58  template<class View>
59  forceinline int
60  ValSelMax<View>::val(const Space&, View x, int) {
61  return x.max();
62  }
63 
64  template<class View>
67  : ValSel<View,int>(home,vb) {}
68  template<class View>
71  : ValSel<View,int>(home,vs) {}
72  template<class View>
73  forceinline int
74  ValSelMed<View>::val(const Space&, View x, int) {
75  return x.med();
76  }
77 
78  template<class View>
81  : ValSel<View,int>(home,vb) {}
82  template<class View>
85  : ValSel<View,int>(home,vs) {}
86  template<class View>
87  forceinline int
88  ValSelAvg<View>::val(const Space&, View x, int) {
89  return (x.width() == 2U) ? x.min() : ((x.min()+x.max()) / 2);
90  }
91 
92  template<class View>
95  : ValSel<View,int>(home,vb), r(vb.rnd()) {}
96  template<class View>
99  : ValSel<View,int>(home,vs), r(vs.r) {
100  }
101  template<class View>
102  forceinline int
104  unsigned int p = r(x.size());
105  for (ViewRanges<View> i(x); i(); ++i) {
106  if (i.width() > p)
107  return i.min() + static_cast<int>(p);
108  p -= i.width();
109  }
110  GECODE_NEVER;
111  return 0;
112  }
113  template<class View>
114  forceinline bool
116  return true;
117  }
118  template<class View>
119  forceinline void
121  r.~Rnd();
122  }
123 
126  : ValSel<IntView,int>(home,vb) {}
129  : ValSel<IntView,int>(home,vs) {}
130  forceinline int
132  if (x.range()) {
133  return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
134  } else {
135  ViewRanges<View> r(x);
136  return r.max();
137  }
138  }
139 
142  : ValSel<IntView,int>(home,vb) {}
145  : ValSel<IntView,int>(home,vs) {}
146  forceinline int
148  if (x.range()) {
149  return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
150  } else {
151  int min;
153  do {
154  min = r.min(); ++r;
155  } while (r());
156  return min;
157  }
158  }
159 
160 }}}
161 
162 // STATISTICS: int-branch
163 
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:88
View View
View type.
Definition: val-sel.hpp:47
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:120
int min(void) const
Return smallest value of range.
Definition: int.hpp:446
Rnd r
The used random number generator.
Definition: branch.hh:357
Range iterator for integer variable views
Definition: int.hpp:246
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
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:232
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:46
Value selection class for minimum range of integer view.
Definition: branch.hh:377
Gecode::IntArgs i({1, 2, 3, 4})
ValSelMax(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:52
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:115
bool range(void) const
Test whether domain is a range.
Definition: int.hpp:103
int val(const Space &home, View x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:74
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: int.hpp:85
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
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:60
Value branching information.
Definition: val.hpp:41
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:147
ValSelRnd(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:94
ValSelAvg(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:80
ValSelMin(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:38
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:103
Post propagator for SetVar x
Definition: set.hh:767
ValSelMed(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:66
ValSelRangeMax(Space &home, const ValBranch< IntVar > &vb)
Constructor for initialization.
Definition: val-sel.hpp:141
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:68
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
ValSelRangeMin(Space &home, const ValBranch< IntVar > &vb)
Constructor for initialization.
Definition: val-sel.hpp:125
Base class for value selection.
Definition: val-sel.hpp:44
int val(const Space &home, IntView x, int i)
Return value of integer view x at position i.
Definition: val-sel.hpp:131