main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
gecode
set
branch
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
42
forceinline
43
ValSelMin::ValSelMin
(
Space
& home,
const
ValBranch<Var>
& vb)
44
:
ValSel
<
SetView
,int>(home,vb) {}
45
forceinline
46
ValSelMin::ValSelMin
(
Space
& home,
ValSelMin
& vs)
47
:
ValSel
<
SetView
,int>(home,vs) {}
48
forceinline
int
49
ValSelMin::val
(
const
Space
&,
SetView
x
,
int
) {
50
UnknownRanges<SetView>
u
(
x
);
51
return
u
.min();
52
}
53
54
forceinline
55
ValSelMax::ValSelMax
(
Space
& home,
const
ValBranch<Var>
& vb)
56
:
ValSel
<
SetView
,int>(home,vb) {}
57
forceinline
58
ValSelMax::ValSelMax
(
Space
& home,
ValSelMax
& vs)
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
69
ValSelMed::ValSelMed
(
Space
& home,
const
ValBranch<Var>
& vb)
70
:
ValSel
<
SetView
,int>(home,vb) {}
71
forceinline
72
ValSelMed::ValSelMed
(
Space
& home,
ValSelMed
& vs)
73
:
ValSel
<
SetView
,int>(home,vs) {}
74
forceinline
int
75
ValSelMed::val
(
const
Space
&,
SetView
x
,
int
) {
76
UnknownRanges<SetView>
u1(
x
);
77
unsigned
int
i
=
Iter::Ranges::size
(u1) / 2;
78
UnknownRanges<SetView>
u2(
x
);
79
int
med = (u2.
min
()+u2.
max
()) / 2;
80
++u2;
81
if
(!u2()) {
82
return
med;
83
}
84
UnknownRanges<SetView>
u3(
x
);
85
while
(
i
>= u3.
width
()) {
86
i
-= u3.
width
();
87
++u3;
88
}
89
return
u3.
min
() +
static_cast<
int
>
(
i
);
90
}
91
92
forceinline
93
ValSelRnd::ValSelRnd
(
Space
& home,
const
ValBranch<Var>
& vb)
94
:
ValSel
<
SetView
,int>(home,vb),
r
(vb.rnd()) {}
95
forceinline
96
ValSelRnd::ValSelRnd
(
Space
& home,
ValSelRnd
& vs)
97
:
ValSel
<
SetView
,int>(home,vs),
r
(vs.
r
) {
98
}
99
forceinline
int
100
ValSelRnd::val
(
const
Space
&,
SetView
x
,
int
) {
101
UnknownRanges<SetView>
u
(
x
);
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
116
ValSelRnd::dispose
(
Space
&) {
117
r
.
~Rnd
();
118
}
119
120
}}}
121
122
// STATISTICS: set-branch
123
Gecode::Set::Branch::ValSelMed::ValSelMed
ValSelMed(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition:
val-sel.hpp:69
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::Set::Branch::ValSelMin::ValSelMin
ValSelMin(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition:
val-sel.hpp:43
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:49
Gecode::Set::Branch::ValSelRnd::val
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition:
val-sel.hpp:100
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
Gecode::ValSel
Base class for value selection.
Definition:
val-sel.hpp:44
Gecode::Rnd::~Rnd
~Rnd(void)
Destructor.
Definition:
rnd.cpp:68
Gecode::Set::UnknownRanges
Range iterator for the unknown set.
Definition:
var-imp.hpp:402
Gecode::Set::Branch::ValSelRnd::ValSelRnd
ValSelRnd(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition:
val-sel.hpp:93
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::Set::Branch::ValSelMed::val
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition:
val-sel.hpp:75
Gecode::Iter::Ranges::MinMax::width
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Definition:
ranges-minmax.hpp:107
Gecode
Gecode toplevel namespace
u
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Gecode::Set::Branch::ValSelMin::val
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition:
val-sel.hpp:49
Gecode::Iter::Ranges::MinMax::min
int min(void) const
Return smallest value of range.
Definition:
ranges-minmax.hpp:99
Gecode::Set::Branch::ValSelRnd::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition:
val-sel.hpp:112
Gecode::Set::Branch::ValSelMax::ValSelMax
ValSelMax(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition:
val-sel.hpp:55
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::ValBranch
Value branching information.
Definition:
val.hpp:41
Gecode::Set::Branch::ValSelMax
Value selection class for maximum of view.
Definition:
branch.hh:245
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:56
Gecode::Set::Branch::ValSelRnd
Value selection class for random value of view.
Definition:
branch.hh:277
Gecode::Set::SetView
Set view for set variables
Definition:
view.hpp:56
Gecode::Set::Branch::ValSelRnd::r
Rnd r
The used random number generator.
Definition:
branch.hh:280
Gecode::Iter::Ranges::MinMax::max
int max(void) const
Return largest value of range.
Definition:
ranges-minmax.hpp:103
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Set::Branch::ValSelMax::val
int val(const Space &home, SetView x, int i)
Return value of view x at position i.
Definition:
val-sel.hpp:61
Gecode::Set::Branch::ValSelRnd::dispose
void dispose(Space &home)
Delete value selection.
Definition:
val-sel.hpp:116
Gecode::Set::Branch::ValSelMed
Value selection class for median of view.
Definition:
branch.hh:261
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::Set::Branch::ValSelMin
Value selection class for mimimum of view.
Definition:
branch.hh:229
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:232