Generated on Thu Jul 25 2019 00:00:00 for Gecode by doxygen 1.8.15
brancher-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: 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 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);
58  const Val& val(void) const;
60  virtual size_t size(void) const;
62  virtual void archive(Archive& e) const;
63  };
64 
65 
67  template<class View, class Val, PropCond pc>
68  class ViewValNGL : public NGL {
69  protected:
71  View x;
73  Val n;
74  public:
76  ViewValNGL(Space& home, View x, Val n);
78  ViewValNGL(Space& home, bool share, ViewValNGL& ngl);
80  virtual void subscribe(Space& home, Propagator& p);
82  virtual void cancel(Space& home, Propagator& p);
84  virtual void reschedule(Space& home, Propagator& p);
86  virtual size_t dispose(Space& home);
87  };
88 
96  template<class View, int n, class Val, unsigned int a,
97  class Filter, class Print>
98  class ViewValBrancher : public ViewBrancher<View,Filter,n> {
99  protected:
104  typedef typename View::VarType Var;
108  Print p;
110  ViewValBrancher(Space& home, bool share, ViewValBrancher& b);
112  ViewValBrancher(Home home,
114  ViewSel<View>* vs[n],
118  public:
120  virtual const Choice* choice(Space& home);
122  virtual const Choice* choice(const Space& home, Archive& e);
124  virtual ExecStatus commit(Space& home, const Choice& c, unsigned int b);
126  virtual NGL* ngl(Space& home, const Choice& c, unsigned int b) const;
134  virtual void print(const Space& home, const Choice& c, unsigned int b,
135  std::ostream& o) const;
137  virtual Actor* copy(Space& home, bool share);
139  virtual size_t dispose(Space& home);
141  static void post(Home home,
143  ViewSel<View>* vs[n],
147  };
148 
150  template<class View, int n, class Val, unsigned int a>
151  void
154  ViewSel<View>* vs[n],
159 
160  /*
161  * %Choice with position and value
162  *
163  */
164  template<class Val>
167  const Pos& p, const Val& n)
168  : PosChoice(b,a,p), _val(n) {}
169 
170  template<class Val>
171  forceinline const Val&
173  return _val;
174  }
175 
176  template<class Val>
177  forceinline size_t
179  return sizeof(PosValChoice<Val>);
180  }
181 
182  template<class Val>
183  forceinline void
186  e << _val;
187  }
188 
189 
190  /*
191  * View-value no-good literal
192  *
193  */
194  template<class View, class Val, PropCond pc>
197  : NGL(home), x(x0), n(n0) {}
198 
199  template<class View, class Val, PropCond pc>
202  : NGL(home,share,ngl), n(ngl.n) {
203  x.update(home,share,ngl.x);
204  }
205 
206  template<class View, class Val, PropCond pc>
207  void
209  x.subscribe(home,p,pc);
210  }
211 
212  template<class View, class Val, PropCond pc>
213  void
215  x.cancel(home,p,pc);
216  }
217 
218  template<class View, class Val, PropCond pc>
219  void
221  x.reschedule(home,p,pc);
222  }
223 
224  template<class View, class Val, PropCond pc>
225  size_t
227  (void) NGL::dispose(home);
228  return sizeof(*this);
229  }
230 
231 
232 
233  /*
234  * Generic brancher based on variable/value selection
235  *
236  */
237  template<class View, int n, class Val, unsigned int a,
238  class Filter, class Print>
243  ViewSel<View>* vs[n],
247  : ViewBrancher<View,Filter,n>(home,x,vs,bf), vsc(vsc0), p(vvp) {
248  if (vsc->notice() || f.notice() || p.notice())
249  home.notice(*this,AP_DISPOSE,true);
250  }
251 
252  template<class View, int n, class Val, unsigned int a,
253  class Filter, class Print>
254  forceinline void
259  VarValPrint<Var,Val> vvp) {
261  (home,x,vs,vsc,bf,vvp);
262  }
263 
264  template<class View, int n, class Val, unsigned int a,
265  class Filter, class Print>
270  : ViewBrancher<View,Filter,n>(home,shared,b),
271  vsc(b.vsc->copy(home,shared)), p(home,shared,b.p) {}
272 
273  template<class View, int n, class Val, unsigned int a,
274  class Filter, class Print>
275  Actor*
278  (home,shared,*this);
279  }
280 
281  template<class View, int n, class Val, unsigned int a,
282  class Filter, class Print>
283  const Choice*
287  return new PosValChoice<Val>(*this,a,p,vsc->val(home,v,p.pos));
288  }
289 
290  template<class View, int n, class Val, unsigned int a,
291  class Filter, class Print>
292  const Choice*
294  Archive& e) {
295  (void) home;
296  int p; e >> p;
297  Val v; e >> v;
298  return new PosValChoice<Val>(*this,a,p,v);
299  }
300 
301  template<class View, int n, class Val, unsigned int a,
302  class Filter, class Print>
303  ExecStatus
305  ::commit(Space& home, const Choice& c, unsigned int b) {
306  const PosValChoice<Val>& pvc
307  = static_cast<const PosValChoice<Val>&>(c);
308  return me_failed(vsc->commit(home,b,
310  pvc.pos().pos,
311  pvc.val()))
312  ? ES_FAILED : ES_OK;
313  }
314 
315  template<class View, int n, class Val, unsigned int a,
316  class Filter, class Print>
317  NGL*
319  ::ngl(Space& home, const Choice& c, unsigned int b) const {
320  const PosValChoice<Val>& pvc
321  = static_cast<const PosValChoice<Val>&>(c);
322  return vsc->ngl(home,b,
324  }
325 
326  template<class View, int n, class Val, unsigned int a,
327  class Filter, class Print>
328  void
330  ::print(const Space& home, const Choice& c, unsigned int b,
331  std::ostream& o) const {
332  const PosValChoice<Val>& pvc
333  = static_cast<const PosValChoice<Val>&>(c);
334  View xi = ViewBrancher<View,Filter,n>::view(pvc.pos());
335  if (p)
336  p(home,*this,b,xi,pvc.pos().pos,pvc.val(),o);
337  else
338  vsc->print(home,b,xi,pvc.pos().pos,pvc.val(),o);
339  }
340 
341  template<class View, int n, class Val, unsigned int a,
342  class Filter, class Print>
343  forceinline size_t
345  if (vsc->notice() || f.notice() || p.notice())
346  home.ignore(*this,AP_DISPOSE,true);
347  vsc->dispose(home);
350  }
351 
352  template<class View, int n, class Val, unsigned int a>
353  forceinline void
356  ViewSel<View>* vs[n],
360  if (bf) {
361  if (vvp) {
362  ViewValBrancher<View,n,Val,a,
364  ::post(home,x,vs,vsc,bf,vvp);
365  } else {
366  ViewValBrancher<View,n,Val,a,
368  ::post(home,x,vs,vsc,bf,vvp);
369  }
370  } else {
371  if (vvp)
372  ViewValBrancher<View,n,Val,a,
374  ::post(home,x,vs,vsc,bf,vvp);
375  else
376  ViewValBrancher<View,n,Val,a,
378  ::post(home,x,vs,vsc,bf,vvp);
379  }
380  }
381 
382 }
383 
384 // STATISTICS: kernel-branch
virtual size_t dispose(Space &home)
Dispose.
virtual void cancel(Space &home, Propagator &p)
Cancel subscription for no-good literal.
ViewValBrancher(Space &home, bool share, ViewValBrancher &b)
Constructor for cloning b.
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.
Actor must always be disposed.
Definition: core.hpp:630
View::VarType Var
The corresponding variable.
Class withot a branch filter function.
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
Val n
The stored value.
virtual size_t dispose(Space &home)
Delete brancher and return its size.
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.
Generic brancher by view selection.
View x
The stored view.
Base-class for propagators.
Definition: core.hpp:1092
ViewArray< View > x
Views to branch on.
View view(const Pos &p) const
Return view according to position information p.
Computation spaces.
Definition: core.hpp:1748
Class storing a print function.
const Pos & pos(void) const
Return position in array.
Class without print function.
Base-class for both propagators and branchers.
Definition: core.hpp:696
virtual ExecStatus commit(Space &home, const Choice &c, unsigned int b)
Perform commit for choice c and alternative b.
ViewSel< View > * vs[n]
View selection objects.
Pos pos(Space &home)
Return position information.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
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.
Base-class for branchers.
Definition: core.hpp:1446
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Class storing a branch filter function.
Execution has resulted in failure.
Definition: core.hpp:542
Generic brancher by view and value selection.
virtual size_t size(void) const
Report size occupied.
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.
ValSelCommitBase< View, Val > * vsc
Value selection and commit object.
unsigned int size(I &i)
Size of all ranges of range iterator i.
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
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.
virtual void print(const Space &home, const Choice &c, unsigned int b, std::ostream &o) const
Print branch for choice c and alternative b.
const Val & val(void) const
Return value to branch with.
virtual void subscribe(Space &home, Propagator &p)
Create subscription for no-good literal.
Choices storing position
virtual const Choice * choice(Space &home)
Return choice.
Position information.
View arrays.
Definition: array.hpp:234
Print p
Print function.
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3321
const int v[7]
Definition: distinct.cpp:263
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
virtual void archive(Archive &e) const
Archive into e.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
virtual void reschedule(Space &home, Propagator &p)
Schedule propagator p.
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:4141
Choice for performing commit
Definition: core.hpp:1414
Archive representation
Definition: archive.hpp:45
ExecStatus
Definition: core.hpp:540
#define forceinline
Definition: config.hpp:173
Filter f
Filter function.
Post propagator for SetVar x
Definition: set.hh:784
Execution is okay.
Definition: core.hpp:544
ViewValNGL(Space &home, View x, Val n)
Initialize for propagator p with view x and value n.
View-value no-good literal.
virtual void archive(Archive &e) const
Archive into e.
virtual bool notice(void) const =0
Whether dispose must always be called (that is, notice is needed)
virtual Actor * copy(Space &home, bool share)
Perform cloning.
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
Gecode toplevel namespace
#define GECODE_VTABLE_EXPORT
Definition: support.hh:76
const int pos
Position of view.
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
Home class for posting propagators
Definition: core.hpp:922
Choice storing position and value
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.
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.
No-good literal recorded during search.
Definition: core.hpp:1342