main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:33 for Gecode by
doxygen
1.8.3.1
gecode
int
branch.cpp
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
* Last modified:
10
* $Date: 2013-03-05 20:51:24 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
11
* $Revision: 13438 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include <
gecode/int/branch.hh
>
39
40
namespace
Gecode {
41
42
BrancherHandle
43
branch
(
Home
home,
const
IntVarArgs
&
x
,
44
IntVarBranch
vars,
IntValBranch
vals,
IntBranchFilter
bf) {
45
using namespace
Int;
46
if
(home.
failed
())
return
BrancherHandle
();
47
vars.
expand
(home,x);
48
ViewArray<IntView>
xv(home,x);
49
ViewSel<IntView>
* vs[1] = {
50
Branch::viewselint
(home,vars)
51
};
52
switch
(vals.
select
()) {
53
case
IntValBranch::SEL_VALUES_MIN
:
54
return
Branch::ViewValuesBrancher<1,true>::post
(home,xv,vs,bf);
55
break
;
56
case
IntValBranch::SEL_VALUES_MAX
:
57
return
Branch::ViewValuesBrancher<1,false>::post
(home,xv,vs,bf);
58
break
;
59
default
:
60
return
ViewValBrancher<IntView,1,int,2>::post
61
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),bf);
62
}
63
}
64
65
BrancherHandle
66
branch
(
Home
home,
const
IntVarArgs
&
x
,
67
TieBreak<IntVarBranch>
vars,
IntValBranch
vals,
IntBranchFilter
bf) {
68
using namespace
Int;
69
if
(home.
failed
())
return
BrancherHandle
();
70
vars.
a
.expand(home,x);
71
if
((vars.
a
.select() ==
IntVarBranch::SEL_NONE
) ||
72
(vars.
a
.select() ==
IntVarBranch::SEL_RND
))
73
vars.
b
=
INT_VAR_NONE
();
74
vars.
b
.expand(home,x);
75
if
((vars.
b
.select() ==
IntVarBranch::SEL_NONE
) ||
76
(vars.
b
.select() ==
IntVarBranch::SEL_RND
))
77
vars.
c
=
INT_VAR_NONE
();
78
vars.
c
.expand(home,x);
79
if
((vars.
c
.select() ==
IntVarBranch::SEL_NONE
) ||
80
(vars.
c
.select() ==
IntVarBranch::SEL_RND
))
81
vars.
d
=
INT_VAR_NONE
();
82
vars.
d
.expand(home,x);
83
if
(vars.
b
.select() ==
IntVarBranch::SEL_NONE
) {
84
return
branch
(home,x,vars.
a
,vals,bf);
85
}
else
{
86
ViewArray<IntView>
xv(home,x);
87
if
(vars.
c
.select() ==
IntVarBranch::SEL_NONE
) {
88
ViewSel<IntView>
* vs[2] = {
89
Branch::viewselint
(home,vars.
a
),
Branch::viewselint
(home,vars.
b
)
90
};
91
switch
(vals.
select
()) {
92
case
IntValBranch::SEL_VALUES_MIN
:
93
return
Branch::ViewValuesBrancher<2,true>::post
(home,xv,vs,bf);
94
break
;
95
case
IntValBranch::SEL_VALUES_MAX
:
96
return
Branch::ViewValuesBrancher<2,false>::post
(home,xv,vs,bf);
97
break
;
98
default
:
99
return
ViewValBrancher<IntView,2,int,2>
100
::post
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),bf);
101
}
102
}
else
if
(vars.
d
.select() ==
IntVarBranch::SEL_NONE
) {
103
ViewSel<IntView>
* vs[3] = {
104
Branch::viewselint
(home,vars.
a
),
Branch::viewselint
(home,vars.
b
),
105
Branch::viewselint
(home,vars.
c
)
106
};
107
switch
(vals.
select
()) {
108
case
IntValBranch::SEL_VALUES_MIN
:
109
return
Branch::ViewValuesBrancher<3,true>::post
(home,xv,vs,bf);
110
break
;
111
case
IntValBranch::SEL_VALUES_MAX
:
112
return
Branch::ViewValuesBrancher<3,false>::post
(home,xv,vs,bf);
113
break
;
114
default
:
115
return
ViewValBrancher<IntView,3,int,2>
116
::post
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),bf);
117
}
118
}
else
{
119
ViewSel<IntView>
* vs[4] = {
120
Branch::viewselint
(home,vars.
a
),
Branch::viewselint
(home,vars.
b
),
121
Branch::viewselint
(home,vars.
c
),
Branch::viewselint
(home,vars.
d
)
122
};
123
switch
(vals.
select
()) {
124
case
IntValBranch::SEL_VALUES_MIN
:
125
return
Branch::ViewValuesBrancher<4,true>::post
(home,xv,vs,bf);
126
break
;
127
case
IntValBranch::SEL_VALUES_MAX
:
128
return
Branch::ViewValuesBrancher<4,false>::post
(home,xv,vs,bf);
129
break
;
130
default
:
131
return
ViewValBrancher<IntView,4,int,2>
132
::post
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),bf);
133
}
134
}
135
}
136
}
137
138
BrancherHandle
139
branch
(
Home
home,
IntVar
x
,
IntValBranch
vals) {
140
IntVarArgs
xv(1); xv[0]=
x
;
141
return
branch
(home, xv,
INT_VAR_NONE
(), vals);
142
}
143
144
BrancherHandle
145
assign
(
Home
home,
const
IntVarArgs
&
x
,
IntAssign
ia,
146
IntBranchFilter
bf) {
147
using namespace
Int;
148
if
(home.
failed
())
return
BrancherHandle
();
149
ViewArray<IntView>
xv(home,x);
150
ViewSel<IntView>
* vs[1] = {
151
new
(home)
ViewSelNone<IntView>
(home,
INT_VAR_NONE
())
152
};
153
return
ViewValBrancher<IntView,1,int,1>::post
154
(home,xv,vs,
Branch::valselcommitint
(home,ia),bf);
155
}
156
157
BrancherHandle
158
assign
(
Home
home,
IntVar
x,
IntAssign
ia) {
159
IntVarArgs
xv(1); xv[0]=
x
;
160
return
assign
(home, xv, ia);
161
}
162
163
164
BrancherHandle
165
branch
(
Home
home,
const
BoolVarArgs
& x,
166
IntVarBranch
vars,
IntValBranch
vals,
BoolBranchFilter
bf) {
167
using namespace
Int;
168
if
(home.
failed
())
return
BrancherHandle
();
169
vars.
expand
(home,x);
170
ViewArray<BoolView>
xv(home,x);
171
ViewSel<BoolView>
* vs[1] = {
172
Branch::viewselbool
(home,vars)
173
};
174
return
ViewValBrancher<BoolView,1,int,2>::post
175
(home,xv,vs,
Branch::valselcommitbool
(home,x.
size
(),vals),bf);
176
}
177
178
BrancherHandle
179
branch
(
Home
home,
const
BoolVarArgs
& x,
180
TieBreak<IntVarBranch>
vars,
IntValBranch
vals,
181
BoolBranchFilter
bf) {
182
using namespace
Int;
183
if
(home.
failed
())
return
BrancherHandle
();
184
vars.
a
.expand(home,x);
185
if
((vars.
a
.select() ==
IntVarBranch::SEL_NONE
) ||
186
(vars.
a
.select() ==
IntVarBranch::SEL_RND
))
187
vars.
b
=
INT_VAR_NONE
();
188
vars.
b
.expand(home,x);
189
if
((vars.
b
.select() ==
IntVarBranch::SEL_NONE
) ||
190
(vars.
b
.select() ==
IntVarBranch::SEL_RND
))
191
vars.
c
=
INT_VAR_NONE
();
192
vars.
c
.expand(home,x);
193
if
((vars.
c
.select() ==
IntVarBranch::SEL_NONE
) ||
194
(vars.
c
.select() ==
IntVarBranch::SEL_RND
))
195
vars.
d
=
INT_VAR_NONE
();
196
vars.
d
.expand(home,x);
197
if
(vars.
b
.select() ==
IntVarBranch::SEL_NONE
) {
198
return
branch
(home,x,vars.
a
,vals,bf);
199
}
else
{
200
ViewArray<BoolView>
xv(home,x);
201
ValSelCommitBase<BoolView,int>
*
202
vsc =
Branch::valselcommitbool
(home,x.
size
(),vals);
203
if
(vars.
c
.select() ==
IntVarBranch::SEL_NONE
) {
204
ViewSel<BoolView>
* vs[2] = {
205
Branch::viewselbool
(home,vars.
a
),
Branch::viewselbool
(home,vars.
b
)
206
};
207
return
ViewValBrancher<BoolView,2,int,2>::post
(home,xv,vs,vsc,bf);
208
}
else
if
(vars.
d
.select() ==
IntVarBranch::SEL_NONE
) {
209
ViewSel<BoolView>
* vs[3] = {
210
Branch::viewselbool
(home,vars.
a
),
Branch::viewselbool
(home,vars.
b
),
211
Branch::viewselbool
(home,vars.
c
)
212
};
213
return
ViewValBrancher<BoolView,3,int,2>::post
(home,xv,vs,vsc,bf);
214
}
else
{
215
ViewSel<BoolView>
* vs[4] = {
216
Branch::viewselbool
(home,vars.
a
),
Branch::viewselbool
(home,vars.
b
),
217
Branch::viewselbool
(home,vars.
c
),
Branch::viewselbool
(home,vars.
d
)
218
};
219
return
ViewValBrancher<BoolView,4,int,2>::post
(home,xv,vs,vsc,bf);
220
}
221
}
222
}
223
224
BrancherHandle
225
branch
(
Home
home,
BoolVar
x,
IntValBranch
vals) {
226
BoolVarArgs
xv(1); xv[0]=
x
;
227
return
branch
(home, xv,
INT_VAR_NONE
(), vals);
228
}
229
230
BrancherHandle
231
assign
(
Home
home,
const
BoolVarArgs
& x,
IntAssign
ia,
232
BoolBranchFilter
bf) {
233
using namespace
Int;
234
if
(home.
failed
())
return
BrancherHandle
();
235
ViewArray<BoolView>
xv(home,x);
236
ViewSel<BoolView>
* vs[1] = {
237
new
(home)
ViewSelNone<BoolView>
(home,
INT_VAR_NONE
())
238
};
239
return
ViewValBrancher<BoolView,1,int,1>::post
240
(home,xv,vs,
Branch::valselcommitbool
(home,ia),bf);
241
}
242
243
BrancherHandle
244
assign
(
Home
home,
BoolVar
x,
IntAssign
ia) {
245
BoolVarArgs
xv(1); xv[0]=
x
;
246
return
assign
(home, xv, ia);
247
}
248
249
}
250
251
// STATISTICS: int-post