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
float
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-02-25 21:43:24 +0100 (Mon, 25 Feb 2013) $ by $Author: schulte $
11
* $Revision: 13406 $
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/float/branch.hh
>
39
40
namespace
Gecode {
41
42
BrancherHandle
43
branch
(
Home
home,
const
FloatVarArgs
&
x
,
44
FloatVarBranch
vars,
FloatValBranch
vals,
FloatBranchFilter
bf) {
45
using namespace
Float;
46
if
(home.
failed
())
return
BrancherHandle
();
47
vars.
expand
(home,x);
48
ViewArray<FloatView>
xv(home,x);
49
ViewSel<FloatView>
* vs[1] = {
50
Branch::viewsel
(home,vars)
51
};
52
if
(vals.
select
() ==
FloatValBranch::SEL_SPLIT_RND
) {
53
ValSelCommitBase<FloatView,std::pair<FloatNum,bool>
>* vsc
54
=
new
(home)
55
ValSelCommit<Branch::ValSelRnd,Branch::ValCommitLqGq>
(home,vals);
56
return
ViewValBrancher<FloatView,1,std::pair<FloatNum,bool>
,2>
::post
57
(home,xv,vs,vsc,bf);
58
}
else
{
59
return
ViewValBrancher<FloatView,1,FloatNum,2>::post
60
(home,xv,vs,
Branch::valselcommit
(home,vals),bf);
61
}
62
}
63
64
BrancherHandle
65
branch
(
Home
home,
const
FloatVarArgs
&
x
,
66
TieBreak<FloatVarBranch>
vars,
FloatValBranch
vals,
67
FloatBranchFilter
bf) {
68
using namespace
Float;
69
if
(home.
failed
())
return
BrancherHandle
();
70
vars.
a
.expand(home,x);
71
if
((vars.
a
.select() ==
FloatVarBranch::SEL_NONE
) ||
72
(vars.
a
.select() ==
FloatVarBranch::SEL_RND
))
73
vars.
b
=
FLOAT_VAR_NONE
();
74
vars.
b
.expand(home,x);
75
if
((vars.
b
.select() ==
FloatVarBranch::SEL_NONE
) ||
76
(vars.
b
.select() ==
FloatVarBranch::SEL_RND
))
77
vars.
c
=
FLOAT_VAR_NONE
();
78
vars.
c
.expand(home,x);
79
if
((vars.
c
.select() ==
FloatVarBranch::SEL_NONE
) ||
80
(vars.
c
.select() ==
FloatVarBranch::SEL_RND
))
81
vars.
d
=
FLOAT_VAR_NONE
();
82
vars.
d
.expand(home,x);
83
if
(vars.
b
.select() ==
FloatVarBranch::SEL_NONE
) {
84
return
branch
(home,x,vars.
a
,vals,bf);
85
}
else
{
86
ViewArray<FloatView>
xv(home,x);
87
if
(vals.
select
() ==
FloatValBranch::SEL_SPLIT_RND
) {
88
ValSelCommitBase<FloatView,std::pair<FloatNum,bool>
>* vsc
89
=
new
(home)
90
ValSelCommit<Branch::ValSelRnd,Branch::ValCommitLqGq>
(home,vals);
91
if
(vars.
c
.select() ==
FloatVarBranch::SEL_NONE
) {
92
ViewSel<FloatView>
* vs[2] = {
93
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
)
94
};
95
return
ViewValBrancher<FloatView,2,std::pair<FloatNum,bool>
,2>
96
::post
(home,xv,vs,vsc,bf);
97
}
else
if
(vars.
d
.select() ==
FloatVarBranch::SEL_NONE
) {
98
ViewSel<FloatView>
* vs[3] = {
99
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
100
Branch::viewsel
(home,vars.
c
)
101
};
102
return
ViewValBrancher<FloatView,3,std::pair<FloatNum,bool>
,2>
103
::post
(home,xv,vs,vsc,bf);
104
}
else
{
105
ViewSel<FloatView>
* vs[4] = {
106
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
107
Branch::viewsel
(home,vars.
c
),
Branch::viewsel
(home,vars.
d
)
108
};
109
return
ViewValBrancher<FloatView,4,std::pair<FloatNum,bool>
,2>
110
::post
(home,xv,vs,vsc,bf);
111
}
112
}
else
{
113
ValSelCommitBase<FloatView,FloatNum>
*
114
vsc =
Branch::valselcommit
(home,vals);
115
if
(vars.
c
.select() ==
FloatVarBranch::SEL_NONE
) {
116
ViewSel<FloatView>
* vs[2] = {
117
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
)
118
};
119
return
ViewValBrancher<FloatView,2,FloatNum,2>
120
::post
(home,xv,vs,vsc,bf);
121
}
else
if
(vars.
d
.select() ==
FloatVarBranch::SEL_NONE
) {
122
ViewSel<FloatView>
* vs[3] = {
123
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
124
Branch::viewsel
(home,vars.
c
)
125
};
126
return
ViewValBrancher<FloatView,3,FloatNum,2>
127
::post
(home,xv,vs,vsc,bf);
128
}
else
{
129
ViewSel<FloatView>
* vs[4] = {
130
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
131
Branch::viewsel
(home,vars.
c
),
Branch::viewsel
(home,vars.
d
)
132
};
133
return
ViewValBrancher<FloatView,4,FloatNum,2>
134
::post
(home,xv,vs,vsc,bf);
135
}
136
}
137
}
138
}
139
140
BrancherHandle
141
branch
(
Home
home,
FloatVar
x
,
FloatValBranch
vals) {
142
FloatVarArgs
xv(1); xv[0]=
x
;
143
return
branch
(home, xv,
FLOAT_VAR_NONE
(), vals);
144
}
145
146
BrancherHandle
147
assign
(
Home
home,
const
FloatVarArgs
&
x
,
FloatAssign
fa,
148
FloatBranchFilter
bf) {
149
using namespace
Float;
150
if
(home.
failed
())
return
BrancherHandle
();
151
ViewArray<FloatView>
xv(home,x);
152
ViewSel<FloatView>
* vs[1] = {
153
new
(home)
ViewSelNone<FloatView>
(home,
FLOAT_VAR_NONE
())
154
};
155
if
(fa.
select
() ==
FloatAssign::SEL_RND
) {
156
ValSelCommitBase<FloatView,std::pair<FloatNum,bool>
>* vsc
157
=
new
(home)
158
ValSelCommit<Branch::ValSelRnd,Branch::ValCommitLqGq>
(home,fa);
159
return
ViewValBrancher<FloatView,1,std::pair<FloatNum,bool>
,1>
::post
160
(home,xv,vs,vsc,bf);
161
}
else
{
162
return
ViewValBrancher<FloatView,1,FloatNum,1>::post
163
(home,xv,vs,
Branch::valselcommit
(home,fa),bf);
164
}
165
}
166
167
BrancherHandle
168
assign
(
Home
home,
FloatVar
x,
FloatAssign
fa) {
169
FloatVarArgs
xv(1); xv[0]=
x
;
170
return
assign
(home, xv, fa);
171
}
172
173
}
174
175
// STATISTICS: float-post