Generated on Thu Apr 5 2018 19:44:19 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, 2017
8  *
9  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
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 
40 
41 namespace Gecode { namespace FlatZinc {
42 
43  void
45  Choice::archive(e);
46  e << _pos;
47  e << _val;
48  }
49 
50 
51  bool
53  if (start < x.size()) {
54  for (int i=start; i < x.size(); i++)
55  if (!x[i].assigned()) {
56  start = i;
57  return true;
58  }
59  start = x.size();
60  }
61  for (int i=start-x.size(); i < y.size(); i++)
62  if (!y[i].assigned()) {
63  start = x.size() + i;
64  return true;
65  }
66  return false;
67  }
68 
71  unsigned int b) {
72  const PosIntChoice& c
73  = static_cast<const PosIntChoice&>(_c);
74  int p=c.pos(); int n=c.val();
75  if (p < x.size()) {
76  return me_failed(xvsc->commit(home,b,x[p],p,n)) ?
77  ES_FAILED : ES_OK;
78  } else {
79  p -= x.size();
80  return me_failed(yvsc->commit(home,b,y[p],p,n)) ?
81  ES_FAILED : ES_OK;
82  }
83  }
84 
85  NGL*
87  unsigned int b) const {
88  const PosIntChoice& c
89  = static_cast<const PosIntChoice&>(_c);
90  int p=c.pos(); int n=c.val();
91  if (p < x.size()) {
92  return xvsc->ngl(home,b,x[p],n);
93  } else {
94  p -= x.size();
95  return yvsc->ngl(home,b,y[p],n);
96  }
97  }
98 
99  void
101  unsigned int b,
102  std::ostream& o) const {
103  const PosIntChoice& c
104  = static_cast<const PosIntChoice&>(_c);
105  int p=c.pos(); int n=c.val();
106  if (p < x.size()) {
107  xvsc->print(home,b,x[p],p,n,o);
108  } else {
109  p -= x.size();
110  yvsc->print(home,b,y[p],p,n,o);
111  }
112  }
113 
114  const Choice*
116  (void) home;
117  int p; e >> p;
118  int v; e >> v;
119  return new PosIntChoice(*this,2,p,v);
120  }
121 
122 
123  void
124  branch(Home home, const IntVarArgs& x, const BoolVarArgs& y,
125  IntBoolVarBranch vars, IntValBranch vals) {
126  if (home.failed()) return;
127  vars.expand(home,x,y);
128  ViewArray<Int::IntView> xv(home,x);
129  ViewArray<Int::BoolView> yv(home,y);
131  Int::Branch::valselcommit(home,vals);
133  Int::Branch::valselcommit(home,i2b(vals));
134  switch (vars.select()) {
136  {
137  MeritMaxAFC m(home,vars);
138  IntBoolBrancher<MeritMaxAFC>::post(home,xv,yv,m,xvsc,yvsc);
139  }
140  break;
142  {
143  MeritMaxAction m(home,vars);
144  IntBoolBrancher<MeritMaxAction>::post(home,xv,yv,m,xvsc,yvsc);
145  }
146  break;
148  {
149  MeritMaxCHB m(home,vars);
150  IntBoolBrancher<MeritMaxCHB>::post(home,xv,yv,m,xvsc,yvsc);
151  }
152  break;
154  {
155  MeritMaxAFCSize m(home,vars);
156  IntBoolBrancher<MeritMaxAFCSize>::post(home,xv,yv,m,xvsc,yvsc);
157  }
158  break;
160  {
161  MeritMaxActionSize m(home,vars);
162  IntBoolBrancher<MeritMaxActionSize>::post(home,xv,yv,m,xvsc,yvsc);
163  }
164  break;
166  {
167  MeritMaxCHBSize m(home,vars);
168  IntBoolBrancher<MeritMaxCHBSize>::post(home,xv,yv,m,xvsc,yvsc);
169  }
170  break;
171  default:
172  GECODE_NEVER;
173  }
174  }
175 
176 }}
177 
178 // STATISTICS: flatzinc-branch
179 
virtual bool status(const Space &home) const
Check status of brancher, return true if alternatives left.
Definition: branch.cpp:52
static void post(Home home, ViewArray< Int::IntView > x, ViewArray< Int::BoolView > y, Merit &m, ValSelCommitBase< Int::IntView, int > *xvsc, ValSelCommitBase< Int::BoolView, int > *yvsc)
Post brancher.
Definition: branch.hpp:351
With largest accumulated failure count.
Definition: branch.hh:52
Which values to select for branching first.
Definition: int.hh:4651
PosIntChoice(const Brancher &b, unsigned int a, int p, int n)
Initialize choice for brancher b, number of alternatives a, position p, and value n...
Definition: branch.hpp:295
Multi _c(Gecode::IntArgs(3, 1, 2, 3))
Select by maximal Action over size.
Definition: branch.hh:190
Choice storing position and value
Definition: branch.hh:250
Computation spaces.
Definition: core.hpp:1668
Base class for value selection and commit.
void expand(Home home, const IntVarArgs &x, const BoolVarArgs &y)
Expand AFC, action, and CHB.
Definition: branch.hpp:88
Select by maximal AFC.
Definition: branch.hh:130
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
With largest CHB Q-score divided by domain size.
Definition: branch.hh:57
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Select by maximal CHB.
Definition: branch.hh:210
virtual ExecStatus commit(Space &home, const Choice &c, unsigned int b)
Perform commit for choice c and alternative b.
Definition: branch.cpp:70
Execution has resulted in failure.
Definition: core.hpp:466
With largest accumulated failure count divided by domain size.
Definition: branch.hh:55
Which integer or Boolean variable to select for branching.
Definition: branch.hh:48
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3918
Select select(void) const
Return selection strategy.
Definition: branch.hpp:57
void branch(Home home, const IntVarArgs &x, const BoolVarArgs &y, IntBoolVarBranch vars, IntValBranch vals)
Branch function for integer and Boolean variables.
Definition: branch.cpp:124
BoolValBranch i2b(const IntValBranch &ivb)
Map respective integer value selection to Boolean value selection.
Definition: branch.hpp:425
virtual const Choice * choice(Space &home)=0
Return choice.
ValSelCommitBase< IntView, int > * valselcommit(Space &home, const IntValBranch &ivb)
Return value and commit for integer views.
Passing integer variables.
Definition: int.hh:637
Select by maximal AFC over size.
Definition: branch.hh:150
Passing Boolean variables.
Definition: int.hh:691
virtual void archive(Archive &e) const
Archive into e.
Definition: branch.cpp:44
virtual NGL * ngl(Space &home, const Choice &c, unsigned int b) const
Create no-good literal for choice c and alternative b.
Definition: branch.cpp:86
Select by maximal CHB over size.
Definition: branch.hh:230
const int v[7]
Definition: distinct.cpp:263
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
With largest action divided by domain size.
Definition: branch.hh:56
virtual void archive(Archive &e) const
Archive into e.
Definition: core.cpp:857
Choice for performing commit
Definition: core.hpp:1338
int val(void) const
Return value to assign to.
Definition: branch.hpp:302
Archive representation
Definition: archive.hpp:46
Select by maximal Action.
Definition: branch.hh:170
ExecStatus
Definition: core.hpp:464
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
virtual void print(const Space &home, const Choice &c, unsigned int b, std::ostream &o) const
Print branch for choice c and alternative b.
Definition: branch.cpp:100
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
Gecode toplevel namespace
Home class for posting propagators
Definition: core.hpp:846
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
int pos(void) const
Return position of view to assign.
Definition: branch.hpp:298
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition: modevent.hpp:58
No-good literal recorded during search.
Definition: core.hpp:1266