Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
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/set/branch.hh>
39 
40 namespace Gecode {
41 
42  void
43  branch(Home home, const SetVarArgs& x,
44  SetVarBranch vars, SetValBranch vals,
45  SetBranchFilter bf,
46  SetVarValPrint vvp) {
47  using namespace Set;
48  if (home.failed()) return;
49  vars.expand(home,x);
50  ViewArray<SetView> xv(home,x);
51  ViewSel<SetView>* vs[1] = {
52  Branch::viewsel(home,vars)
53  };
54  postviewvalbrancher<SetView,1,int,2>
55  (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
56  }
57 
58  void
59  branch(Home home, const SetVarArgs& x,
61  SetBranchFilter bf,
62  SetVarValPrint vvp) {
63  using namespace Set;
64  if (home.failed()) return;
65  vars.a.expand(home,x);
66  if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
67  (vars.a.select() == SetVarBranch::SEL_RND))
68  vars.b = SET_VAR_NONE();
69  vars.b.expand(home,x);
70  if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
71  (vars.b.select() == SetVarBranch::SEL_RND))
72  vars.c = SET_VAR_NONE();
73  vars.c.expand(home,x);
74  if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
75  (vars.c.select() == SetVarBranch::SEL_RND))
76  vars.d = SET_VAR_NONE();
77  vars.d.expand(home,x);
78  if (vars.b.select() == SetVarBranch::SEL_NONE) {
79  branch(home,x,vars.a,vals,bf,vvp);
80  } else {
81  ViewArray<SetView> xv(home,x);
83  if (vars.c.select() == SetVarBranch::SEL_NONE) {
84  ViewSel<SetView>* vs[2] = {
85  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
86  };
87  postviewvalbrancher<SetView,2,int,2>(home,xv,vs,vsc,bf,vvp);
88  } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
89  ViewSel<SetView>* vs[3] = {
90  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
91  Branch::viewsel(home,vars.c)
92  };
93  postviewvalbrancher<SetView,3,int,2>(home,xv,vs,vsc,bf,vvp);
94  } else {
95  ViewSel<SetView>* vs[4] = {
96  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
97  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
98  };
99  postviewvalbrancher<SetView,4,int,2>(home,xv,vs,vsc,bf,vvp);
100  }
101  }
102  }
103 
104  void
106  SetVarArgs xv(1); xv[0]=x;
107  branch(home, xv, SET_VAR_NONE(), vals, nullptr, vvp);
108  }
109 
110  void
111  assign(Home home, const SetVarArgs& x, SetAssign sa,
112  SetBranchFilter bf,
113  SetVarValPrint vvp) {
114  using namespace Set;
115  if (home.failed()) return;
116  ViewArray<SetView> xv(home,x);
117  ViewSel<SetView>* vs[1] = {
118  new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
119  };
120  postviewvalbrancher<SetView,1,int,1>
121  (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
122  }
123 
124  void
126  SetVarArgs xv(1); xv[0]=x;
127  assign(home, xv, sa, nullptr, vvp);
128  }
129 
130 }
131 
132 // STATISTICS: set-post
Post propagator for SetVar x
Definition: set.hh:784
ValSelCommitBase< SetView, int > * valselcommit(Space &home, const SetValBranch &svb)
Return value and commit for set views.
VarBranch b
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:115
Select the first unassigned view.
Combine variable selection criteria for tie-breaking.
Which values to select for branching first.
Definition: set.hh:1484
Passing set variables.
Definition: set.hh:492
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
@ SEL_NONE
First unassigned.
Definition: set.hh:1337
SetVarBranch SET_VAR_NONE(void)
Definition: var.hpp:100
Which value to select for assignment.
Definition: set.hh:1554
Gecode toplevel namespace
std::function< bool(const Space &home, SetVar x, int i)> SetBranchFilter
Branch filter function type for set variables.
Definition: set.hh:1129
Home class for posting propagators
Definition: core.hpp:922
VarBranch d
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:1322
VarBranch c
Set variables
Definition: set.hh:131
ViewSel< SetView > * viewsel(Space &home, const SetVarBranch &svb)
Return view selectors for set views.
Definition: view-sel.cpp:43
Base class for value selection and commit.
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:4099
Abstract class for view selection.
Expand and CHB void expand(Home home, const SetVarArgs &x)
Definition: var.hpp:78
@ SEL_RND
Random (uniform, for tie breaking)
Definition: set.hh:1338
Which variable to select for branching.
Definition: set.hh:1333
VarBranch a
Branching criteria to try in order.