main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Oct 22 2013 00:49:00 for Gecode by
doxygen
1.8.4
gecode
set
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/set/branch.hh
>
39
40
namespace
Gecode {
41
BrancherHandle
42
branch
(
Home
home,
const
SetVarArgs
&
x
,
43
SetVarBranch
vars,
SetValBranch
vals,
44
SetBranchFilter
bf,
SetVarValPrint
vvp) {
45
using namespace
Set;
46
if
(home.
failed
())
return
BrancherHandle
();
47
vars.
expand
(home,x);
48
ViewArray<SetView>
xv(home,x);
49
ViewSel<SetView>
* vs[1] = {
50
Branch::viewsel
(home,vars)
51
};
52
return
ViewValBrancher<SetView,1,int,2>::post
53
(home,xv,vs,
Branch::valselcommit
(home,vals),bf,vvp);
54
}
55
56
BrancherHandle
57
branch
(
Home
home,
const
SetVarArgs
&
x
,
58
TieBreak<SetVarBranch>
vars,
SetValBranch
vals,
59
SetBranchFilter
bf,
SetVarValPrint
vvp) {
60
using namespace
Set;
61
if
(home.
failed
())
return
BrancherHandle
();
62
vars.
a
.expand(home,x);
63
if
((vars.
a
.select() ==
SetVarBranch::SEL_NONE
) ||
64
(vars.
a
.select() ==
SetVarBranch::SEL_RND
))
65
vars.
b
=
SET_VAR_NONE
();
66
vars.
b
.expand(home,x);
67
if
((vars.
b
.select() ==
SetVarBranch::SEL_NONE
) ||
68
(vars.
b
.select() ==
SetVarBranch::SEL_RND
))
69
vars.
c
=
SET_VAR_NONE
();
70
vars.
c
.expand(home,x);
71
if
((vars.
c
.select() ==
SetVarBranch::SEL_NONE
) ||
72
(vars.
c
.select() ==
SetVarBranch::SEL_RND
))
73
vars.
d
=
SET_VAR_NONE
();
74
vars.
d
.expand(home,x);
75
if
(vars.
b
.select() ==
SetVarBranch::SEL_NONE
) {
76
return
branch
(home,x,vars.
a
,vals,bf,vvp);
77
}
else
{
78
ViewArray<SetView>
xv(home,x);
79
ValSelCommitBase<SetView,int>
* vsc =
Branch::valselcommit
(home,vals);
80
if
(vars.
c
.select() ==
SetVarBranch::SEL_NONE
) {
81
ViewSel<SetView>
* vs[2] = {
82
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
)
83
};
84
return
ViewValBrancher<SetView,2,int,2>::post
(home,xv,vs,vsc,bf,vvp);
85
}
else
if
(vars.
d
.select() ==
SetVarBranch::SEL_NONE
) {
86
ViewSel<SetView>
* vs[3] = {
87
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
88
Branch::viewsel
(home,vars.
c
)
89
};
90
return
ViewValBrancher<SetView,3,int,2>::post
(home,xv,vs,vsc,bf,vvp);
91
}
else
{
92
ViewSel<SetView>
* vs[4] = {
93
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
94
Branch::viewsel
(home,vars.
c
),
Branch::viewsel
(home,vars.
d
)
95
};
96
return
ViewValBrancher<SetView,4,int,2>::post
(home,xv,vs,vsc,bf,vvp);
97
}
98
}
99
}
100
101
BrancherHandle
102
branch
(
Home
home,
SetVar
x
,
SetValBranch
vals,
SetVarValPrint
vvp) {
103
SetVarArgs
xv(1); xv[0]=
x
;
104
return
branch
(home, xv,
SET_VAR_NONE
(), vals, NULL, vvp);
105
}
106
107
BrancherHandle
108
assign
(
Home
home,
const
SetVarArgs
&
x
,
SetAssign
sa,
109
SetBranchFilter
bf,
SetVarValPrint
vvp) {
110
using namespace
Set;
111
if
(home.
failed
())
return
BrancherHandle
();
112
ViewArray<SetView>
xv(home,x);
113
ViewSel<SetView>
* vs[1] = {
114
new
(home)
ViewSelNone<SetView>
(home,
SET_VAR_NONE
())
115
};
116
return
ViewValBrancher<SetView,1,int,1>::post
117
(home,xv,vs,
Branch::valselcommit
(home,sa),bf,vvp);
118
}
119
120
BrancherHandle
121
assign
(
Home
home,
SetVar
x,
SetAssign
sa,
SetVarValPrint
vvp) {
122
SetVarArgs
xv(1); xv[0]=
x
;
123
return
assign
(home, xv, sa, NULL, vvp);
124
}
125
126
}
127
128
// STATISTICS: set-post