Generated on Sat Jun 2 2018 07:17:44 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/set/branch.hh>
35 
36 namespace Gecode {
37 
38  void
39  branch(Home home, const SetVarArgs& x,
40  SetVarBranch vars, SetValBranch vals,
41  SetBranchFilter bf,
42  SetVarValPrint vvp) {
43  using namespace Set;
44  if (home.failed()) return;
45  vars.expand(home,x);
46  ViewArray<SetView> xv(home,x);
47  ViewSel<SetView>* vs[1] = {
48  Branch::viewsel(home,vars)
49  };
50  postviewvalbrancher<SetView,1,int,2>
51  (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
52  }
53 
54  void
55  branch(Home home, const SetVarArgs& x,
57  SetBranchFilter bf,
58  SetVarValPrint vvp) {
59  using namespace Set;
60  if (home.failed()) return;
61  vars.a.expand(home,x);
62  if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
63  (vars.a.select() == SetVarBranch::SEL_RND))
64  vars.b = SET_VAR_NONE();
65  vars.b.expand(home,x);
66  if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
67  (vars.b.select() == SetVarBranch::SEL_RND))
68  vars.c = SET_VAR_NONE();
69  vars.c.expand(home,x);
70  if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
71  (vars.c.select() == SetVarBranch::SEL_RND))
72  vars.d = SET_VAR_NONE();
73  vars.d.expand(home,x);
74  if (vars.b.select() == SetVarBranch::SEL_NONE) {
75  branch(home,x,vars.a,vals,bf,vvp);
76  } else {
77  ViewArray<SetView> xv(home,x);
79  if (vars.c.select() == SetVarBranch::SEL_NONE) {
80  ViewSel<SetView>* vs[2] = {
81  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
82  };
83  postviewvalbrancher<SetView,2,int,2>(home,xv,vs,vsc,bf,vvp);
84  } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
85  ViewSel<SetView>* vs[3] = {
86  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
87  Branch::viewsel(home,vars.c)
88  };
89  postviewvalbrancher<SetView,3,int,2>(home,xv,vs,vsc,bf,vvp);
90  } else {
91  ViewSel<SetView>* vs[4] = {
92  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
93  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
94  };
95  postviewvalbrancher<SetView,4,int,2>(home,xv,vs,vsc,bf,vvp);
96  }
97  }
98  }
99 
100  void
102  SetVarArgs xv(1); xv[0]=x;
103  branch(home, xv, SET_VAR_NONE(), vals, nullptr, vvp);
104  }
105 
106  void
107  assign(Home home, const SetVarArgs& x, SetAssign sa,
108  SetBranchFilter bf,
109  SetVarValPrint vvp) {
110  using namespace Set;
111  if (home.failed()) return;
112  ViewArray<SetView> xv(home,x);
113  ViewSel<SetView>* vs[1] = {
114  new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
115  };
116  postviewvalbrancher<SetView,1,int,1>
117  (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
118  }
119 
120  void
122  SetVarArgs xv(1); xv[0]=x;
123  assign(home, xv, sa, nullptr, vvp);
124  }
125 
126 }
127 
128 // STATISTICS: set-post
Which values to select for branching first.
Definition: set.hh:1445
Combine variable selection criteria for tie-breaking.
Definition: tiebreak.hpp:38
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
First unassigned.
Definition: set.hh:1298
Abstract class for view selection.
Definition: view-sel.hpp:44
Expand and CHB void expand(Home home, const SetVarArgs &x)
Definition: var.hpp:74
SetVarBranch SET_VAR_NONE(void)
Definition: var.hpp:96
Base class for value selection and commit.
Select the first unassigned view.
Definition: view-sel.hpp:109
ViewSel< SetView > * viewsel(Space &home, const SetVarBranch &svb)
Return view selectors for set views.
Definition: view-sel.cpp:39
VarBranch b
Definition: tiebreak.hpp:41
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3967
ValSelCommitBase< SetView, int > * valselcommit(Space &home, const SetValBranch &svb)
Return value and commit for set views.
Function type for printing branching alternatives for set variables typedef std::function< void(const Space &home, const Brancher &b, unsigned int a, SetVar x, int i, const int &n, std::ostream &o)> SetVarValPrint
Definition: set.hh:1283
Passing set variables.
Definition: set.hh:488
Set variables
Definition: set.hh:127
VarBranch a
Branching criteria to try in order.
Definition: tiebreak.hpp:41
std::function< bool(const Space &home, SetVar x, int i)> SetBranchFilter
Branch filter function type for set variables.
Definition: set.hh:1081
Post propagator for SetVar x
Definition: set.hh:765
Random (uniform, for tie breaking)
Definition: set.hh:1299
Which value to select for assignment.
Definition: set.hh:1515
Gecode toplevel namespace
Which variable to select for branching.
Definition: set.hh:1294
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
VarBranch d
Definition: tiebreak.hpp:41