Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
view-val.hpp
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$ 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 namespace Gecode {
39 
48  template<class Val>
51  private:
53  const Val _val;
54  public:
56  PosValChoice(const Brancher& b, unsigned int a, const Pos& p, const Val& n);
57  const Val& val(void) const;
59  virtual void archive(Archive& e) const;
60  };
61 
62 
64  template<class View, class Val, PropCond pc>
65  class ViewValNGL : public NGL {
66  protected:
68  View x;
70  Val n;
71  public:
73  ViewValNGL(Space& home, View x, Val n);
75  ViewValNGL(Space& home, ViewValNGL& ngl);
77  virtual void subscribe(Space& home, Propagator& p);
79  virtual void cancel(Space& home, Propagator& p);
81  virtual void reschedule(Space& home, Propagator& p);
83  virtual size_t dispose(Space& home);
84  };
85 
93  template<class View, int n, class Val, unsigned int a,
94  class Filter, class Print>
95  class ViewValBrancher : public ViewBrancher<View,Filter,n> {
96  protected:
101  typedef typename View::VarType Var;
105  Print p;
109  ViewValBrancher(Home home,
111  ViewSel<View>* vs[n],
115  public:
117  virtual const Choice* choice(Space& home);
119  virtual const Choice* choice(const Space& home, Archive& e);
121  virtual ExecStatus commit(Space& home, const Choice& c, unsigned int b);
123  virtual NGL* ngl(Space& home, const Choice& c, unsigned int b) const;
131  virtual void print(const Space& home, const Choice& c, unsigned int b,
132  std::ostream& o) const;
134  virtual Actor* copy(Space& home);
136  virtual size_t dispose(Space& home);
138  static void post(Home home,
140  ViewSel<View>* vs[n],
144  };
145 
147  template<class View, int n, class Val, unsigned int a>
148  void
151  ViewSel<View>* vs[n],
156 
157  /*
158  * %Choice with position and value
159  *
160  */
161  template<class Val>
164  const Pos& p, const Val& n)
165  : PosChoice(b,a,p), _val(n) {}
166 
167  template<class Val>
168  forceinline const Val&
170  return _val;
171  }
172 
173  template<class Val>
174  forceinline void
177  e << _val;
178  }
179 
180 
181  /*
182  * View-value no-good literal
183  *
184  */
185  template<class View, class Val, PropCond pc>
188  : NGL(home), x(x0), n(n0) {}
189 
190  template<class View, class Val, PropCond pc>
193  : NGL(home,ngl), n(ngl.n) {
194  x.update(home,ngl.x);
195  }
196 
197  template<class View, class Val, PropCond pc>
198  void
200  x.subscribe(home,p,pc);
201  }
202 
203  template<class View, class Val, PropCond pc>
204  void
206  x.cancel(home,p,pc);
207  }
208 
209  template<class View, class Val, PropCond pc>
210  void
212  x.reschedule(home,p,pc);
213  }
214 
215  template<class View, class Val, PropCond pc>
216  size_t
218  (void) NGL::dispose(home);
219  return sizeof(*this);
220  }
221 
222 
223 
224  /*
225  * Generic brancher based on variable/value selection
226  *
227  */
228  template<class View, int n, class Val, unsigned int a,
229  class Filter, class Print>
234  ViewSel<View>* vs[n],
238  : ViewBrancher<View,Filter,n>(home,x,vs,bf), vsc(vsc0), p(vvp) {
239  if (vsc->notice() || f.notice() || p.notice())
240  home.notice(*this,AP_DISPOSE,true);
241  }
242 
243  template<class View, int n, class Val, unsigned int a,
244  class Filter, class Print>
245  forceinline void
250  VarValPrint<Var,Val> vvp) {
252  (home,x,vs,vsc,bf,vvp);
253  }
254 
255  template<class View, int n, class Val, unsigned int a,
256  class Filter, class Print>
261  : ViewBrancher<View,Filter,n>(home,b),
262  vsc(b.vsc->copy(home)), p(b.p) {}
263 
264  template<class View, int n, class Val, unsigned int a,
265  class Filter, class Print>
266  Actor*
269  (home,*this);
270  }
271 
272  template<class View, int n, class Val, unsigned int a,
273  class Filter, class Print>
274  const Choice*
278  return new PosValChoice<Val>(*this,a,p,vsc->val(home,v,p.pos));
279  }
280 
281  template<class View, int n, class Val, unsigned int a,
282  class Filter, class Print>
283  const Choice*
285  Archive& e) {
286  (void) home;
287  int p; e >> p;
288  Val v; e >> v;
289  return new PosValChoice<Val>(*this,a,p,v);
290  }
291 
292  template<class View, int n, class Val, unsigned int a,
293  class Filter, class Print>
294  ExecStatus
296  ::commit(Space& home, const Choice& c, unsigned int b) {
297  const PosValChoice<Val>& pvc
298  = static_cast<const PosValChoice<Val>&>(c);
299  return me_failed(vsc->commit(home,b,
301  pvc.pos().pos,
302  pvc.val()))
303  ? ES_FAILED : ES_OK;
304  }
305 
306  template<class View, int n, class Val, unsigned int a,
307  class Filter, class Print>
308  NGL*
310  ::ngl(Space& home, const Choice& c, unsigned int b) const {
311  const PosValChoice<Val>& pvc
312  = static_cast<const PosValChoice<Val>&>(c);
313  return vsc->ngl(home,b,
315  }
316 
317  template<class View, int n, class Val, unsigned int a,
318  class Filter, class Print>
319  void
321  ::print(const Space& home, const Choice& c, unsigned int b,
322  std::ostream& o) const {
323  const PosValChoice<Val>& pvc
324  = static_cast<const PosValChoice<Val>&>(c);
325  View xi = ViewBrancher<View,Filter,n>::view(pvc.pos());
326  if (p)
327  p(home,*this,b,xi,pvc.pos().pos,pvc.val(),o);
328  else
329  vsc->print(home,b,xi,pvc.pos().pos,pvc.val(),o);
330  }
331 
332  template<class View, int n, class Val, unsigned int a,
333  class Filter, class Print>
334  forceinline size_t
336  if (vsc->notice() || f.notice() || p.notice())
337  home.ignore(*this,AP_DISPOSE,true);
338  vsc->dispose(home);
341  }
342 
343  template<class View, int n, class Val, unsigned int a>
344  forceinline void
347  ViewSel<View>* vs[n],
351  if (bf) {
352  if (vvp) {
353  ViewValBrancher<View,n,Val,a,
355  ::post(home,x,vs,vsc,bf,vvp);
356  } else {
357  ViewValBrancher<View,n,Val,a,
359  ::post(home,x,vs,vsc,bf,vvp);
360  }
361  } else {
362  if (vvp)
363  ViewValBrancher<View,n,Val,a,
365  ::post(home,x,vs,vsc,bf,vvp);
366  else
367  ViewValBrancher<View,n,Val,a,
368  BrancherNoFilter<View>,BrancherNoPrint<View,Val> >
369  ::post(home,x,vs,vsc,bf,vvp);
370  }
371  }
372 
373 }
374 
375 // STATISTICS: kernel-branch
ViewValBrancher(Space &home, ViewValBrancher &b)
Constructor for cloning b.
Definition: view-val.hpp:259
void postviewvalbrancher(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, BranchFilter< typename View::VarType > bf, VarValPrint< typename View::VarType, Val > vvp)
Post view value brancher.
Definition: view-val.hpp:345
Actor must always be disposed.
Definition: core.hpp:554
View::VarType Var
The corresponding variable.
Definition: view-val.hpp:101
Class withot a branch filter function.
Definition: filter.hpp:72
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
Val n
The stored value.
Definition: view-val.hpp:70
virtual size_t dispose(Space &home)
Delete brancher and return its size.
Definition: view-val.hpp:335
std::function< void(const Space &home, const Brancher &b, unsigned int a, Var x, int i, const Val &m, std::ostream &o)> VarValPrint
Function type for printing variable and value selection.
Definition: print.hpp:47
Generic brancher by view selection.
Definition: view.hpp:82
View x
The stored view.
Definition: view-val.hpp:68
Base-class for propagators.
Definition: core.hpp:1016
virtual Actor * copy(Space &home)
Perform cloning.
Definition: view-val.hpp:267
virtual void dispose(Space &home)=0
Delete value selection.
ViewArray< View > x
Views to branch on.
Definition: view.hpp:87
View view(const Pos &p) const
Return view according to position information p.
Definition: view.hpp:217
#define forceinline
Definition: config.hpp:182
Computation spaces.
Definition: core.hpp:1668
Class storing a print function.
Definition: print.hpp:51
const Pos & pos(void) const
Return position in array.
Definition: view.hpp:130
Class without print function.
Definition: print.hpp:77
Base-class for both propagators and branchers.
Definition: core.hpp:620
virtual ExecStatus commit(Space &home, const Choice &c, unsigned int b)
Perform commit for choice c and alternative b.
Definition: view-val.hpp:296
ViewSel< View > * vs[n]
View selection objects.
Definition: view.hpp:91
Pos pos(Space &home)
Return position information.
Definition: view.hpp:177
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
virtual NGL * ngl(Space &home, const Choice &c, unsigned int b) const
Create no-good literal for choice c and alternative b.
Definition: view-val.hpp:310
Base-class for branchers.
Definition: core.hpp:1368
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Class storing a branch filter function.
Definition: filter.hpp:49
virtual void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const =0
Print on o branch for alternative a, view x at position i, and value n.
Execution has resulted in failure.
Definition: core.hpp:466
Generic brancher by view and value selection.
Definition: view-val.hpp:95
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
std::function< bool(const Space &home, Var x, int i)> BranchFilter
Function type for branch filter functions.
Definition: filter.hpp:45
ValSelCommitBase< View, Val > * vsc
Value selection and commit object.
Definition: view-val.hpp:103
static void post(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, BranchFilter< Var > bf, VarValPrint< Var, Val > vvp)
Brancher post function.
Definition: view-val.hpp:247
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: view-val.hpp:321
const Val & val(void) const
Definition: view-val.hpp:169
Choices storing position
Definition: view.hpp:59
virtual const Choice * choice(Space &home)
Return choice.
Definition: view-val.hpp:275
Position information.
Definition: view.hpp:48
View arrays.
Definition: array.hpp:228
Print p
Print function.
Definition: view-val.hpp:105
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3139
const int v[7]
Definition: distinct.cpp:263
virtual ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)=0
Commit view x at position i to value n for alternative a.
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition: print.hpp:67
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
virtual void archive(Archive &e) const
Archive into e.
Definition: view-val.hpp:175
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
virtual NGL * ngl(Space &home, unsigned int a, View x, Val n) const =0
Create no-good literal for choice c and alternative a.
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:3944
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Choice for performing commit
Definition: core.hpp:1338
Archive representation
Definition: archive.hpp:46
ExecStatus
Definition: core.hpp:464
Filter f
Filter function.
Definition: view.hpp:93
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
ViewValNGL(Space &home, View x, Val n)
Initialize for propagator p with view x and value n.
Definition: view-val.hpp:187
View-value no-good literal.
Definition: view-val.hpp:65
virtual void archive(Archive &e) const
Archive into e.
Definition: view.hpp:134
virtual bool notice(void) const =0
Whether dispose must always be called (that is, notice is needed)
Gecode toplevel namespace
#define GECODE_VTABLE_EXPORT
Definition: support.hh:76
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
Home class for posting propagators
Definition: core.hpp:846
Choice storing position and value
Definition: view-val.hpp:50
virtual Val val(const Space &home, View x, int i)=0
Return value of view x at position i.
PosValChoice(const Brancher &b, unsigned int a, const Pos &p, const Val &n)
Initialize choice for brancher b, number of alternatives a, position p, and value n...
Definition: view-val.hpp:163
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition: modevent.hpp:58
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:142
No-good literal recorded during search.
Definition: core.hpp:1266