Generated on Sat Jan 12 2019 20:58:51 for Gecode by doxygen 1.8.13
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
113  FloatVarValPrint vvp) {
114  using namespace Float;
115  if (home.failed()) return;
116  ViewArray<FloatView> xv(home,x);
117  ViewSel<FloatView>* vs[1] = {
118  new (home) ViewSelNone<FloatView>(home,FLOAT_VAR_NONE())
119  };
120  postviewvalbrancher<FloatView,1,FloatNumBranch,1>
121  (home,xv,vs,Branch::valselcommit(home,fa),bf,vvp);
122  }
123 
124  void
126  FloatVarArgs xv(1); xv[0]=x;
127  assign(home, xv, fa, nullptr, vvp);
128  }
129 
130 }
131 
132 // STATISTICS: float-post
Combine variable selection criteria for tie-breaking.
Definition: tiebreak.hpp:38
Which values to select for branching first.
Definition: float.hh:1820
First unassigned.
Definition: float.hh:1672
VarBranch c
Definition: tiebreak.hpp:41
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
Passing float variables.
Definition: float.hh:979
Abstract class for view selection.
Definition: view-sel.hpp:44
void expand(Home home, const FloatVarArgs &x)
Expand AFC, action, and CHB.
Definition: var.hpp:74
Which variable to select for branching.
Definition: float.hh:1668
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:97
Base class for value selection and commit.
Select the first unassigned view.
Definition: view-sel.hpp:109
VarBranch b
Definition: tiebreak.hpp:41
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3975
ViewSel< FloatView > * viewsel(Space &home, const FloatVarBranch &fvb)
Return view selectors for float views.
Definition: view-sel.cpp:39
View arrays.
Definition: array.hpp:235
Random (uniform, for tie breaking)
Definition: float.hh:1673
std::function< bool(const Space &home, FloatVar x, int i)> FloatBranchFilter
Branch filter function type for float variables.
Definition: float.hh:1442
VarBranch a
Branching criteria to try in order.
Definition: tiebreak.hpp:41
Which values to select for assignment.
Definition: float.hh:1874
Post propagator for SetVar x
Definition: set.hh:767
Float variables.
Definition: float.hh:870
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
Gecode toplevel namespace
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:111
Home class for posting propagators
Definition: core.hpp:853
ValSelCommitBase< FloatView, FloatNumBranch > * valselcommit(Space &home, const FloatValBranch &fvb)
Return value and commit for float views.
VarBranch d
Definition: tiebreak.hpp:41