Generated on Thu Mar 16 2017 03:24:15 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  * Last modified:
10  * $Date: 2016-05-26 13:44:53 +0200 (Thu, 26 May 2016) $ by $Author: schulte $
11  * $Revision: 15087 $
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 
42  void
43  branch(Home home, const SetVarArgs& x,
44  SetVarBranch vars, SetValBranch vals,
46  using namespace Set;
47  if (home.failed()) return;
48  vars.expand(home,x);
49  ViewArray<SetView> xv(home,x);
50  ViewSel<SetView>* vs[1] = {
51  Branch::viewsel(home,vars)
52  };
54  (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
55  }
56 
57  void
58  branch(Home home, const SetVarArgs& x,
61  using namespace Set;
62  if (home.failed()) return;
63  vars.a.expand(home,x);
64  if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
65  (vars.a.select() == SetVarBranch::SEL_RND))
66  vars.b = SET_VAR_NONE();
67  vars.b.expand(home,x);
68  if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
69  (vars.b.select() == SetVarBranch::SEL_RND))
70  vars.c = SET_VAR_NONE();
71  vars.c.expand(home,x);
72  if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
73  (vars.c.select() == SetVarBranch::SEL_RND))
74  vars.d = SET_VAR_NONE();
75  vars.d.expand(home,x);
76  if (vars.b.select() == SetVarBranch::SEL_NONE) {
77  branch(home,x,vars.a,vals,bf,vvp);
78  } else {
79  ViewArray<SetView> xv(home,x);
81  if (vars.c.select() == SetVarBranch::SEL_NONE) {
82  ViewSel<SetView>* vs[2] = {
83  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
84  };
85  ViewValBrancher<SetView,2,int,2>::post(home,xv,vs,vsc,bf,vvp);
86  } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
87  ViewSel<SetView>* vs[3] = {
88  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
89  Branch::viewsel(home,vars.c)
90  };
91  ViewValBrancher<SetView,3,int,2>::post(home,xv,vs,vsc,bf,vvp);
92  } else {
93  ViewSel<SetView>* vs[4] = {
94  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
95  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
96  };
97  ViewValBrancher<SetView,4,int,2>::post(home,xv,vs,vsc,bf,vvp);
98  }
99  }
100  }
101 
102  void
104  SetVarArgs xv(1); xv[0]=x;
105  branch(home, xv, SET_VAR_NONE(), vals, NULL, vvp);
106  }
107 
108  void
109  assign(Home home, const SetVarArgs& x, SetAssign sa,
111  using namespace Set;
112  if (home.failed()) return;
113  ViewArray<SetView> xv(home,x);
114  ViewSel<SetView>* vs[1] = {
115  new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
116  };
118  (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
119  }
120 
121  void
123  SetVarArgs xv(1); xv[0]=x;
124  assign(home, xv, sa, NULL, vvp);
125  }
126 
127 }
128 
129 // STATISTICS: set-post
Which values to select for branching first.
Definition: set.hh:1381
Combine variable selection criteria for tie-breaking.
SetVarBranch SET_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:91
Random (uniform, for tie breaking)
Definition: set.hh:1257
Abstract class for view selection.
Base class for value selection and commit.
Select the first unassigned view.
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
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:113
ViewSel< SetView > * viewsel(Space &home, const SetVarBranch &svb)
Return view selectors for set views.
Definition: view-sel.cpp:43
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3967
void(* SetVarValPrint)(const Space &home, const Brancher &b, 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:1238
static void post(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, BranchFilter bf, VarValPrint vvp)
Brancher post function.
ValSelCommitBase< SetView, int > * valselcommit(Space &home, const SetValBranch &svb)
Return value and commit for set views.
Passing set variables.
Definition: set.hh:490
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
bool(* SetBranchFilter)(const Space &home, SetVar x, int i)
Branch filter function type for set variables.
Definition: set.hh:1101
VarBranch a
Branching criteria to try in order.
Which value to select for assignment.
Definition: set.hh:1451
Gecode toplevel namespace
Which variable to select for branching.
Definition: set.hh:1252
Home class for posting propagators
Definition: core.hpp:905
First unassigned.
Definition: set.hh:1256