main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
11
* $Revision: 15623 $
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
void
43
branch
(
Home
home,
const
FloatVarArgs
&
x
,
44
FloatVarBranch
vars,
FloatValBranch
vals,
45
FloatBranchFilter
bf,
46
FloatVarValPrint
vvp) {
47
using namespace
Float;
48
if
(home.
failed
())
return
;
49
vars.
expand
(home,
x
);
50
ViewArray<FloatView>
xv(home,
x
);
51
ViewSel<FloatView>
* vs[1] = {
52
Branch::viewsel
(home,vars)
53
};
54
postviewvalbrancher<FloatView,1,FloatNumBranch,2>
55
(home,xv,vs,
Branch::valselcommit
(home,vals),bf,vvp);
56
}
57
58
void
59
branch
(
Home
home,
const
FloatVarArgs
&
x
,
60
TieBreak<FloatVarBranch>
vars,
FloatValBranch
vals,
61
FloatBranchFilter
bf,
62
FloatVarValPrint
vvp) {
63
using namespace
Float;
64
if
(home.
failed
())
return
;
65
vars.
a
.expand(home,
x
);
66
if
((vars.
a
.select() ==
FloatVarBranch::SEL_NONE
) ||
67
(vars.
a
.select() ==
FloatVarBranch::SEL_RND
))
68
vars.
b
=
FLOAT_VAR_NONE
();
69
vars.
b
.expand(home,
x
);
70
if
((vars.
b
.select() ==
FloatVarBranch::SEL_NONE
) ||
71
(vars.
b
.select() ==
FloatVarBranch::SEL_RND
))
72
vars.
c
=
FLOAT_VAR_NONE
();
73
vars.
c
.expand(home,
x
);
74
if
((vars.
c
.select() ==
FloatVarBranch::SEL_NONE
) ||
75
(vars.
c
.select() ==
FloatVarBranch::SEL_RND
))
76
vars.
d
=
FLOAT_VAR_NONE
();
77
vars.
d
.expand(home,
x
);
78
if
(vars.
b
.select() ==
FloatVarBranch::SEL_NONE
) {
79
branch
(home,
x
,vars.
a
,vals,bf,vvp);
80
}
else
{
81
ViewArray<FloatView>
xv(home,
x
);
82
ValSelCommitBase<FloatView,FloatNumBranch>
*
83
vsc =
Branch::valselcommit
(home,vals);
84
if
(vars.
c
.select() ==
FloatVarBranch::SEL_NONE
) {
85
ViewSel<FloatView>
* vs[2] = {
86
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
)
87
};
88
postviewvalbrancher<FloatView,2,FloatNumBranch,2>
89
(home,xv,vs,vsc,bf,vvp);
90
}
else
if
(vars.
d
.select() ==
FloatVarBranch::SEL_NONE
) {
91
ViewSel<FloatView>
* vs[3] = {
92
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
93
Branch::viewsel
(home,vars.
c
)
94
};
95
postviewvalbrancher<FloatView,3,FloatNumBranch,2>
96
(home,xv,vs,vsc,bf,vvp);
97
}
else
{
98
ViewSel<FloatView>
* vs[4] = {
99
Branch::viewsel
(home,vars.
a
),
Branch::viewsel
(home,vars.
b
),
100
Branch::viewsel
(home,vars.
c
),
Branch::viewsel
(home,vars.
d
)
101
};
102
postviewvalbrancher<FloatView,4,FloatNumBranch,2>
103
(home,xv,vs,vsc,bf,vvp);
104
}
105
}
106
}
107
108
void
109
branch
(
Home
home,
FloatVar
x
,
FloatValBranch
vals,
FloatVarValPrint
vvp) {
110
FloatVarArgs
xv(1); xv[0]=
x
;
111
branch
(home, xv,
FLOAT_VAR_NONE
(), vals,
nullptr
, vvp);
112
}
113
114
void
115
assign
(
Home
home,
const
FloatVarArgs
&
x
,
FloatAssign
fa,
116
FloatBranchFilter
bf,
117
FloatVarValPrint
vvp) {
118
using namespace
Float;
119
if
(home.
failed
())
return
;
120
ViewArray<FloatView>
xv(home,
x
);
121
ViewSel<FloatView>
* vs[1] = {
122
new
(home)
ViewSelNone<FloatView>
(home,
FLOAT_VAR_NONE
())
123
};
124
postviewvalbrancher<FloatView,1,FloatNumBranch,1>
125
(home,xv,vs,
Branch::valselcommit
(home,fa),bf,vvp);
126
}
127
128
void
129
assign
(
Home
home,
FloatVar
x
,
FloatAssign
fa,
FloatVarValPrint
vvp) {
130
FloatVarArgs
xv(1); xv[0]=
x
;
131
assign
(home, xv, fa,
nullptr
, vvp);
132
}
133
134
}
135
136
// STATISTICS: float-post
Gecode::FloatVarArgs
Passing float variables.
Definition:
float.hh:981
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::TieBreak::b
VarBranch b
Definition:
branch-tiebreak.hpp:45
Gecode::assign
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition:
branch.cpp:115
Gecode::FloatVarBranch::expand
void expand(Home home, const FloatVarArgs &x)
Expand AFC, action, and CHB.
Definition:
var.hpp:78
Gecode::ViewSelNone
Select the first unassigned view.
Definition:
brancher-view-sel.hpp:113
Gecode::TieBreak
Combine variable selection criteria for tie-breaking.
Definition:
branch-tiebreak.hpp:42
Gecode::Float::Branch::valselcommit
ValSelCommitBase< FloatView, FloatNumBranch > * valselcommit(Space &home, const FloatValBranch &fvb)
Return value and commit for float views.
Definition:
val-sel-commit.cpp:43
Gecode::FloatVarValPrint
std::function< void(const Space &home, const Brancher &b, unsigned int a, FloatVar x, int i, const FloatNumBranch &n, std::ostream &o)> FloatVarValPrint
Function type for explaining branching alternatives for float variables.
Definition:
float.hh:1594
Gecode::FloatValBranch
Which values to select for branching first.
Definition:
float.hh:1757
Gecode::FloatVarBranch::SEL_NONE
@ SEL_NONE
First unassigned.
Definition:
float.hh:1609
Gecode::FloatVarBranch
Which variable to select for branching.
Definition:
float.hh:1605
Gecode::FLOAT_VAR_NONE
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition:
var.hpp:101
Gecode::branch
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Definition:
branch.cpp:43
Gecode
Gecode toplevel namespace
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::TieBreak::d
VarBranch d
Definition:
branch-tiebreak.hpp:45
Gecode::TieBreak::c
VarBranch c
Definition:
branch-tiebreak.hpp:45
Gecode::ValSelCommitBase
Base class for value selection and commit.
Definition:
brancher-val-sel-commit.hpp:48
branch.hh
Gecode::Home::failed
bool failed(void) const
Check whether corresponding space is failed.
Definition:
core.hpp:4099
Gecode::FloatBranchFilter
std::function< bool(const Space &home, FloatVar x, int i)> FloatBranchFilter
Branch filter function type for float variables.
Definition:
float.hh:1388
Gecode::Float::Branch::viewsel
ViewSel< FloatView > * viewsel(Space &home, const FloatVarBranch &fvb)
Return view selectors for float views.
Definition:
view-sel.cpp:43
Gecode::FloatVar
Float variables.
Definition:
float.hh:874
Gecode::ViewSel
Abstract class for view selection.
Definition:
brancher-view-sel.hpp:48
Gecode::FloatAssign
Which values to select for assignment.
Definition:
float.hh:1811
Gecode::ViewArray
View arrays.
Definition:
array.hpp:234
Gecode::FloatVarBranch::SEL_RND
@ SEL_RND
Random (uniform, for tie breaking)
Definition:
float.hh:1610
Gecode::TieBreak::a
VarBranch a
Branching criteria to try in order.
Definition:
branch-tiebreak.hpp:45