Generated on Tue Jan 26 2021 00:00:00 for Gecode by doxygen 1.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  * Contributing authors:
7  * Gabor Szokoli <szokoli@gecode.org>
8  * Guido Tack <tack@gecode.org>
9  *
10  * Copyright:
11  * Christian Schulte, 2012
12  * Gabor Szokoli, 2004
13  * Guido Tack, 2004
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 namespace Gecode { namespace Set { namespace Branch {
41 
44  : ValSel<SetView,int>(home,vb) {}
47  : ValSel<SetView,int>(home,vs) {}
48  forceinline int
49  ValSelMin::val(const Space&, SetView x, int) {
51  return u.min();
52  }
53 
56  : ValSel<SetView,int>(home,vb) {}
59  : ValSel<SetView,int>(home,vs) {}
60  forceinline int
61  ValSelMax::val(const Space&, SetView x, int) {
62  int max = 0;
63  for (UnknownRanges<SetView> u(x); u(); ++u)
64  max = u.max();
65  return max;
66  }
67 
70  : ValSel<SetView,int>(home,vb) {}
73  : ValSel<SetView,int>(home,vs) {}
74  forceinline int
75  ValSelMed::val(const Space&, SetView x, int) {
77  unsigned int i = Iter::Ranges::size(u1) / 2;
79  int med = (u2.min()+u2.max()) / 2;
80  ++u2;
81  if (!u2()) {
82  return med;
83  }
85  while (i >= u3.width()) {
86  i -= u3.width();
87  ++u3;
88  }
89  return u3.min() + static_cast<int>(i);
90  }
91 
94  : ValSel<SetView,int>(home,vb), r(vb.rnd()) {}
97  : ValSel<SetView,int>(home,vs), r(vs.r) {
98  }
99  forceinline int
100  ValSelRnd::val(const Space&, SetView x, int) {
102  unsigned int p = r(Iter::Ranges::size(u));
103  for (UnknownRanges<SetView> i(x); i(); ++i) {
104  if (i.width() > p)
105  return i.min() + static_cast<int>(p);
106  p -= i.width();
107  }
108  GECODE_NEVER;
109  return 0;
110  }
111  forceinline bool
112  ValSelRnd::notice(void) const {
113  return true;
114  }
115  forceinline void
117  r.~Rnd();
118  }
119 
120 }}}
121 
122 // STATISTICS: set-branch
123 
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
NNF * r
Right subtree.
Definition: bool-expr.cpp:242
int min(void) const
Return smallest value of range.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
int max(void) const
Return largest value of range.
~Rnd(void)
Destructor.
Definition: rnd.cpp:68
Value selection class for maximum of view.
Definition: branch.hh:245
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:61
ValSelMax(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:55
Value selection class for median of view.
Definition: branch.hh:261
ValSelMed(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:69
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:75
Value selection class for mimimum of view.
Definition: branch.hh:229
ValSelMin(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:43
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:49
Value selection class for random value of view.
Definition: branch.hh:277
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:112
ValSelRnd(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:93
Rnd r
The used random number generator.
Definition: branch.hh:280
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition: val-sel.hpp:100
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:116
Set view for set variables
Definition: view.hpp:56
Range iterator for the unknown set.
Definition: var-imp.hpp:402
Computation spaces.
Definition: core.hpp:1742
Value branching information.
Definition: val.hpp:41
Base class for value selection.
Definition: val-sel.hpp:44
const FloatNum max
Largest allowed float value.
Definition: float.hh:844
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::IntArgs i({1, 2, 3, 4})
#define forceinline
Definition: config.hpp:185
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56