Generated on Sat Feb 7 2015 02:01:15 for Gecode by doxygen 1.8.9.1
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-29 13:53:43 +0200 (Wed, 29 May 2013) $ by $Author: schulte $
11  * $Revision: 13672 $
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  BrancherHandle
43  branch(Home home, const FloatVarArgs& x,
44  FloatVarBranch vars, FloatValBranch vals,
46  using namespace Float;
47  if (home.failed()) return BrancherHandle();
48  vars.expand(home,x);
49  ViewArray<FloatView> xv(home,x);
50  ViewSel<FloatView>* vs[1] = {
51  Branch::viewsel(home,vars)
52  };
54  (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
55  }
56 
57  BrancherHandle
58  branch(Home home, const FloatVarArgs& x,
61  using namespace Float;
62  if (home.failed()) return BrancherHandle();
63  vars.a.expand(home,x);
64  if ((vars.a.select() == FloatVarBranch::SEL_NONE) ||
65  (vars.a.select() == FloatVarBranch::SEL_RND))
66  vars.b = FLOAT_VAR_NONE();
67  vars.b.expand(home,x);
68  if ((vars.b.select() == FloatVarBranch::SEL_NONE) ||
69  (vars.b.select() == FloatVarBranch::SEL_RND))
70  vars.c = FLOAT_VAR_NONE();
71  vars.c.expand(home,x);
72  if ((vars.c.select() == FloatVarBranch::SEL_NONE) ||
73  (vars.c.select() == FloatVarBranch::SEL_RND))
74  vars.d = FLOAT_VAR_NONE();
75  vars.d.expand(home,x);
76  if (vars.b.select() == FloatVarBranch::SEL_NONE) {
77  return branch(home,x,vars.a,vals,bf,vvp);
78  } else {
79  ViewArray<FloatView> xv(home,x);
81  vsc = Branch::valselcommit(home,vals);
82  if (vars.c.select() == FloatVarBranch::SEL_NONE) {
83  ViewSel<FloatView>* vs[2] = {
84  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
85  };
87  ::post(home,xv,vs,vsc,bf,vvp);
88  } else if (vars.d.select() == FloatVarBranch::SEL_NONE) {
89  ViewSel<FloatView>* vs[3] = {
90  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
91  Branch::viewsel(home,vars.c)
92  };
94  ::post(home,xv,vs,vsc,bf,vvp);
95  } else {
96  ViewSel<FloatView>* vs[4] = {
97  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
98  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
99  };
101  ::post(home,xv,vs,vsc,bf,vvp);
102  }
103  }
104  }
105 
106  BrancherHandle
108  FloatVarArgs xv(1); xv[0]=x;
109  return branch(home, xv, FLOAT_VAR_NONE(), vals, NULL, vvp);
110  }
111 
112  BrancherHandle
115  using namespace Float;
116  if (home.failed()) return BrancherHandle();
117  ViewArray<FloatView> xv(home,x);
118  ViewSel<FloatView>* vs[1] = {
119  new (home) ViewSelNone<FloatView>(home,FLOAT_VAR_NONE())
120  };
122  (home,xv,vs,Branch::valselcommit(home,fa),bf,vvp);
123  }
124 
127  FloatVarArgs xv(1); xv[0]=x;
128  return assign(home, xv, fa, NULL, vvp);
129  }
130 
131 }
132 
133 // STATISTICS: float-post
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
Combine variable selection criteria for tie-breaking.
Which values to select for branching first.
Definition: float.hh:1646
Handle for brancher.
Definition: core.hpp:1157
Passing float variables.
Definition: float.hh:966
Abstract class for view selection.
void expand(Home home, const FloatVarArgs &x)
Expand decay factor into AFC or activity.
Definition: var.hpp:74
bool(* FloatBranchFilter)(const Space &home, FloatVar x, int i)
Branch filter function type for float variables.
Definition: float.hh:1353
Which variable to select for branching.
Definition: float.hh:1516
static BrancherHandle post(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, BranchFilter bf, VarValPrint vvp)
Brancher post function.
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:92
Base class for value selection and commit.
Select the first unassigned view.
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:1521
BrancherHandle assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:113
First unassigned.
Definition: float.hh:1520
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
VarBranch a
Branching criteria to try in order.
Which values to select for assignment.
Definition: float.hh:1700
Float variables.
Definition: float.hh:857
Gecode toplevel namespace
BrancherHandle 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
void(* FloatVarValPrint)(const Space &home, const BrancherHandle &bh, unsigned int a, FloatVar x, int i, const FloatNumBranch &n, std::ostream &o)
Function type for explaining branching alternatives for set variables.
Definition: float.hh:1502
Home class for posting propagators
Definition: core.hpp:717
ValSelCommitBase< FloatView, FloatNumBranch > * valselcommit(Space &home, const FloatValBranch &fvb)
Return value and commit for float views.