main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:25 for Gecode by
doxygen
1.8.4
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-05-02 17:10:16 +0200 (Thu, 02 May 2013) $ by $Author: schulte $
11
* $Revision: 13603 $
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,
45
IntBranchFilter
bf,
IntVarValPrint
vvp) {
46
using namespace
Int;
47
if
(home.
failed
())
return
BrancherHandle
();
48
vars.
expand
(home,x);
49
ViewArray<IntView>
xv(home,x);
50
ViewSel<IntView>
* vs[1] = {
51
Branch::viewselint
(home,vars)
52
};
53
switch
(vals.
select
()) {
54
case
IntValBranch::SEL_VALUES_MIN
:
55
return
Branch::ViewValuesBrancher<1,true>::post
(home,xv,vs,bf,vvp);
56
break
;
57
case
IntValBranch::SEL_VALUES_MAX
:
58
return
Branch::ViewValuesBrancher<1,false>::post
(home,xv,vs,bf,vvp);
59
break
;
60
default
:
61
return
ViewValBrancher<IntView,1,int,2>::post
62
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),bf,vvp);
63
}
64
}
65
66
BrancherHandle
67
branch
(
Home
home,
const
IntVarArgs
&
x
,
68
TieBreak<IntVarBranch>
vars,
IntValBranch
vals,
69
IntBranchFilter
bf,
IntVarValPrint
vvp) {
70
using namespace
Int;
71
if
(home.
failed
())
return
BrancherHandle
();
72
vars.
a
.expand(home,x);
73
if
((vars.
a
.select() ==
IntVarBranch::SEL_NONE
) ||
74
(vars.
a
.select() ==
IntVarBranch::SEL_RND
))
75
vars.
b
=
INT_VAR_NONE
();
76
vars.
b
.expand(home,x);
77
if
((vars.
b
.select() ==
IntVarBranch::SEL_NONE
) ||
78
(vars.
b
.select() ==
IntVarBranch::SEL_RND
))
79
vars.
c
=
INT_VAR_NONE
();
80
vars.
c
.expand(home,x);
81
if
((vars.
c
.select() ==
IntVarBranch::SEL_NONE
) ||
82
(vars.
c
.select() ==
IntVarBranch::SEL_RND
))
83
vars.
d
=
INT_VAR_NONE
();
84
vars.
d
.expand(home,x);
85
if
(vars.
b
.select() ==
IntVarBranch::SEL_NONE
) {
86
return
branch
(home,x,vars.
a
,vals,bf,vvp);
87
}
else
{
88
ViewArray<IntView>
xv(home,x);
89
if
(vars.
c
.select() ==
IntVarBranch::SEL_NONE
) {
90
ViewSel<IntView>
* vs[2] = {
91
Branch::viewselint
(home,vars.
a
),
Branch::viewselint
(home,vars.
b
)
92
};
93
switch
(vals.
select
()) {
94
case
IntValBranch::SEL_VALUES_MIN
:
95
return
Branch::ViewValuesBrancher<2,true>::post
(home,xv,vs,bf,vvp);
96
break
;
97
case
IntValBranch::SEL_VALUES_MAX
:
98
return
Branch::ViewValuesBrancher<2,false>::post
(home,xv,vs,bf,vvp);
99
break
;
100
default
:
101
return
ViewValBrancher<IntView,2,int,2>
102
::post
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),
103
bf,vvp);
104
}
105
}
else
if
(vars.
d
.select() ==
IntVarBranch::SEL_NONE
) {
106
ViewSel<IntView>
* vs[3] = {
107
Branch::viewselint
(home,vars.
a
),
Branch::viewselint
(home,vars.
b
),
108
Branch::viewselint
(home,vars.
c
)
109
};
110
switch
(vals.
select
()) {
111
case
IntValBranch::SEL_VALUES_MIN
:
112
return
Branch::ViewValuesBrancher<3,true>::post
(home,xv,vs,bf,vvp);
113
break
;
114
case
IntValBranch::SEL_VALUES_MAX
:
115
return
Branch::ViewValuesBrancher<3,false>::post
(home,xv,vs,bf,vvp);
116
break
;
117
default
:
118
return
ViewValBrancher<IntView,3,int,2>
119
::post
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),
120
bf,vvp);
121
}
122
}
else
{
123
ViewSel<IntView>
* vs[4] = {
124
Branch::viewselint
(home,vars.
a
),
Branch::viewselint
(home,vars.
b
),
125
Branch::viewselint
(home,vars.
c
),
Branch::viewselint
(home,vars.
d
)
126
};
127
switch
(vals.
select
()) {
128
case
IntValBranch::SEL_VALUES_MIN
:
129
return
Branch::ViewValuesBrancher<4,true>::post
(home,xv,vs,bf,vvp);
130
break
;
131
case
IntValBranch::SEL_VALUES_MAX
:
132
return
Branch::ViewValuesBrancher<4,false>::post
(home,xv,vs,bf,vvp);
133
break
;
134
default
:
135
return
ViewValBrancher<IntView,4,int,2>
136
::post
(home,xv,vs,
Branch::valselcommitint
(home,x.
size
(),vals),
137
bf,vvp);
138
}
139
}
140
}
141
}
142
143
BrancherHandle
144
branch
(
Home
home,
IntVar
x
,
IntValBranch
vals,
IntVarValPrint
vvp) {
145
IntVarArgs
xv(1); xv[0]=
x
;
146
return
branch
(home, xv,
INT_VAR_NONE
(), vals, NULL, vvp);
147
}
148
149
BrancherHandle
150
assign
(
Home
home,
const
IntVarArgs
&
x
,
IntAssign
ia,
151
IntBranchFilter
bf,
IntVarValPrint
vvp) {
152
using namespace
Int;
153
if
(home.
failed
())
return
BrancherHandle
();
154
ViewArray<IntView>
xv(home,x);
155
ViewSel<IntView>
* vs[1] = {
156
new
(home)
ViewSelNone<IntView>
(home,
INT_VAR_NONE
())
157
};
158
return
ViewValBrancher<IntView,1,int,1>::post
159
(home,xv,vs,
Branch::valselcommitint
(home,ia),bf,vvp);
160
}
161
162
BrancherHandle
163
assign
(
Home
home,
IntVar
x,
IntAssign
ia,
IntVarValPrint
vvp) {
164
IntVarArgs
xv(1); xv[0]=
x
;
165
return
assign
(home, xv, ia, NULL, vvp);
166
}
167
168
169
BrancherHandle
170
branch
(
Home
home,
const
BoolVarArgs
& x,
171
IntVarBranch
vars,
IntValBranch
vals,
172
BoolBranchFilter
bf,
BoolVarValPrint
vvp) {
173
using namespace
Int;
174
if
(home.
failed
())
return
BrancherHandle
();
175
vars.
expand
(home,x);
176
ViewArray<BoolView>
xv(home,x);
177
ViewSel<BoolView>
* vs[1] = {
178
Branch::viewselbool
(home,vars)
179
};
180
return
ViewValBrancher<BoolView,1,int,2>::post
181
(home,xv,vs,
Branch::valselcommitbool
(home,x.
size
(),vals),bf,vvp);
182
}
183
184
BrancherHandle
185
branch
(
Home
home,
const
BoolVarArgs
& x,
186
TieBreak<IntVarBranch>
vars,
IntValBranch
vals,
187
BoolBranchFilter
bf,
BoolVarValPrint
vvp) {
188
using namespace
Int;
189
if
(home.
failed
())
return
BrancherHandle
();
190
vars.
a
.expand(home,x);
191
if
((vars.
a
.select() ==
IntVarBranch::SEL_NONE
) ||
192
(vars.
a
.select() ==
IntVarBranch::SEL_RND
))
193
vars.
b
=
INT_VAR_NONE
();
194
vars.
b
.expand(home,x);
195
if
((vars.
b
.select() ==
IntVarBranch::SEL_NONE
) ||
196
(vars.
b
.select() ==
IntVarBranch::SEL_RND
))
197
vars.
c
=
INT_VAR_NONE
();
198
vars.
c
.expand(home,x);
199
if
((vars.
c
.select() ==
IntVarBranch::SEL_NONE
) ||
200
(vars.
c
.select() ==
IntVarBranch::SEL_RND
))
201
vars.
d
=
INT_VAR_NONE
();
202
vars.
d
.expand(home,x);
203
if
(vars.
b
.select() ==
IntVarBranch::SEL_NONE
) {
204
return
branch
(home,x,vars.
a
,vals,bf,vvp);
205
}
else
{
206
ViewArray<BoolView>
xv(home,x);
207
ValSelCommitBase<BoolView,int>
*
208
vsc =
Branch::valselcommitbool
(home,x.
size
(),vals);
209
if
(vars.
c
.select() ==
IntVarBranch::SEL_NONE
) {
210
ViewSel<BoolView>
* vs[2] = {
211
Branch::viewselbool
(home,vars.
a
),
Branch::viewselbool
(home,vars.
b
)
212
};
213
return
ViewValBrancher<BoolView,2,int,2>::post
(home,xv,vs,vsc,bf,vvp);
214
}
else
if
(vars.
d
.select() ==
IntVarBranch::SEL_NONE
) {
215
ViewSel<BoolView>
* vs[3] = {
216
Branch::viewselbool
(home,vars.
a
),
Branch::viewselbool
(home,vars.
b
),
217
Branch::viewselbool
(home,vars.
c
)
218
};
219
return
ViewValBrancher<BoolView,3,int,2>::post
(home,xv,vs,vsc,bf,vvp);
220
}
else
{
221
ViewSel<BoolView>
* vs[4] = {
222
Branch::viewselbool
(home,vars.
a
),
Branch::viewselbool
(home,vars.
b
),
223
Branch::viewselbool
(home,vars.
c
),
Branch::viewselbool
(home,vars.
d
)
224
};
225
return
ViewValBrancher<BoolView,4,int,2>::post
(home,xv,vs,vsc,bf,vvp);
226
}
227
}
228
}
229
230
BrancherHandle
231
branch
(
Home
home,
BoolVar
x,
IntValBranch
vals,
BoolVarValPrint
vvp) {
232
BoolVarArgs
xv(1); xv[0]=
x
;
233
return
branch
(home, xv,
INT_VAR_NONE
(), vals, NULL, vvp);
234
}
235
236
BrancherHandle
237
assign
(
Home
home,
const
BoolVarArgs
& x,
IntAssign
ia,
238
BoolBranchFilter
bf,
BoolVarValPrint
vvp) {
239
using namespace
Int;
240
if
(home.
failed
())
return
BrancherHandle
();
241
ViewArray<BoolView>
xv(home,x);
242
ViewSel<BoolView>
* vs[1] = {
243
new
(home)
ViewSelNone<BoolView>
(home,
INT_VAR_NONE
())
244
};
245
return
ViewValBrancher<BoolView,1,int,1>::post
246
(home,xv,vs,
Branch::valselcommitbool
(home,ia),bf,vvp);
247
}
248
249
BrancherHandle
250
assign
(
Home
home,
BoolVar
x,
IntAssign
ia,
BoolVarValPrint
vvp) {
251
BoolVarArgs
xv(1); xv[0]=
x
;
252
return
assign
(home, xv, ia, NULL, vvp);
253
}
254
255
}
256
257
// STATISTICS: int-post