Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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 * Contributing authors:
7 * Samuel Gagnon <samuel.gagnon92@gmail.com>
8 *
9 * Copyright:
10 * Christian Schulte, 2005
11 * Samuel Gagnon, 2018
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
38namespace 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
54 unsigned int degree(void) const;
56 double afc(void) const;
58 static bool varderived(void);
60 VarImpType* varimp(void) const;
61#ifdef GECODE_HAS_CBS
63 unsigned int id(void) const;
64#endif
66
68
69
70 bool assigned(void) const;
72
74
75
76 static void schedule(Space& home, Propagator& p, ModEvent me);
78 static ModEvent me(const ModEventDelta& med);
82
84
85
92 void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
94 void cancel(Space& home, Propagator& p, PropCond pc);
102 void subscribe(Space& home, Advisor& a, bool fail=false);
104 void cancel(Space& home, Advisor& a, bool fail=false);
106
108
109
110 static ModEvent modevent(const Delta& d);
112
114
115
116 void update(Space& home, ConstView& y);
118
120
121
122 bool operator <(const ConstView& y) const;
124 };
125
126
127
132 template<class Var>
134 public:
136 typedef Var VarType;
138 typedef typename Var::VarImpType VarImpType;
139 protected:
148 public:
150
151
152 static bool varderived(void);
154 VarImpType* varimp(void) const;
156 unsigned int degree(void) const;
158 double afc(void) const;
159#ifdef GECODE_HAS_CBS
161 unsigned int id(void) const;
162#endif
164
166
167
168 bool assigned(void) const;
170
172
173
174 static void schedule(Space& home, Propagator& p, ModEvent me);
176 static ModEvent me(const ModEventDelta& med);
180
182
183
190 void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
192 void cancel(Space& home, Propagator& p, PropCond pc);
200 void subscribe(Space& home, Advisor& a, bool fail=false);
202 void cancel(Space& home, Advisor& a, bool fail=false);
204
206
207
208 static ModEvent modevent(const Delta& d);
210
212
213
216
218
219
220 bool operator <(const VarImpView& y) const;
222 };
223
224
229 template<class View>
231 public:
233 typedef typename View::VarImpType VarImpType;
235 typedef typename View::VarType VarType;
236 protected:
238 View x;
241 public:
243 DerivedView(const View& y);
245
246
247 static bool varderived(void);
249 VarImpType* varimp(void) const;
251 View base(void) const;
253 unsigned int degree(void) const;
255 double afc(void) const;
256#ifdef GECODE_HAS_CBS
258 unsigned int id(void) const;
259#endif
261
263
264
265 bool assigned(void) const;
267
269
270
271 static void schedule(Space& home, Propagator& p, ModEvent me);
273 static ModEvent me(const ModEventDelta& med);
277
279
280
287 void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
289 void cancel(Space& home, Propagator& p, PropCond pc);
297 void subscribe(Space& home, Advisor& a, bool fail=false);
299 void cancel(Space& home, Advisor& a, bool fail=false);
301
303
304
305 static ModEvent modevent(const Delta& d);
307
309
310
313
315
316
317 bool operator <(const DerivedView<View>& y) const;
319 };
320
321
326 template<class ViewA, class ViewB>
327 bool shared(const ConstView<ViewA>&, const ConstView<ViewB>&);
332 template<class Var, class View>
333 bool shared(const VarImpView<Var>&, const ConstView<View>&);
338 template<class ViewA, class ViewB>
339 bool shared(const DerivedView<ViewA>&, const ConstView<ViewB>&);
344 template<class View, class Var>
345 bool shared(const ConstView<View>&, const VarImpView<Var>&);
350 template<class ViewA, class ViewB>
351 bool shared(const ConstView<ViewA>&, const DerivedView<ViewB>&);
356 template<class VarA, class VarB>
357 bool shared(const VarImpView<VarA>&, const VarImpView<VarB>&);
362 template<class Var, class View>
363 bool shared(const VarImpView<Var>&, const DerivedView<View>&);
368 template<class View, class Var>
369 bool shared(const DerivedView<View>&, const VarImpView<Var>&);
374 template<class ViewA, class ViewB>
375 bool shared(const DerivedView<ViewA>&, const DerivedView<ViewB>&);
376
377
378 /*
379 * Constant view: has no variable implementation
380 *
381 */
382 template<class View>
383 forceinline unsigned int
385 return 0;
386 }
387 template<class View>
388 forceinline double
390 return 0.0;
391 }
392 template<class View>
393 forceinline bool
395 return false;
396 }
397 template<class View>
398 forceinline typename View::VarImpType*
400 return NULL;
401 }
402#ifdef GECODE_HAS_CBS
403 template<class View>
404 forceinline unsigned int
405 ConstView<View>::id(void) const {
406 return 0;
407 }
408#endif
409 template<class View>
410 forceinline bool
412 return true;
413 }
414 template<class View>
415 forceinline void
417 bool schedule) {
418 if (schedule)
419 View::schedule(home,p,ME_GEN_ASSIGNED);
420 }
421 template<class View>
422 forceinline void
425 template<class View>
426 forceinline void
428 View::schedule(home,p,ME_GEN_ASSIGNED);
429 }
430 template<class View>
431 forceinline void
434 template<class View>
435 forceinline void
438 template<class View>
439 forceinline void
441 View::schedule(home,p,me);
442 }
443 template<class View>
446 return View::me(med);
447 }
448 template<class View>
451 return View::med(me);
452 }
453 template<class View>
456 (void) d;
457 return ME_GEN_NONE;
458 }
459 template<class View>
460 forceinline void
463 template<class View>
466 return true;
467 }
468
469
470 /*
471 * Variable view: contains a pointer to a variable implementation
472 *
473 */
474 template<class Var>
477 : x(NULL) {}
478 template<class Var>
482 template<class Var>
483 forceinline void
487 template<class Var>
488 forceinline bool
490 return true;
491 }
492 template<class Var>
493 forceinline typename Var::VarImpType*
495 return x;
496 }
497 template<class Var>
498 forceinline unsigned int
500 return x->degree();
501 }
502 template<class Var>
503 forceinline double
505 return x->afc();
506 }
507#ifdef GECODE_HAS_CBS
508 template<class Var>
509 forceinline unsigned int
510 VarImpView<Var>::id(void) const {
511 return x->id();
512 }
513#endif
514 template<class Var>
515 forceinline bool
517 return x->assigned();
518 }
519 template<class Var>
520 forceinline void
522 bool schedule) {
523 x->subscribe(home,p,pc,schedule);
524 }
525 template<class Var>
526 forceinline void
528 x->cancel(home,p,pc);
529 }
530 template<class Var>
531 forceinline void
533 x->reschedule(home,p,pc);
534 }
535 template<class Var>
536 forceinline void
538 x->subscribe(home,a,fail);
539 }
540 template<class Var>
541 forceinline void
543 x->cancel(home,a,fail);
544 }
545 template<class Var>
546 forceinline void
548 VarImpType::schedule(home,p,me);
549 }
550 template<class Var>
553 return VarImpType::me(med);
554 }
555 template<class Var>
558 return VarImpType::med(me);
559 }
560 template<class Var>
563 return VarImpType::modevent(d);
564 }
565 template<class Var>
566 forceinline void
568 x = y.x->copy(home);
569 }
570 template<class Var>
573 return this->varimp() < y.varimp();
574 }
575
576
577 /*
578 * Derived view: contain the base view from which they are derived
579 *
580 */
581
582 template<class View>
585
586 template<class View>
589 : x(y) {}
590
591 template<class View>
592 forceinline bool
594 return View::varderived();
595 }
596
597 template<class View>
598 forceinline typename View::VarImpType*
600 return x.varimp();
601 }
602
603 template<class View>
604 forceinline View
606 return x;
607 }
608
609 template<class View>
610 forceinline unsigned int
612 return x.degree();
613 }
614 template<class View>
615 forceinline double
617 return x.afc();
618 }
619#ifdef GECODE_HAS_CBS
620 template<class View>
621 forceinline unsigned int
622 DerivedView<View>::id(void) const {
623 return x.id();
624 }
625#endif
626 template<class View>
627 forceinline bool
629 return x.assigned();
630 }
631
632 template<class View>
633 forceinline void
635 return View::schedule(home,p,me);
636 }
637 template<class View>
640 return View::me(med);
641 }
642 template<class View>
645 return View::med(me);
646 }
647
648 template<class View>
649 forceinline void
651 bool schedule) {
652 x.subscribe(home,p,pc,schedule);
653 }
654 template<class View>
655 forceinline void
657 x.cancel(home,p,pc);
658 }
659 template<class View>
660 forceinline void
662 x.reschedule(home,p,pc);
663 }
664 template<class View>
665 forceinline void
667 x.subscribe(home,a,fail);
668 }
669 template<class View>
670 forceinline void
672 x.cancel(home,a,fail);
673 }
674 template<class View>
677 return View::modevent(d);
678 }
679 template<class View>
680 forceinline void
684 template<class View>
687 return base() < y.base();
688 }
689
690
691 /*
692 * Tests whether two views are the same
693 *
694 */
695
697 template<class ViewA, class ViewB>
698 forceinline bool
700 return false;
701 }
703 template<class Var, class View>
704 forceinline bool
706 return false;
707 }
709 template<class ViewA, class ViewB>
710 forceinline bool
712 return false;
713 }
715 template<class Var, class View>
716 forceinline bool
718 return false;
719 }
721 template<class Var, class View>
722 forceinline bool
724 return false;
725 }
727 template<class ViewX, class ViewY>
728 forceinline bool
730 return false;
731 }
733 template<class View, class Var>
734 forceinline bool
736 return false;
737 }
739 template<class ViewX, class ViewY>
740 forceinline bool
742 return false;
743 }
745 template<class VarX, class VarY>
746 forceinline bool
748 return x.varimp() == y.varimp();
749 }
750
752 template<class ViewA, class ViewB>
753 forceinline bool
755 return true;
756 }
758 template<class Var, class View>
759 forceinline bool
761 return true;
762 }
764 template<class ViewA, class ViewB>
765 forceinline bool
767 return true;
768 }
770 template<class Var, class View>
771 forceinline bool
773 return true;
774 }
776 template<class Var, class View>
777 forceinline bool
779 return true;
780 }
782 template<class ViewX, class ViewY>
783 forceinline bool
785 return true;
786 }
788 template<class View, class Var>
789 forceinline bool
791 return true;
792 }
794 template<class ViewX, class ViewY>
795 forceinline bool
797 return true;
798 }
800 template<class VarX, class VarY>
801 forceinline bool
803 return x.varimp() != y.varimp();
804 }
805
806
807 /*
808 * Testing whether two views share the same variable
809 *
810 */
811
812 template<class ViewA, class ViewB>
813 forceinline bool
815 return false;
816 }
817 template<class Var, class View>
818 forceinline bool
820 return false;
821 }
822 template<class ViewA, class ViewB>
823 forceinline bool
825 return false;
826 }
827 template<class View, class Var>
828 forceinline bool
830 return false;
831 }
832 template<class ViewA, class ViewB>
833 forceinline bool
835 return false;
836 }
837 template<class VarA, class VarB>
838 forceinline bool
840 return (static_cast<VarImpBase*>(x.varimp()) ==
841 static_cast<VarImpBase*>(y.varimp()));
842 }
843 template<class Var, class View>
844 forceinline bool
846 return (View::varderived() &&
847 static_cast<VarImpBase*>(x.varimp()) ==
848 static_cast<VarImpBase*>(y.varimp()));
849 }
850 template<class View, class Var>
851 forceinline bool
853 return (View::varderived() &&
854 static_cast<VarImpBase*>(x.varimp()) ==
855 static_cast<VarImpBase*>(y.varimp()));
856 }
857 template<class ViewA, class ViewB>
858 forceinline bool
860 return (ViewA::varderived() && ViewB::varderived() &&
861 static_cast<VarImpBase*>(x.varimp()) ==
862 static_cast<VarImpBase*>(y.varimp()));
863 }
864
865}
866
867// STATISTICS: kernel-var
int p
Number of positive literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Base-class for advisors.
Definition core.hpp:1292
Base-class for constant views.
Definition view.hpp:45
void cancel(Space &home, Advisor &a, bool fail=false)
Cancel subscription of advisor a.
Definition view.hpp:436
double afc(void) const
Return accumulated failure count.
Definition view.hpp:389
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors)
Definition view.hpp:384
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition view.hpp:416
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition view.hpp:427
bool operator<(const ConstView &y) const
Whether this view comes before view y (arbitray order)
Definition view.hpp:465
static ModEvent modevent(const Delta &d)
Return modification event.
Definition view.hpp:455
static ModEventDelta med(ModEvent me)
Translate modification event me to modification event delta for view.
Definition view.hpp:450
void subscribe(Space &home, Advisor &a, bool fail=false)
Subscribe advisor a to view.
Definition view.hpp:432
bool assigned(void) const
Test whether view is assigned.
Definition view.hpp:411
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition view.hpp:445
View::VarImpType VarImpType
The variable implementation type corresponding to the constant view.
Definition view.hpp:48
View::VarType VarType
The variable type corresponding to the constant view.
Definition view.hpp:50
static bool varderived(void)
Return whether this view is derived from a VarImpView.
Definition view.hpp:394
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition view.hpp:423
void update(Space &home, ConstView &y)
Update this view to be a clone of view y.
Definition view.hpp:461
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition view.hpp:440
VarImpType * varimp(void) const
Return dummy variable implementation of view.
Definition view.hpp:399
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Base-class for derived views.
Definition view.hpp:230
View base(void) const
Return view from which this view is derived.
Definition view.hpp:605
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition view.hpp:661
static ModEvent modevent(const Delta &d)
Return modification event.
Definition view.hpp:676
void subscribe(Space &home, Advisor &a, bool fail=false)
Subscribe advisor a to view.
Definition view.hpp:666
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition view.hpp:650
View x
View from which this view is derived.
Definition view.hpp:238
bool operator<(const DerivedView< View > &y) const
Whether this view comes before view y (arbitray order)
Definition view.hpp:686
void cancel(Space &home, Advisor &a, bool fail=false)
Cancel subscription of advisor a.
Definition view.hpp:671
static bool varderived(void)
Return whether this view is derived from a VarImpView.
Definition view.hpp:593
DerivedView(void)
Default constructor.
Definition view.hpp:584
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition view.hpp:639
bool assigned(void) const
Test whether view is assigned.
Definition view.hpp:628
View::VarType VarType
The variable type belonging to the View.
Definition view.hpp:235
VarImpType * varimp(void) const
Return variable implementation of view.
Definition view.hpp:599
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition view.hpp:634
View::VarImpType VarImpType
The variable implementation type belonging to the View.
Definition view.hpp:233
unsigned int degree(void) const
Return degree (number of subscribed propagators)
Definition view.hpp:611
void update(Space &home, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition view.hpp:681
double afc(void) const
Return accumulated failure count.
Definition view.hpp:616
DerivedView(const View &y)
Initialize with view y.
Definition view.hpp:588
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition view.hpp:656
static ModEventDelta med(ModEvent)
Translate modification event me to modification event delta for view.
Definition view.hpp:644
Float variable implementation.
Definition var-imp.hpp:76
Base-class for propagators.
Definition core.hpp:1064
SetVarImp * copy(Space &home)
Return copy of this variable.
Definition set.hpp:424
Computation spaces.
Definition core.hpp:1742
Base-class for variable implementations.
Definition core.hpp:172
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Definition var.hpp:116
bool assigned(void) const
Test whether view is assigned.
Definition var.hpp:111
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors)
Definition var.hpp:101
VarImp * varimp(void) const
Return variable implementation of variable.
Definition var.hpp:96
VarImp * x
Pointer to variable implementation.
Definition var.hpp:50
double afc(void) const
Return accumulated failure count.
Definition var.hpp:106
Base-class for variable implementation views.
Definition view.hpp:133
void cancel(Space &home, Advisor &a, bool fail=false)
Cancel subscription of advisor a.
Definition view.hpp:542
void update(Space &home, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition view.hpp:567
static ModEventDelta med(ModEvent me)
Translate modification event me to modification event delta for view.
Definition view.hpp:557
bool operator<(const VarImpView &y) const
Whether this view comes before view y (arbitray order)
Definition view.hpp:572
VarImpType * varimp(void) const
Return variable implementation of view.
Definition view.hpp:494
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors)
Definition view.hpp:499
void subscribe(Space &home, Advisor &a, bool fail=false)
Subscribe advisor a to view.
Definition view.hpp:537
VarImpView(VarImpType *y)
Initialize with variable implementation y.
Definition view.hpp:480
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition view.hpp:552
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition view.hpp:547
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition view.hpp:527
static bool varderived(void)
Return whether this view is derived from a VarImpView.
Definition view.hpp:489
VarImpView(void)
Default constructor.
Definition view.hpp:476
Var VarType
The variable type corresponding to the view.
Definition view.hpp:136
double afc(void) const
Return accumulated failure count.
Definition view.hpp:504
Var::VarImpType VarImpType
The variable implementation type corresponding to the view.
Definition view.hpp:138
static ModEvent modevent(const Delta &d)
Return modification event.
Definition view.hpp:562
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition view.hpp:532
bool assigned(void) const
Test whether view is assigned.
Definition view.hpp:516
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition view.hpp:521
void varimp(VarImpType *y)
Set variable implementation to y.
Definition view.hpp:484
VarImpType * x
Pointer to variable implementation.
Definition view.hpp:141
Base class for variables.
Definition var.hpp:40
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:767
const ModEvent ME_GEN_NONE
Generic modification event: no modification.
Definition core.hpp:67
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1466
int PropCond
Type for propagation conditions.
Definition core.hpp:72
const ModEvent ME_GEN_ASSIGNED
Generic modification event: variable is assigned a value.
Definition core.hpp:69
Post propagator for SetVar x
Definition set.hh:767
bool operator==(const FloatVal &x, const FloatVal &y)
Definition val.hpp:294
bool operator!=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:317
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:187