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-02 17:10:16 +0200 (Thu, 02 May 2013) $ by $Author: schulte $
11  * $Revision: 13603 $
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/set/branch.hh>
39 
40 namespace Gecode {
41  BrancherHandle
42  branch(Home home, const SetVarArgs& x,
43  SetVarBranch vars, SetValBranch vals,
45  using namespace Set;
46  if (home.failed()) return BrancherHandle();
47  vars.expand(home,x);
48  ViewArray<SetView> xv(home,x);
49  ViewSel<SetView>* vs[1] = {
50  Branch::viewsel(home,vars)
51  };
53  (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
54  }
55 
56  BrancherHandle
57  branch(Home home, const SetVarArgs& x,
60  using namespace Set;
61  if (home.failed()) return BrancherHandle();
62  vars.a.expand(home,x);
63  if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
64  (vars.a.select() == SetVarBranch::SEL_RND))
65  vars.b = SET_VAR_NONE();
66  vars.b.expand(home,x);
67  if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
68  (vars.b.select() == SetVarBranch::SEL_RND))
69  vars.c = SET_VAR_NONE();
70  vars.c.expand(home,x);
71  if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
72  (vars.c.select() == SetVarBranch::SEL_RND))
73  vars.d = SET_VAR_NONE();
74  vars.d.expand(home,x);
75  if (vars.b.select() == SetVarBranch::SEL_NONE) {
76  return branch(home,x,vars.a,vals,bf,vvp);
77  } else {
78  ViewArray<SetView> xv(home,x);
80  if (vars.c.select() == SetVarBranch::SEL_NONE) {
81  ViewSel<SetView>* vs[2] = {
82  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
83  };
84  return ViewValBrancher<SetView,2,int,2>::post(home,xv,vs,vsc,bf,vvp);
85  } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
86  ViewSel<SetView>* vs[3] = {
87  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
88  Branch::viewsel(home,vars.c)
89  };
90  return ViewValBrancher<SetView,3,int,2>::post(home,xv,vs,vsc,bf,vvp);
91  } else {
92  ViewSel<SetView>* vs[4] = {
93  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
94  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
95  };
96  return ViewValBrancher<SetView,4,int,2>::post(home,xv,vs,vsc,bf,vvp);
97  }
98  }
99  }
100 
101  BrancherHandle
103  SetVarArgs xv(1); xv[0]=x;
104  return branch(home, xv, SET_VAR_NONE(), vals, NULL, vvp);
105  }
106 
107  BrancherHandle
108  assign(Home home, const SetVarArgs& x, SetAssign sa,
110  using namespace Set;
111  if (home.failed()) return BrancherHandle();
112  ViewArray<SetView> xv(home,x);
113  ViewSel<SetView>* vs[1] = {
114  new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
115  };
117  (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
118  }
119 
122  SetVarArgs xv(1); xv[0]=x;
123  return assign(home, xv, sa, NULL, vvp);
124  }
125 
126 }
127 
128 // STATISTICS: set-post
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
Which values to select for branching first.
Definition: set.hh:1382
Combine variable selection criteria for tie-breaking.
SetVarBranch SET_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:91
Handle for brancher.
Definition: core.hpp:1157
Abstract class for view selection.
static BrancherHandle post(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, BranchFilter bf, VarValPrint vvp)
Brancher post function.
Base class for value selection and commit.
Select the first unassigned view.
First unassigned.
Definition: set.hh:1257
ViewSel< SetView > * viewsel(Space &home, const SetVarBranch &svb)
Return view selectors for set views.
Definition: view-sel.cpp:43
ValSelCommitBase< SetView, int > * valselcommit(Space &home, const SetValBranch &svb)
Return value and commit for set views.
Passing set variables.
Definition: set.hh:490
Random (uniform, for tie breaking)
Definition: set.hh:1258
BrancherHandle assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:113
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
void expand(Home home, const SetVarArgs &x)
Expand decay factor into AFC or activity.
Definition: var.hpp:74
void(* SetVarValPrint)(const Space &home, const BrancherHandle &bh, unsigned int a, SetVar x, int i, const int &n, std::ostream &o)
Function type for printing branching alternatives for set variables.
Definition: set.hh:1239
bool(* SetBranchFilter)(const Space &home, SetVar x, int i)
Branch filter function type for set variables.
Definition: set.hh:1102
VarBranch a
Branching criteria to try in order.
Which value to select for assignment.
Definition: set.hh:1452
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
Which variable to select for branching.
Definition: set.hh:1253
Home class for posting propagators
Definition: core.hpp:717