Generated on Sat Jul 28 2018 17:10:27 for Gecode by doxygen 1.8.14
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,
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,
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);
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
110  FloatVarArgs xv(1); xv[0]=x;
111  branch(home, xv, FLOAT_VAR_NONE(), vals, nullptr, vvp);
112  }
113 
114  void
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
130  FloatVarArgs xv(1); xv[0]=x;
131  assign(home, xv, fa, nullptr, vvp);
132  }
133 
134 }
135 
136 // STATISTICS: float-post
Combine variable selection criteria for tie-breaking.
Which values to select for branching first.
Definition: float.hh:1757
First unassigned.
Definition: float.hh:1609
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
Passing float variables.
Definition: float.hh:981
Abstract class for view selection.
void expand(Home home, const FloatVarArgs &x)
Expand AFC, action, and CHB.
Definition: var.hpp:78
Which variable to select for branching.
Definition: float.hh:1605
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:101
Base class for value selection and commit.
Select the first unassigned view.
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:4099
ViewSel< FloatView > * viewsel(Space &home, const FloatVarBranch &fvb)
Return view selectors for float views.
Definition: view-sel.cpp:43
View arrays.
Definition: array.hpp:234
Random (uniform, for tie breaking)
Definition: float.hh:1610
std::function< bool(const Space &home, FloatVar x, int i)> FloatBranchFilter
Branch filter function type for float variables.
Definition: float.hh:1388
VarBranch a
Branching criteria to try in order.
Which values to select for assignment.
Definition: float.hh:1811
Post propagator for SetVar x
Definition: set.hh:784
Float variables.
Definition: float.hh:874
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 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:115
Home class for posting propagators
Definition: core.hpp:922
ValSelCommitBase< FloatView, FloatNumBranch > * valselcommit(Space &home, const FloatValBranch &fvb)
Return value and commit for float views.