552
552
* Reified greater or equal propagator (integer rhs)
555
template<class VX, class VB>
555
template<class VX, class VB, ReifyMode rm>
557
ReGqBoolInt<VX,VB>::ReGqBoolInt(Home home, ViewArray<VX>& x, int c, VB b)
557
ReGqBoolInt<VX,VB,rm>::ReGqBoolInt(Home home, ViewArray<VX>& x, int c, VB b)
558
558
: ReLinBoolInt<VX,VB>(home,x,c,b) {}
560
template<class VX, class VB>
560
template<class VX, class VB, ReifyMode rm>
562
ReGqBoolInt<VX,VB>::ReGqBoolInt(Space& home, bool share,
563
ReGqBoolInt<VX,VB>& p)
562
ReGqBoolInt<VX,VB,rm>::ReGqBoolInt(Space& home, bool share,
563
ReGqBoolInt<VX,VB,rm>& p)
564
564
: ReLinBoolInt<VX,VB>(home,share,p) {}
566
template<class VX, class VB>
566
template<class VX, class VB, ReifyMode rm>
568
ReGqBoolInt<VX,VB>::copy(Space& home, bool share) {
569
return new (home) ReGqBoolInt<VX,VB>(home,share,*this);
568
ReGqBoolInt<VX,VB,rm>::copy(Space& home, bool share) {
569
return new (home) ReGqBoolInt<VX,VB,rm>(home,share,*this);
572
template<class VX, class VB>
572
template<class VX, class VB, ReifyMode rm>
574
ReGqBoolInt<VX,VB>::advise(Space&, Advisor&, const Delta& d) {
574
ReGqBoolInt<VX,VB,rm>::advise(Space&, Advisor&, const Delta& d) {
584
template<class VX, class VB>
584
template<class VX, class VB, ReifyMode rm>
586
ReGqBoolInt<VX,VB>::propagate(Space& home, const ModEventDelta&) {
586
ReGqBoolInt<VX,VB,rm>::propagate(Space& home, const ModEventDelta&) {
589
GECODE_ME_CHECK(b.one_none(home));
590
GECODE_ME_CHECK(b.one_none(home));
591
GECODE_ME_CHECK(b.zero_none(home));
593
GECODE_ME_CHECK(b.zero_none(home));
596
GECODE_REWRITE(*this,(GqBoolInt<VX>::post(home(*this),x,c)));
599
GECODE_REWRITE(*this,(GqBoolInt<VX>::post(home(*this),x,c)));
598
ViewArray<typename BoolNegTraits<VX>::NegView> nx(home,x.size());
599
for (int i=x.size(); i--; )
600
nx[i]=BoolNegTraits<VX>::neg(x[i]);
601
GECODE_REWRITE(*this,GqBoolInt<typename BoolNegTraits<VX>::NegView>
602
::post(home(*this),nx,x.size()-c+1));
602
ViewArray<typename BoolNegTraits<VX>::NegView> nx(home,x.size());
603
for (int i=x.size(); i--; )
604
nx[i]=BoolNegTraits<VX>::neg(x[i]);
605
GECODE_REWRITE(*this,GqBoolInt<typename BoolNegTraits<VX>::NegView>
606
::post(home(*this),nx,x.size()-c+1));
605
610
return home.ES_SUBSUMED(*this);
608
template<class VX, class VB>
613
template<class VX, class VB, ReifyMode rm>
610
ReGqBoolInt<VX,VB>::post(Home home, ViewArray<VX>& x, int c, VB b) {
615
ReGqBoolInt<VX,VB,rm>::post(Home home, ViewArray<VX>& x, int c, VB b) {
611
616
assert(!b.assigned()); // checked before posting
613
618
// Eliminate assigned views
624
GECODE_ME_CHECK(b.zero_none(home));
630
GECODE_ME_CHECK(b.zero_none(home));
625
631
} else if (c <= 0) {
626
632
// Whatever the x[i] take for values, the inequality is subsumed
627
GECODE_ME_CHECK(b.one_none(home));
634
GECODE_ME_CHECK(b.one_none(home));
635
} else if ((c == 1) && (rm == RM_EQV)) {
629
636
// Equivalent to Boolean disjunction
630
637
return Bool::NaryOr<VX,VB>::post(home,x,b);
631
} else if (c == n_x) {
638
} else if ((c == n_x) && (rm == RM_EQV)) {
632
639
// Equivalent to Boolean conjunction, transform to Boolean disjunction
633
640
ViewArray<typename BoolNegTraits<VX>::NegView> nx(home,n_x);
634
641
for (int i=n_x; i--; )
638
645
typename BoolNegTraits<VB>::NegView>
639
646
::post(home,nx,BoolNegTraits<VB>::neg(b));
641
(void) new (home) ReGqBoolInt<VX,VB>(home,x,c,b);
648
(void) new (home) ReGqBoolInt<VX,VB,rm>(home,x,c,b);
647
654
* Reified equal propagator (integer rhs)
650
template<class VX, class VB>
657
template<class VX, class VB, ReifyMode rm>
652
ReEqBoolInt<VX,VB>::ReEqBoolInt(Home home, ViewArray<VX>& x, int c, VB b)
659
ReEqBoolInt<VX,VB,rm>::ReEqBoolInt(Home home, ViewArray<VX>& x, int c, VB b)
653
660
: ReLinBoolInt<VX,VB>(home,x,c,b) {}
655
template<class VX, class VB>
662
template<class VX, class VB, ReifyMode rm>
657
ReEqBoolInt<VX,VB>::ReEqBoolInt(Space& home, bool share,
658
ReEqBoolInt<VX,VB>& p)
664
ReEqBoolInt<VX,VB,rm>::ReEqBoolInt(Space& home, bool share,
665
ReEqBoolInt<VX,VB,rm>& p)
659
666
: ReLinBoolInt<VX,VB>(home,share,p) {}
661
template<class VX, class VB>
668
template<class VX, class VB, ReifyMode rm>
663
ReEqBoolInt<VX,VB>::copy(Space& home, bool share) {
664
return new (home) ReEqBoolInt<VX,VB>(home,share,*this);
670
ReEqBoolInt<VX,VB,rm>::copy(Space& home, bool share) {
671
return new (home) ReEqBoolInt<VX,VB,rm>(home,share,*this);
667
template<class VX, class VB>
674
template<class VX, class VB, ReifyMode rm>
669
ReEqBoolInt<VX,VB>::advise(Space&, Advisor&, const Delta& d) {
676
ReEqBoolInt<VX,VB,rm>::advise(Space&, Advisor&, const Delta& d) {
680
template<class VX, class VB>
687
template<class VX, class VB, ReifyMode rm>
682
ReEqBoolInt<VX,VB>::propagate(Space& home, const ModEventDelta&) {
689
ReEqBoolInt<VX,VB,rm>::propagate(Space& home, const ModEventDelta&) {
684
691
if ((c == 0) && (n_s == 0)) {
685
GECODE_ME_CHECK(b.one_none(home));
693
GECODE_ME_CHECK(b.one_none(home));
687
GECODE_ME_CHECK(b.zero_none(home));
696
GECODE_ME_CHECK(b.zero_none(home));
692
GECODE_REWRITE(*this,(EqBoolInt<VX>::post(home(*this),x,c)));
702
GECODE_REWRITE(*this,(EqBoolInt<VX>::post(home(*this),x,c)));
694
GECODE_REWRITE(*this,(NqBoolInt<VX>::post(home(*this),x,c)));
705
GECODE_REWRITE(*this,(NqBoolInt<VX>::post(home(*this),x,c)));
697
708
return home.ES_SUBSUMED(*this);
700
template<class VX, class VB>
711
template<class VX, class VB, ReifyMode rm>
702
ReEqBoolInt<VX,VB>::post(Home home, ViewArray<VX>& x, int c, VB b) {
713
ReEqBoolInt<VX,VB,rm>::post(Home home, ViewArray<VX>& x, int c, VB b) {
703
714
assert(!b.assigned()); // checked before posting
705
716
// Eliminate assigned views
714
725
if ((n_x < c) || (c < 0)) {
716
GECODE_ME_CHECK(b.zero_none(home));
728
GECODE_ME_CHECK(b.zero_none(home));
717
729
} else if ((c == 0) && (n_x == 0)) {
718
730
// all variables set, and c == 0: equality
719
GECODE_ME_CHECK(b.one_none(home));
732
GECODE_ME_CHECK(b.one_none(home));
733
} else if ((c == 0) && (rm == RM_EQV)) {
721
734
// Equivalent to Boolean disjunction
722
735
return Bool::NaryOr<VX,typename BoolNegTraits<VB>::NegView>
723
736
::post(home,x,BoolNegTraits<VB>::neg(b));
724
} else if (c == n_x) {
737
} else if ((c == n_x) && (rm == RM_EQV)) {
725
738
// Equivalent to Boolean conjunction, transform to Boolean disjunction
726
739
ViewArray<typename BoolNegTraits<VX>::NegView> nx(home,n_x);
727
740
for (int i=n_x; i--; )
731
744
typename BoolNegTraits<VB>::NegView>
732
745
::post(home,nx,BoolNegTraits<VB>::neg(b));
734
(void) new (home) ReEqBoolInt<VX,VB>(home,x,c,b);
747
(void) new (home) ReEqBoolInt<VX,VB,rm>(home,x,c,b);