Generated on for Gecode by doxygen 1.17.0
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.dev>
5 *
6 * Contributing authors:
7 * Gabor Szokoli <szokoli@gecode.dev>
8 * Guido Tack <tack@gecode.dev>
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.dev
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
40namespace Gecode { namespace Set { namespace Branch {
41
42 forceinline
44 : ValSel<SetView,int>(home,vb) {}
45 forceinline
47 : ValSel<SetView,int>(home,vs) {}
48 forceinline int
49 ValSelMin::val(const Space&, SetView x, int) {
51 return u.min();
52 }
53
54 forceinline
56 : ValSel<SetView,int>(home,vb) {}
57 forceinline
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
68 forceinline
70 : ValSel<SetView,int>(home,vb) {}
71 forceinline
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
92 forceinline
94 : ValSel<SetView,int>(home,vb), r(vb.rnd()) {}
95 forceinline
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 }
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 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.
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
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
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
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:1775
Value branching information.
Definition val.hpp:41
ValSel(Space &home, const ValBranch< Var > &vb)
Definition val-sel.hpp:100
unsigned int size(I &i)
Size of all ranges of range iterator i.
Set branchings
Finite integer sets.
Definition var-imp.hpp:145
Gecode toplevel namespace
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56