Generated on Fri Jan 10 2020 11:38:25 for Gecode by doxygen 1.8.16
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include <gecode/float/branch.hh>
35 
36 namespace Gecode {
37 
38  void
39  branch(Home home, const FloatVarArgs& x,
40  FloatVarBranch vars, FloatValBranch vals,
42  FloatVarValPrint vvp) {
43  using namespace Float;
44  if (home.failed()) return;
45  vars.expand(home,x);
46  ViewArray<FloatView> xv(home,x);
47  ViewSel<FloatView>* vs[1] = {
48  Branch::viewsel(home,vars)
49  };
50  postviewvalbrancher<FloatView,1,FloatNumBranch,2>
51  (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
52  }
53 
54  void
55  branch(Home home, const FloatVarArgs& x,
58  FloatVarValPrint vvp) {
59  using namespace Float;
60  if (home.failed()) return;
61  vars.a.expand(home,x);
62  if ((vars.a.select() == FloatVarBranch::SEL_NONE) ||
63  (vars.a.select() == FloatVarBranch::SEL_RND))
64  vars.b = FLOAT_VAR_NONE();
65  vars.b.expand(home,x);
66  if ((vars.b.select() == FloatVarBranch::SEL_NONE) ||
67  (vars.b.select() == FloatVarBranch::SEL_RND))
68  vars.c = FLOAT_VAR_NONE();
69  vars.c.expand(home,x);
70  if ((vars.c.select() == FloatVarBranch::SEL_NONE) ||
71  (vars.c.select() == FloatVarBranch::SEL_RND))
72  vars.d = FLOAT_VAR_NONE();
73  vars.d.expand(home,x);
74  if (vars.b.select() == FloatVarBranch::SEL_NONE) {
75  branch(home,x,vars.a,vals,bf,vvp);
76  } else {
77  ViewArray<FloatView> xv(home,x);
79  vsc = Branch::valselcommit(home,vals);
80  if (vars.c.select() == FloatVarBranch::SEL_NONE) {
81  ViewSel<FloatView>* vs[2] = {
82  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
83  };
84  postviewvalbrancher<FloatView,2,FloatNumBranch,2>
85  (home,xv,vs,vsc,bf,vvp);
86  } else if (vars.d.select() == FloatVarBranch::SEL_NONE) {
87  ViewSel<FloatView>* vs[3] = {
88  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
89  Branch::viewsel(home,vars.c)
90  };
91  postviewvalbrancher<FloatView,3,FloatNumBranch,2>
92  (home,xv,vs,vsc,bf,vvp);
93  } else {
94  ViewSel<FloatView>* vs[4] = {
95  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
96  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
97  };
98  postviewvalbrancher<FloatView,4,FloatNumBranch,2>
99  (home,xv,vs,vsc,bf,vvp);
100  }
101  }
102  }
103 
104  void
106  FloatVarArgs xv(1); xv[0]=x;
107  branch(home, xv, FLOAT_VAR_NONE(), vals, nullptr, vvp);
108  }
109 
110  void
111  assign(Home home, const FloatVarArgs& x,
112  FloatVarBranch vars, FloatAssign vals,
114  FloatVarValPrint vvp) {
115  using namespace Float;
116  if (home.failed()) return;
117  ViewArray<FloatView> xv(home,x);
118  ViewSel<FloatView>* vs[1] = {
119  new (home) ViewSelNone<FloatView>(home,vars)
120  };
121  postviewvalbrancher<FloatView,1,FloatNumBranch,1>
122  (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
123  }
124 
125  void
126  assign(Home home, const FloatVarArgs& x,
129  FloatVarValPrint vvp) {
130  using namespace Float;
131  if (home.failed()) return;
132  vars.a.expand(home,x);
133  if ((vars.a.select() == FloatVarBranch::SEL_NONE) ||
134  (vars.a.select() == FloatVarBranch::SEL_RND))
135  vars.b = FLOAT_VAR_NONE();
136  vars.b.expand(home,x);
137  if ((vars.b.select() == FloatVarBranch::SEL_NONE) ||
138  (vars.b.select() == FloatVarBranch::SEL_RND))
139  vars.c = FLOAT_VAR_NONE();
140  vars.c.expand(home,x);
141  if ((vars.c.select() == FloatVarBranch::SEL_NONE) ||
142  (vars.c.select() == FloatVarBranch::SEL_RND))
143  vars.d = FLOAT_VAR_NONE();
144  vars.d.expand(home,x);
145  if (vars.b.select() == FloatVarBranch::SEL_NONE) {
146  assign(home,x,vars.a,vals,bf,vvp);
147  } else {
148  ViewArray<FloatView> xv(home,x);
150  vsc = Branch::valselcommit(home,vals);
151  if (vars.c.select() == FloatVarBranch::SEL_NONE) {
152  ViewSel<FloatView>* vs[2] = {
153  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
154  };
155  postviewvalbrancher<FloatView,2,FloatNumBranch,1>
156  (home,xv,vs,vsc,bf,vvp);
157  } else if (vars.d.select() == FloatVarBranch::SEL_NONE) {
158  ViewSel<FloatView>* vs[3] = {
159  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
160  Branch::viewsel(home,vars.c)
161  };
162  postviewvalbrancher<FloatView,3,FloatNumBranch,1>
163  (home,xv,vs,vsc,bf,vvp);
164  } else {
165  ViewSel<FloatView>* vs[4] = {
166  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
167  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
168  };
169  postviewvalbrancher<FloatView,4,FloatNumBranch,1>
170  (home,xv,vs,vsc,bf,vvp);
171  }
172  }
173  }
174 
175  void
177  FloatVarArgs xv(1); xv[0]=x;
178  assign(home, xv, FLOAT_VAR_NONE(), vals, nullptr, vvp);
179  }
180 
181 }
182 
183 // STATISTICS: float-post
Passing float variables.
Definition: float.hh:979
Post propagator for SetVar x
Definition: set.hh:767
VarBranch b
Definition: tiebreak.hpp:41
void expand(Home home, const FloatVarArgs &x)
Expand AFC, action, and CHB.
Definition: var.hpp:74
Select the first unassigned view.
Definition: view-sel.hpp:109
Combine variable selection criteria for tie-breaking.
Definition: tiebreak.hpp:38
ValSelCommitBase< FloatView, FloatNumBranch > * valselcommit(Space &home, const FloatValBranch &fvb)
Return value and commit for float views.
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:1657
Which values to select for branching first.
Definition: float.hh:1820
First unassigned.
Definition: float.hh:1672
Which variable to select for branching.
Definition: float.hh:1668
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:97
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:39
Gecode toplevel namespace
Home class for posting propagators
Definition: core.hpp:856
VarBranch d
Definition: tiebreak.hpp:41
VarBranch c
Definition: tiebreak.hpp:41
void assign(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatAssign vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with variable selection vars and value selection vals.
Definition: branch.cpp:111
Base class for value selection and commit.
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:4048
std::function< bool(const Space &home, FloatVar x, int i)> FloatBranchFilter
Branch filter function type for float variables.
Definition: float.hh:1442
ViewSel< FloatView > * viewsel(Space &home, const FloatVarBranch &fvb)
Return view selectors for float views.
Definition: view-sel.cpp:39
Float variables.
Definition: float.hh:870
Abstract class for view selection.
Definition: view-sel.hpp:44
Which values to select for assignment.
Definition: float.hh:1874
View arrays.
Definition: array.hpp:253
Random (uniform, for tie breaking)
Definition: float.hh:1673
VarBranch a
Branching criteria to try in order.
Definition: tiebreak.hpp:41