main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Aug 27 2012 17:15:38 for Gecode by
doxygen
1.8.1.2
gecode
set
branch
select-val.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Guido Tack <tack@gecode.org>
5
* Christian Schulte <schulte@gecode.org>
6
*
7
* Contributing authors:
8
* Gabor Szokoli <szokoli@gecode.org>
9
*
10
* Copyright:
11
* Guido Tack, 2004
12
* Christian Schulte, 2004
13
* Gabor Szokoli, 2004
14
*
15
* Last modified:
16
* $Date: 2011-05-11 20:44:17 +1000 (Wed, 11 May 2011) $ by $Author: tack $
17
* $Revision: 12001 $
18
*
19
* This file is part of Gecode, the generic constraint
20
* development environment:
21
* http://www.gecode.org
22
*
23
* Permission is hereby granted, free of charge, to any person obtaining
24
* a copy of this software and associated documentation files (the
25
* "Software"), to deal in the Software without restriction, including
26
* without limitation the rights to use, copy, modify, merge, publish,
27
* distribute, sublicense, and/or sell copies of the Software, and to
28
* permit persons to whom the Software is furnished to do so, subject to
29
* the following conditions:
30
*
31
* The above copyright notice and this permission notice shall be
32
* included in all copies or substantial portions of the Software.
33
*
34
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
*
42
*/
43
44
namespace
Gecode {
namespace
Set {
namespace
Branch {
45
46
template
<
bool
inc>
47
forceinline
48
ValMin<inc>::ValMin
(
void
) {}
49
template
<
bool
inc>
50
forceinline
51
ValMin<inc>::ValMin
(
Space
& home,
const
ValBranchOptions
& vbo)
52
:
ValSelBase
<
SetView
,int>(home,vbo) {}
53
template
<
bool
inc>
54
forceinline
int
55
ValMin<inc>::val
(
Space
&,
SetView
x)
const
{
56
UnknownRanges<SetView>
u(x);
57
return
u.
min
();
58
}
59
template
<
bool
inc>
60
forceinline
ModEvent
61
ValMin<inc>::tell
(
Space
& home,
unsigned
int
a
,
SetView
x,
int
v
) {
62
return
((a == 0) == inc) ? x.
include
(home,v) : x.
exclude
(home,v);
63
}
64
65
66
template
<
bool
inc>
67
forceinline
68
ValMed<inc>::ValMed
(
void
) {}
69
template
<
bool
inc>
70
forceinline
71
ValMed<inc>::ValMed
(
Space
& home,
const
ValBranchOptions
& vbo)
72
:
ValSelBase
<
SetView
,int>(home,vbo) {}
73
template
<
bool
inc>
74
forceinline
int
75
ValMed<inc>::val
(
Space
&,
SetView
x)
const
{
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
template
<
bool
inc>
92
forceinline
ModEvent
93
ValMed<inc>::tell
(
Space
& home,
unsigned
int
a
,
SetView
x,
int
v
) {
94
return
((a == 0) == inc) ? x.
include
(home,v) : x.
exclude
(home,v);
95
}
96
97
template
<
bool
inc>
98
forceinline
99
ValMax<inc>::ValMax
(
void
) {}
100
template
<
bool
inc>
101
forceinline
102
ValMax<inc>::ValMax
(
Space
& home,
const
ValBranchOptions
& vbo)
103
:
ValSelBase
<
SetView
,int>(home,vbo) {}
104
template
<
bool
inc>
105
forceinline
int
106
ValMax<inc>::val
(
Space
&,
SetView
x)
const
{
107
int
max
= 0;
108
for
(
UnknownRanges<SetView>
u(x); u(); ++u)
109
max = u.max();
110
return
max
;
111
}
112
template
<
bool
inc>
113
forceinline
ModEvent
114
ValMax<inc>::tell
(
Space
& home,
unsigned
int
a
,
SetView
x,
int
v
) {
115
return
((a == 0) == inc) ? x.
include
(home,v) : x.
exclude
(home,v);
116
}
117
118
119
template
<
bool
inc>
120
forceinline
121
ValRnd<inc>::ValRnd
(
void
) {}
122
template
<
bool
inc>
123
forceinline
124
ValRnd<inc>::ValRnd
(
Space
&,
const
ValBranchOptions
& vbo)
125
:
r
(vbo.seed) {}
126
template
<
bool
inc>
127
forceinline
int
128
ValRnd<inc>::val
(
Space
&,
SetView
x) {
129
UnknownRanges<SetView>
u(x);
130
unsigned
int
p =
r
(
Iter::Ranges::size
(u));
131
for
(
UnknownRanges<SetView>
i
(x);
i
(); ++
i
) {
132
if
(
i
.width() > p)
133
return
i
.min() +
static_cast<
int
>
(p);
134
p -=
i
.width();
135
}
136
GECODE_NEVER
;
137
return
0;
138
}
139
template
<
bool
inc>
140
forceinline
ModEvent
141
ValRnd<inc>::tell
(
Space
& home,
unsigned
int
a
,
SetView
x,
int
v
) {
142
return
((a == 0) == inc) ? x.
include
(home,v) : x.
exclude
(home,v);
143
}
144
template
<
bool
inc>
145
forceinline
typename
ValRnd<inc>::Choice
146
ValRnd<inc>::choice
(
Space
&) {
147
return
r
;
148
}
149
template
<
bool
inc>
150
forceinline
typename
ValRnd<inc>::Choice
151
ValRnd<inc>::choice
(
const
Space
&,
Archive
& e) {
152
return
Choice
(e.
get
());
153
}
154
template
<
bool
inc>
155
forceinline
void
156
ValRnd<inc>::commit
(
Space
&,
const
Choice
&
c
,
157
unsigned
int
) {
158
r
=
c
;
159
}
160
template
<
bool
inc>
161
forceinline
void
162
ValRnd<inc>::update
(
Space
&,
bool
,
ValRnd<inc>
& vr) {
163
r
= vr.
r
;
164
}
165
template
<
bool
inc>
166
forceinline
void
167
ValRnd<inc>::dispose
(
Space
&) {}
168
169
170
template
<
bool
inc>
171
forceinline
172
AssignValMin<inc>::AssignValMin
(
void
) {}
173
template
<
bool
inc>
174
forceinline
175
AssignValMin<inc>::AssignValMin
(
Space
& home,
const
ValBranchOptions
& vbo)
176
:
ValMin
<inc>(home,vbo) {}
177
178
template
<
bool
inc>
179
forceinline
180
AssignValMed<inc>::AssignValMed
(
void
) {}
181
template
<
bool
inc>
182
forceinline
183
AssignValMed<inc>::AssignValMed
(
Space
& home,
const
ValBranchOptions
& vbo)
184
:
ValMed
<inc>(home,vbo) {}
185
186
template
<
bool
inc>
187
forceinline
188
AssignValMax<inc>::AssignValMax
(
void
) {}
189
template
<
bool
inc>
190
forceinline
191
AssignValMax<inc>::AssignValMax
(
Space
& home,
const
ValBranchOptions
& vbo)
192
:
ValMax
<inc>(home,vbo) {}
193
194
template
<
bool
inc>
195
forceinline
196
AssignValRnd<inc>::AssignValRnd
(
void
) {}
197
template
<
bool
inc>
198
forceinline
199
AssignValRnd<inc>::AssignValRnd
(
Space
& home,
const
ValBranchOptions
& vbo)
200
:
ValRnd
<inc>(home,vbo) {}
201
202
}}}
203
204
// STATISTICS: set-branch