Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
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: 2013-02-18 21:53:58 +0100 (Mon, 18 Feb 2013) $ by $Author: schulte $
11  * $Revision: 13310 $
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(const Space& home) 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 subscribe(Space& home, Advisor& a);
94  void cancel(Space& home, Advisor& a);
96 
98 
99  static ModEvent modevent(const Delta& d);
102 
104 
105  void update(Space& home, bool share, ConstView& y);
108  };
109 
110 
111 
116  template<class Var>
117  class VarImpView {
118  public:
120  typedef Var VarType;
122  typedef typename Var::VarImpType VarImpType;
123  protected:
125  VarImpType* x;
127  VarImpView(void);
129  VarImpView(VarImpType* y);
130  public:
132 
133  static bool varderived(void);
136  VarImpType* varimp(void) const;
138  unsigned int degree(void) const;
140  double afc(const Space& home) const;
142 
144 
145  bool assigned(void) const;
148 
150 
151  static void schedule(Space& home, Propagator& p, ModEvent me);
154  static ModEvent me(const ModEventDelta& med);
156  static ModEventDelta med(ModEvent me);
158 
160 
161 
168  void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
170  void cancel(Space& home, Propagator& p, PropCond pc);
172  void subscribe(Space& home, Advisor& a);
174  void cancel(Space& home, Advisor& a);
176 
178 
179  static ModEvent modevent(const Delta& d);
182 
184 
185  void update(Space& home, bool share, VarImpView<Var>& y);
188  };
189 
194  template<class VarA, class VarB>
196  bool same(const VarImpView<VarA>& x, const VarImpView<VarB>& y);
198  template<class ViewA, class ViewB>
199  bool before(const ViewA& x, const ViewB& y);
201 
202 
207  template<class View>
208  class DerivedView {
209  public:
211  typedef typename View::VarImpType VarImpType;
213  typedef typename View::VarType VarType;
214  protected:
216  View x;
218  DerivedView(void);
220  DerivedView(const View& y);
221  public:
223 
224  static bool varderived(void);
227  VarImpType* varimp(void) const;
229  View base(void) const;
231  unsigned int degree(void) const;
233  double afc(const Space& home) const;
235 
237 
238  bool assigned(void) const;
241 
243 
244  static void schedule(Space& home, Propagator& p, ModEvent me);
247  static ModEvent me(const ModEventDelta& med);
249  static ModEventDelta med(ModEvent);
251 
253 
254 
261  void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
263  void cancel(Space& home, Propagator& p, PropCond pc);
265  void subscribe(Space& home, Advisor& a);
267  void cancel(Space& home, Advisor& a);
269 
271 
272  static ModEvent modevent(const Delta& d);
275 
277 
278  void update(Space& home, bool share, DerivedView<View>& y);
281  };
282 
283 
288  template<class ViewA, class ViewB>
289  bool shared(const ConstView<ViewA>&, const ConstView<ViewB>&);
294  template<class Var, class View>
295  bool shared(const VarImpView<Var>&, const ConstView<View>&);
300  template<class ViewA, class ViewB>
301  bool shared(const DerivedView<ViewA>&, const ConstView<ViewB>&);
306  template<class View, class Var>
307  bool shared(const ConstView<View>&, const VarImpView<Var>&);
312  template<class ViewA, class ViewB>
313  bool shared(const ConstView<ViewA>&, const DerivedView<ViewB>&);
318  template<class VarA, class VarB>
319  bool shared(const VarImpView<VarA>&, const VarImpView<VarB>&);
324  template<class Var, class View>
325  bool shared(const VarImpView<Var>&, const DerivedView<View>&);
330  template<class View, class Var>
331  bool shared(const DerivedView<View>&, const VarImpView<Var>&);
336  template<class ViewA, class ViewB>
337  bool shared(const DerivedView<ViewA>&, const DerivedView<ViewB>&);
338 
339 
340  /*
341  * Constant view: has no variable implementation
342  *
343  */
344  template<class View>
345  forceinline unsigned int
347  return 0;
348  }
349  template<class View>
350  forceinline double
351  ConstView<View>::afc(const Space&) const {
352  return 0.0;
353  }
354  template<class View>
355  forceinline bool
357  return false;
358  }
359  template<class View>
360  forceinline typename View::VarImpType*
362  return NULL;
363  }
364  template<class View>
365  forceinline bool
367  return true;
368  }
369  template<class View>
370  forceinline void
372  bool schedule) {
373  if (schedule)
374  View::schedule(home,p,ME_GEN_ASSIGNED);
375  }
376  template<class View>
377  forceinline void
379  }
380  template<class View>
381  forceinline void
383  }
384  template<class View>
385  forceinline void
387  }
388  template<class View>
389  forceinline void
391  View::schedule(home,p,me);
392  }
393  template<class View>
396  return View::me(med);
397  }
398  template<class View>
401  return View::med(me);
402  }
403  template<class View>
406  (void) d;
407  return ME_GEN_NONE;
408  }
409  template<class View>
410  forceinline void
412  }
413 
414  /*
415  * Variable view: contains a pointer to a variable implementation
416  *
417  */
418  template<class Var>
421  : x(NULL) {}
422  template<class Var>
425  : x(y) {}
426  template<class Var>
427  forceinline bool
429  return true;
430  }
431  template<class Var>
432  forceinline typename Var::VarImpType*
434  return x;
435  }
436  template<class Var>
437  forceinline unsigned int
439  return x->degree();
440  }
441  template<class Var>
442  forceinline double
443  VarImpView<Var>::afc(const Space& home) const {
444  return x->afc(home);
445  }
446  template<class Var>
447  forceinline bool
449  return x->assigned();
450  }
451  template<class Var>
452  forceinline void
454  bool schedule) {
455  x->subscribe(home,p,pc,schedule);
456  }
457  template<class Var>
458  forceinline void
460  x->cancel(home,p,pc);
461  }
462  template<class Var>
463  forceinline void
465  x->subscribe(home,a);
466  }
467  template<class Var>
468  forceinline void
470  x->cancel(home,a);
471  }
472  template<class Var>
473  forceinline void
475  VarImpType::schedule(home,p,me);
476  }
477  template<class Var>
480  return VarImpType::me(med);
481  }
482  template<class Var>
485  return VarImpType::med(me);
486  }
487  template<class Var>
490  return VarImpType::modevent(d);
491  }
492  template<class Var>
493  forceinline void
495  x = y.x->copy(home,share);
496  }
497 
498  /*
499  * Derived view: contain the base view from which they are derived
500  *
501  */
502 
503  template<class View>
506 
507  template<class View>
510  : x(y) {}
511 
512  template<class View>
513  forceinline bool
515  return View::varderived();
516  }
517 
518  template<class View>
519  forceinline typename View::VarImpType*
521  return x.varimp();
522  }
523 
524  template<class View>
525  forceinline View
527  return x;
528  }
529 
530  template<class View>
531  forceinline unsigned int
533  return x.degree();
534  }
535  template<class View>
536  forceinline double
537  DerivedView<View>::afc(const Space& home) const {
538  return x.afc(home);
539  }
540  template<class View>
541  forceinline bool
543  return x.assigned();
544  }
545 
546  template<class View>
547  forceinline void
549  return View::schedule(home,p,me);
550  }
551  template<class View>
554  return View::me(med);
555  }
556  template<class View>
559  return View::med(me);
560  }
561 
562  template<class View>
563  forceinline void
565  bool schedule) {
566  x.subscribe(home,p,pc,schedule);
567  }
568  template<class View>
569  forceinline void
571  x.cancel(home,p,pc);
572  }
573  template<class View>
574  forceinline void
576  x.subscribe(home,a);
577  }
578  template<class View>
579  forceinline void
581  x.cancel(home,a);
582  }
583  template<class View>
586  return View::modevent(d);
587  }
588  template<class View>
589  forceinline void
591  x.update(home,share,y.x);
592  }
593 
594 
595  /*
596  * Tests whether two views are the same
597  *
598  */
599 
601  template<class ViewA, class ViewB>
602  forceinline bool
604  return false;
605  }
607  template<class Var, class View>
608  forceinline bool
610  return false;
611  }
613  template<class ViewA, class ViewB>
614  forceinline bool
616  return false;
617  }
619  template<class Var, class View>
620  forceinline bool
622  return false;
623  }
625  template<class View, class Var>
626  forceinline bool
628  return false;
629  }
631  template<class Var>
632  forceinline bool
633  same(const VarImpView<Var>& x, const VarImpView<Var>& y) {
634  return x.varimp() == y.varimp();
635  }
637  template<class ViewA, class ViewB>
638  forceinline bool
640  return same(x.base(),y.base());
641  }
642 
643 
644  /*
645  * Tests whether one view is before the other
646  *
647  */
648  template<class ViewA, class ViewB>
649  forceinline bool
650  before(const ViewA& x, const ViewB& y) {
651  return x.varimp() < y.varimp();
652  }
653 
654 
655  /*
656  * Testing whether two views share the same variable
657  *
658  */
659 
660  template<class ViewA, class ViewB>
661  forceinline bool
663  return false;
664  }
665  template<class Var, class View>
666  forceinline bool
668  return false;
669  }
670  template<class ViewA, class ViewB>
671  forceinline bool
673  return false;
674  }
675  template<class View, class Var>
676  forceinline bool
678  return false;
679  }
680  template<class ViewA, class ViewB>
681  forceinline bool
683  return false;
684  }
685  template<class VarA, class VarB>
686  forceinline bool
688  return (static_cast<VarImpBase*>(x.varimp()) ==
689  static_cast<VarImpBase*>(y.varimp()));
690  }
691  template<class Var, class View>
692  forceinline bool
694  return (View::varderived() &&
695  static_cast<VarImpBase*>(x.varimp()) ==
696  static_cast<VarImpBase*>(y.varimp()));
697  }
698  template<class View, class Var>
699  forceinline bool
701  return (View::varderived() &&
702  static_cast<VarImpBase*>(x.varimp()) ==
703  static_cast<VarImpBase*>(y.varimp()));
704  }
705  template<class ViewA, class ViewB>
706  forceinline bool
708  return (ViewA::varderived() && ViewB::varderived() &&
709  static_cast<VarImpBase*>(x.varimp()) ==
710  static_cast<VarImpBase*>(y.varimp()));
711  }
712 
713 }
714 
715 // STATISTICS: kernel-var
static ModEventDelta med(ModEvent me)
Translate modification event me to modification event delta for view.
Definition: view.hpp:484
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:459
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:542
View::VarType VarType
The variable type corresponding to the constant view.
Definition: view.hpp:50
static ModEvent modevent(const Delta &d)
Return modification event.
Definition: view.hpp:585
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:371
VarImpType * varimp(void) const
Return variable implementation of view.
Definition: view.hpp:433
static ModEvent modevent(const Delta &d)
Return modification event.
Definition: view.hpp:405
double afc(const Space &home) const
Return accumulated failure count.
Definition: view.hpp:351
static ModEventDelta med(ModEvent)
Translate modification event me to modification event delta for view.
Definition: view.hpp:558
void update(Space &home, bool share, ConstView &y)
Update this view to be a clone of view y.
Definition: view.hpp:411
const ModEvent ME_GEN_ASSIGNED
Generic modification event: variable is assigned a value.
Definition: core.hpp:153
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition: view.hpp:548
int ModEvent
Type for modification events.
Definition: core.hpp:146
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:570
Base-class for propagators.
Definition: core.hpp:755
Base-class for advisors.
Definition: core.hpp:926
VarImpView(void)
Default constructor.
Definition: view.hpp:420
VarImpType * varimp(void) const
Return dummy variable implementation of view.
Definition: view.hpp:361
Base-class for constant views.
Definition: view.hpp:45
Computation spaces.
Definition: core.hpp:1362
Base-class for derived views.
Definition: view.hpp:208
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:378
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors)
Definition: view.hpp:438
Gecode::IntSet d(v, 7)
DerivedView(void)
Default constructor.
Definition: view.hpp:505
View::VarImpType VarImpType
The variable implementation type corresponding to the constant view.
Definition: view.hpp:48
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:453
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors)
Definition: view.hpp:346
bool same(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether two views are the same.
Definition: view.hpp:603
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
static bool varderived(void)
Return whether this view is derived from a VarImpView.
Definition: view.hpp:428
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:395
View base(void) const
Return view from which this view is derived.
Definition: view.hpp:526
int PropCond
Type for propagation conditions.
Definition: core.hpp:156
static bool varderived(void)
Return whether this view is derived from a VarImpView.
Definition: view.hpp:356
void update(Space &home, bool share, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition: view.hpp:590
bool before(const ViewA &x, const ViewB &y)
Definition: view.hpp:650
Base-class for variable implementation views.
Definition: view.hpp:117
Var VarType
The variable type corresponding to the view.
Definition: view.hpp:120
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:494
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition: view.hpp:390
Var::VarImpType VarImpType
The variable implementation type corresponding to the view.
Definition: view.hpp:122
View::VarType VarType
The variable type belonging to the View.
Definition: view.hpp:213
Base class for variables.
Definition: var.hpp:44
double afc(const Space &home) const
Return accumulated failure count.
Definition: view.hpp:443
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:275
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:366
static ModEvent modevent(const Delta &d)
Return modification event.
Definition: view.hpp:489
View::VarImpType VarImpType
The variable implementation type belonging to the View.
Definition: view.hpp:211
VarImpType * varimp(void) const
Return variable implementation of view.
Definition: view.hpp:520
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:479
#define forceinline
Definition: config.hpp:132
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:448
const ModEvent ME_GEN_NONE
Generic modification event: no modification.
Definition: core.hpp:151
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:564
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:553
View x
View from which this view is derived.
Definition: view.hpp:216
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
static bool varderived(void)
Return whether this view is derived from a VarImpView.
Definition: view.hpp:514
double afc(const Space &home) const
Return accumulated failure count.
Definition: view.hpp:537
Gecode toplevel namespace
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition: view.hpp:474
VarImpType * x
Pointer to variable implementation.
Definition: view.hpp:125
unsigned int degree(void) const
Return degree (number of subscribed propagators)
Definition: view.hpp:532
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
static ModEventDelta med(ModEvent me)
Translate modification event me to modification event delta for view.
Definition: view.hpp:400