Generated on Sat May 25 2013 18:00:33 for Gecode by doxygen 1.8.3.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-03-07 02:18:29 +0100 (Thu, 07 Mar 2013) $ by $Author: mears $
11  * $Revision: 13455 $
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, SetBranchFilter bf) {
44  using namespace Set;
45  if (home.failed()) return BrancherHandle();
46  vars.expand(home,x);
47  ViewArray<SetView> xv(home,x);
48  ViewSel<SetView>* vs[1] = {
49  Branch::viewsel(home,vars)
50  };
52  (home,xv,vs,Branch::valselcommit(home,vals),bf);
53  }
54 
55  BrancherHandle
56  branch(Home home, const SetVarArgs& x,
58  using namespace Set;
59  if (home.failed()) return BrancherHandle();
60  vars.a.expand(home,x);
61  if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
62  (vars.a.select() == SetVarBranch::SEL_RND))
63  vars.b = SET_VAR_NONE();
64  vars.b.expand(home,x);
65  if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
66  (vars.b.select() == SetVarBranch::SEL_RND))
67  vars.c = SET_VAR_NONE();
68  vars.c.expand(home,x);
69  if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
70  (vars.c.select() == SetVarBranch::SEL_RND))
71  vars.d = SET_VAR_NONE();
72  vars.d.expand(home,x);
73  if (vars.b.select() == SetVarBranch::SEL_NONE) {
74  return branch(home,x,vars.a,vals,bf);
75  } else {
76  ViewArray<SetView> xv(home,x);
78  if (vars.c.select() == SetVarBranch::SEL_NONE) {
79  ViewSel<SetView>* vs[2] = {
80  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
81  };
82  return ViewValBrancher<SetView,2,int,2>::post(home,xv,vs,vsc,bf);
83  } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
84  ViewSel<SetView>* vs[3] = {
85  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
86  Branch::viewsel(home,vars.c)
87  };
88  return ViewValBrancher<SetView,3,int,2>::post(home,xv,vs,vsc,bf);
89  } else {
90  ViewSel<SetView>* vs[4] = {
91  Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
92  Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
93  };
94  return ViewValBrancher<SetView,4,int,2>::post(home,xv,vs,vsc,bf);
95  }
96  }
97  }
98 
99  BrancherHandle
100  branch(Home home, SetVar x, SetValBranch vals) {
101  SetVarArgs xv(1); xv[0]=x;
102  return branch(home, xv, SET_VAR_NONE(), vals);
103  }
104 
105  BrancherHandle
106  assign(Home home, const SetVarArgs& x, SetAssign sa,
107  SetBranchFilter bf) {
108  using namespace Set;
109  if (home.failed()) return BrancherHandle();
110  ViewArray<SetView> xv(home,x);
111  ViewSel<SetView>* vs[1] = {
112  new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
113  };
115  (home,xv,vs,Branch::valselcommit(home,sa),bf);
116  }
117 
119  assign(Home home, SetVar x, SetAssign sa) {
120  SetVarArgs xv(1); xv[0]=x;
121  return assign(home, xv, sa);
122  }
123 
124 }
125 
126 // STATISTICS: set-post