Generated on Sat Jan 20 2018 22:21:13 for Gecode by doxygen 1.8.13
view.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, 2005
8  *
9  * Last modified:
10  * $Date: 2017-03-09 09:51:58 +0100 (Thu, 09 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15565 $
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 
44  template<class View>
45  class ConstView {
46  public:
48  typedef typename View::VarImpType VarImpType;
50  typedef typename View::VarType VarType;
52 
53  unsigned int degree(void) const;
56  double afc(void) const;
58  static bool varderived(void);
60  VarImpType* varimp(void) const;
62 
64 
65  bool assigned(void) const;
68 
70 
71  static void schedule(Space& home, Propagator& p, ModEvent me);
74  static ModEvent me(const ModEventDelta& med);
76  static ModEventDelta med(ModEvent me);
78 
80 
81 
88  void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
90  void cancel(Space& home, Propagator& p, PropCond pc);
92  void reschedule(Space& home, Propagator& p, PropCond pc);
98  void subscribe(Space& home, Advisor& a, bool fail=false);
100  void cancel(Space& home, Advisor& a, bool fail=false);
102 
104 
105  static ModEvent modevent(const Delta& d);
108 
110 
111  void update(Space& home, bool share, ConstView& y);
114  };
115 
116 
117 
122  template<class Var>
123  class VarImpView {
124  public:
126  typedef Var VarType;
128  typedef typename Var::VarImpType VarImpType;
129  protected:
131  VarImpType* x;
133  VarImpView(void);
135  VarImpView(VarImpType* y);
137  void varimp(VarImpType* y);
138  public:
140 
141  static bool varderived(void);
144  VarImpType* varimp(void) const;
146  unsigned int degree(void) const;
148  double afc(void) const;
150 
152 
153  bool assigned(void) const;
156 
158 
159  static void schedule(Space& home, Propagator& p, ModEvent me);
162  static ModEvent me(const ModEventDelta& med);
164  static ModEventDelta med(ModEvent me);
166 
168 
169 
176  void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
178  void cancel(Space& home, Propagator& p, PropCond pc);
180  void reschedule(Space& home, Propagator& p, PropCond pc);
186  void subscribe(Space& home, Advisor& a, bool fail=false);
188  void cancel(Space& home, Advisor& a, bool fail=false);
190 
192 
193  static ModEvent modevent(const Delta& d);
196 
198 
199  void update(Space& home, bool share, VarImpView<Var>& y);
202  };
203 
208  template<class VarA, class VarB>
210  bool same(const VarImpView<VarA>& x, const VarImpView<VarB>& y);
212  template<class ViewA, class ViewB>
213  bool before(const ViewA& x, const ViewB& y);
215 
216 
221  template<class View>
222  class DerivedView {
223  public:
225  typedef typename View::VarImpType VarImpType;
227  typedef typename View::VarType VarType;
228  protected:
230  View x;
232  DerivedView(void);
233  public:
235  DerivedView(const View& y);
237 
238  static bool varderived(void);
241  VarImpType* varimp(void) const;
243  View base(void) const;
245  unsigned int degree(void) const;
247  double afc(void) const;
249 
251 
252  bool assigned(void) const;
255 
257 
258  static void schedule(Space& home, Propagator& p, ModEvent me);
261  static ModEvent me(const ModEventDelta& med);
263  static ModEventDelta med(ModEvent);
265 
267 
268 
275  void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
277  void cancel(Space& home, Propagator& p, PropCond pc);
279  void reschedule(Space& home, Propagator& p, PropCond pc);
285  void subscribe(Space& home, Advisor& a, bool fail=false);
287  void cancel(Space& home, Advisor& a, bool fail=false);
289 
291 
292  static ModEvent modevent(const Delta& d);
295 
297 
298  void update(Space& home, bool share, DerivedView<View>& y);
301  };
302 
303 
308  template<class ViewA, class ViewB>
309  bool shared(const ConstView<ViewA>&, const ConstView<ViewB>&);
314  template<class Var, class View>
315  bool shared(const VarImpView<Var>&, const ConstView<View>&);
320  template<class ViewA, class ViewB>
321  bool shared(const DerivedView<ViewA>&, const ConstView<ViewB>&);
326  template<class View, class Var>
327  bool shared(const ConstView<View>&, const VarImpView<Var>&);
332  template<class ViewA, class ViewB>
333  bool shared(const ConstView<ViewA>&, const DerivedView<ViewB>&);
338  template<class VarA, class VarB>
339  bool shared(const VarImpView<VarA>&, const VarImpView<VarB>&);
344  template<class Var, class View>
345  bool shared(const VarImpView<Var>&, const DerivedView<View>&);
350  template<class View, class Var>
351  bool shared(const DerivedView<View>&, const VarImpView<Var>&);
356  template<class ViewA, class ViewB>
357  bool shared(const DerivedView<ViewA>&, const DerivedView<ViewB>&);
358 
359 
360  /*
361  * Constant view: has no variable implementation
362  *
363  */
364  template<class View>
365  forceinline unsigned int
367  return 0;
368  }
369  template<class View>
370  forceinline double
371  ConstView<View>::afc(void) const {
372  return 0.0;
373  }
374  template<class View>
375  forceinline bool
377  return false;
378  }
379  template<class View>
380  forceinline typename View::VarImpType*
382  return NULL;
383  }
384  template<class View>
385  forceinline bool
387  return true;
388  }
389  template<class View>
390  forceinline void
392  bool schedule) {
393  if (schedule)
394  View::schedule(home,p,ME_GEN_ASSIGNED);
395  }
396  template<class View>
397  forceinline void
399  }
400  template<class View>
401  forceinline void
403  View::schedule(home,p,ME_GEN_ASSIGNED);
404  }
405  template<class View>
406  forceinline void
408  }
409  template<class View>
410  forceinline void
412  }
413  template<class View>
414  forceinline void
416  View::schedule(home,p,me);
417  }
418  template<class View>
421  return View::me(med);
422  }
423  template<class View>
426  return View::med(me);
427  }
428  template<class View>
431  (void) d;
432  return ME_GEN_NONE;
433  }
434  template<class View>
435  forceinline void
437  }
438 
439  /*
440  * Variable view: contains a pointer to a variable implementation
441  *
442  */
443  template<class Var>
446  : x(NULL) {}
447  template<class Var>
450  : x(y) {}
451  template<class Var>
452  forceinline void
454  x=y;
455  }
456  template<class Var>
457  forceinline bool
459  return true;
460  }
461  template<class Var>
462  forceinline typename Var::VarImpType*
464  return x;
465  }
466  template<class Var>
467  forceinline unsigned int
469  return x->degree();
470  }
471  template<class Var>
472  forceinline double
473  VarImpView<Var>::afc(void) const {
474  return x->afc();
475  }
476  template<class Var>
477  forceinline bool
479  return x->assigned();
480  }
481  template<class Var>
482  forceinline void
484  bool schedule) {
485  x->subscribe(home,p,pc,schedule);
486  }
487  template<class Var>
488  forceinline void
490  x->cancel(home,p,pc);
491  }
492  template<class Var>
493  forceinline void
495  x->reschedule(home,p,pc);
496  }
497  template<class Var>
498  forceinline void
500  x->subscribe(home,a,fail);
501  }
502  template<class Var>
503  forceinline void
504  VarImpView<Var>::cancel(Space& home, Advisor& a, bool fail) {
505  x->cancel(home,a,fail);
506  }
507  template<class Var>
508  forceinline void
510  VarImpType::schedule(home,p,me);
511  }
512  template<class Var>
515  return VarImpType::me(med);
516  }
517  template<class Var>
520  return VarImpType::med(me);
521  }
522  template<class Var>
525  return VarImpType::modevent(d);
526  }
527  template<class Var>
528  forceinline void
530  x = y.x->copy(home,share);
531  }
532 
533  /*
534  * Derived view: contain the base view from which they are derived
535  *
536  */
537 
538  template<class View>
541 
542  template<class View>
545  : x(y) {}
546 
547  template<class View>
548  forceinline bool
550  return View::varderived();
551  }
552 
553  template<class View>
554  forceinline typename View::VarImpType*
556  return x.varimp();
557  }
558 
559  template<class View>
560  forceinline View
562  return x;
563  }
564 
565  template<class View>
566  forceinline unsigned int
568  return x.degree();
569  }
570  template<class View>
571  forceinline double
573  return x.afc();
574  }
575  template<class View>
576  forceinline bool
578  return x.assigned();
579  }
580 
581  template<class View>
582  forceinline void
584  return View::schedule(home,p,me);
585  }
586  template<class View>
589  return View::me(med);
590  }
591  template<class View>
594  return View::med(me);
595  }
596 
597  template<class View>
598  forceinline void
600  bool schedule) {
601  x.subscribe(home,p,pc,schedule);
602  }
603  template<class View>
604  forceinline void
606  x.cancel(home,p,pc);
607  }
608  template<class View>
609  forceinline void
611  x.reschedule(home,p,pc);
612  }
613  template<class View>
614  forceinline void
616  x.subscribe(home,a,fail);
617  }
618  template<class View>
619  forceinline void
620  DerivedView<View>::cancel(Space& home, Advisor& a, bool fail) {
621  x.cancel(home,a,fail);
622  }
623  template<class View>
626  return View::modevent(d);
627  }
628  template<class View>
629  forceinline void
631  x.update(home,share,y.x);
632  }
633 
634 
635  /*
636  * Tests whether two views are the same
637  *
638  */
639 
641  template<class ViewA, class ViewB>
642  forceinline bool
644  return false;
645  }
647  template<class Var, class View>
648  forceinline bool
650  return false;
651  }
653  template<class ViewA, class ViewB>
654  forceinline bool
656  return false;
657  }
659  template<class Var, class View>
660  forceinline bool
662  return false;
663  }
665  template<class View, class Var>
666  forceinline bool
668  return false;
669  }
671  template<class Var>
672  forceinline bool
674  return x.varimp() == y.varimp();
675  }
677  template<class ViewA, class ViewB>
678  forceinline bool
680  return same(x.base(),y.base());
681  }
682 
683 
684  /*
685  * Tests whether one view is before the other
686  *
687  */
688  template<class ViewA, class ViewB>
689  forceinline bool
690  before(const ViewA& x, const ViewB& y) {
691  return x.varimp() < y.varimp();
692  }
693 
694 
695  /*
696  * Testing whether two views share the same variable
697  *
698  */
699 
700  template<class ViewA, class ViewB>
701  forceinline bool
703  return false;
704  }
705  template<class Var, class View>
706  forceinline bool
708  return false;
709  }
710  template<class ViewA, class ViewB>
711  forceinline bool
713  return false;
714  }
715  template<class View, class Var>
716  forceinline bool
718  return false;
719  }
720  template<class ViewA, class ViewB>
721  forceinline bool
723  return false;
724  }
725  template<class VarA, class VarB>
726  forceinline bool
728  return (static_cast<VarImpBase*>(x.varimp()) ==
729  static_cast<VarImpBase*>(y.varimp()));
730  }
731  template<class Var, class View>
732  forceinline bool
734  return (View::varderived() &&
735  static_cast<VarImpBase*>(x.varimp()) ==
736  static_cast<VarImpBase*>(y.varimp()));
737  }
738  template<class View, class Var>
739  forceinline bool
741  return (View::varderived() &&
742  static_cast<VarImpBase*>(x.varimp()) ==
743  static_cast<VarImpBase*>(y.varimp()));
744  }
745  template<class ViewA, class ViewB>
746  forceinline bool
748  return (ViewA::varderived() && ViewB::varderived() &&
749  static_cast<VarImpBase*>(x.varimp()) ==
750  static_cast<VarImpBase*>(y.varimp()));
751  }
752 
753 }
754 
755 // STATISTICS: kernel-var
VarImpType * varimp(void) const
Return dummy variable implementation of view.
Definition: view.hpp:381
View base(void) const
Return view from which this view is derived.
Definition: view.hpp:561
View::VarType VarType
The variable type corresponding to the constant view.
Definition: view.hpp:50
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:391
static ModEvent modevent(const Delta &d)
Return modification event.
Definition: view.hpp:430
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:386
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
void update(Space &home, bool share, ConstView &y)
Update this view to be a clone of view y.
Definition: view.hpp:436
const ModEvent ME_GEN_ASSIGNED
Generic modification event: variable is assigned a value.
Definition: core.hpp:149
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: view.hpp:402
AFC afc
Definition: afc.cpp:139
int ModEvent
Type for modification events.
Definition: core.hpp:142
void varimp(VarImpType *y)
Set variable implementation to y.
Definition: view.hpp:453
Base-class for propagators.
Definition: core.hpp:1092
Base-class for advisors.
Definition: core.hpp:1294
bool shared(const DerivedView< ViewA > &, const DerivedView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:747
VarImpView(void)
Default constructor.
Definition: view.hpp:445
Base-class for constant views.
Definition: view.hpp:45
Computation spaces.
Definition: core.hpp:1748
Base-class for derived views.
Definition: view.hpp:222
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:398
Gecode::IntSet d(v, 7)
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors)
Definition: view.hpp:366
View::VarImpType VarImpType
The variable implementation type corresponding to the constant view.
Definition: view.hpp:48
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
bool same(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether two views are the same.
Definition: view.hpp:643
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:420
int PropCond
Type for propagation conditions.
Definition: core.hpp:152
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
static bool varderived(void)
Return whether this view is derived from a VarImpView.
Definition: view.hpp:376
bool before(const ViewA &x, const ViewB &y)
Definition: view.hpp:690
Base-class for variable implementation views.
Definition: view.hpp:123
Var VarType
The variable type corresponding to the view.
Definition: view.hpp:126
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition: view.hpp:415
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
Var::VarImpType VarImpType
The variable implementation type corresponding to the view.
Definition: view.hpp:128
View::VarType VarType
The variable type belonging to the View.
Definition: view.hpp:227
const double base
Base for geometric restart sequence.
Definition: search.hh:122
Base class for variables.
Definition: var.hpp:44
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Generic domain change information to be supplied to advisors.
Definition: core.hpp:281
View::VarImpType VarImpType
The variable implementation type belonging to the View.
Definition: view.hpp:225
double afc(void) const
Return accumulated failure count.
Definition: view.hpp:371
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
#define forceinline
Definition: config.hpp:173
const ModEvent ME_GEN_NONE
Generic modification event: no modification.
Definition: core.hpp:147
Post propagator for SetVar x
Definition: set.hh:784
View x
View from which this view is derived.
Definition: view.hpp:230
VarImpType * varimp(void) const
Return variable implementation of view.
Definition: view.hpp:555
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
bool same(const DerivedView< ViewA > &x, const DerivedView< ViewB > &y)
Test whether two views are the same.
Definition: view.hpp:679
Gecode toplevel namespace
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
VarImpType * x
Pointer to variable implementation.
Definition: view.hpp:131
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
static ModEventDelta med(ModEvent me)
Translate modification event me to modification event delta for view.
Definition: view.hpp:425