~ubuntu-branches/debian/stretch/gecode/stretch

« back to all changes in this revision

Viewing changes to gecode/int/linear/bool-int.hpp

  • Committer: Package Import Robot
  • Author(s): Kari Pahula
  • Date: 2013-05-25 15:57:32 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20130525155732-bltd8lu9my9borhk
Tags: 4.0.0-2
Give make check LD_LIBRARY_PATH=. to make test work without gecode
already installed, to fix FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 *     Tias Guns, 2009
10
10
 *
11
11
 *  Last modified:
12
 
 *     $Date: 2010-04-08 20:35:31 +1000 (Thu, 08 Apr 2010) $ by $Author: schulte $
13
 
 *     $Revision: 10684 $
 
12
 *     $Date: 2012-10-18 16:02:42 +0200 (Thu, 18 Oct 2012) $ by $Author: schulte $
 
13
 *     $Revision: 13154 $
14
14
 *
15
15
 *  This file is part of Gecode, the generic constraint
16
16
 *  development environment:
552
552
   * Reified greater or equal propagator (integer rhs)
553
553
   * 
554
554
   */
555
 
  template<class VX, class VB>
 
555
  template<class VX, class VB, ReifyMode rm>
556
556
  forceinline
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) {}
559
559
 
560
 
  template<class VX, class VB>
 
560
  template<class VX, class VB, ReifyMode rm>
561
561
  forceinline
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) {}
565
565
 
566
 
  template<class VX, class VB>
 
566
  template<class VX, class VB, ReifyMode rm>
567
567
  Actor*
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);
570
570
  }
571
571
 
572
 
  template<class VX, class VB>
 
572
  template<class VX, class VB, ReifyMode rm>
573
573
  ExecStatus
574
 
  ReGqBoolInt<VX,VB>::advise(Space&, Advisor&, const Delta& d) {
 
574
  ReGqBoolInt<VX,VB,rm>::advise(Space&, Advisor&, const Delta& d) {
575
575
    if (VX::one(d))
576
576
      c--;
577
577
    n_s--;
581
581
      return ES_FIX;
582
582
  }
583
583
 
584
 
  template<class VX, class VB>
 
584
  template<class VX, class VB, ReifyMode rm>
585
585
  ExecStatus
586
 
  ReGqBoolInt<VX,VB>::propagate(Space& home, const ModEventDelta&) {
 
586
  ReGqBoolInt<VX,VB,rm>::propagate(Space& home, const ModEventDelta&) {
587
587
    if (b.none()) {
588
588
      if (c <= 0) {
589
 
        GECODE_ME_CHECK(b.one_none(home));
 
589
        if (rm != RM_IMP)
 
590
          GECODE_ME_CHECK(b.one_none(home));
590
591
      } else {
591
 
        GECODE_ME_CHECK(b.zero_none(home));
 
592
        if (rm != RM_PMI)
 
593
          GECODE_ME_CHECK(b.zero_none(home));
592
594
      }
593
595
    } else {
594
596
      normalize();
595
597
      if (b.one()) {
596
 
        GECODE_REWRITE(*this,(GqBoolInt<VX>::post(home(*this),x,c)));
 
598
        if (rm != RM_PMI)
 
599
          GECODE_REWRITE(*this,(GqBoolInt<VX>::post(home(*this),x,c)));
597
600
      } else {
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));
 
601
        if (rm != RM_IMP) {
 
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));
 
607
        }
603
608
      }
604
609
    }
605
610
    return home.ES_SUBSUMED(*this);
606
611
  }
607
612
 
608
 
  template<class VX, class VB>
 
613
  template<class VX, class VB, ReifyMode rm>
609
614
  ExecStatus
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
612
617
 
613
618
    // Eliminate assigned views
621
626
    x.size(n_x);
622
627
    if (n_x < c) {
623
628
      // RHS too large
624
 
      GECODE_ME_CHECK(b.zero_none(home));
 
629
      if (rm != RM_PMI)
 
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));
628
 
    } else if (c == 1) {
 
633
      if (rm != RM_IMP)
 
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));
640
647
    } else {
641
 
      (void) new (home) ReGqBoolInt<VX,VB>(home,x,c,b);
 
648
      (void) new (home) ReGqBoolInt<VX,VB,rm>(home,x,c,b);
642
649
    }
643
650
    return ES_OK;
644
651
  }
647
654
   * Reified equal propagator (integer rhs)
648
655
   * 
649
656
   */
650
 
  template<class VX, class VB>
 
657
  template<class VX, class VB, ReifyMode rm>
651
658
  forceinline
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) {}
654
661
 
655
 
  template<class VX, class VB>
 
662
  template<class VX, class VB, ReifyMode rm>
656
663
  forceinline
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) {}
660
667
 
661
 
  template<class VX, class VB>
 
668
  template<class VX, class VB, ReifyMode rm>
662
669
  Actor*
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);
665
672
  }
666
673
 
667
 
  template<class VX, class VB>
 
674
  template<class VX, class VB, ReifyMode rm>
668
675
  ExecStatus
669
 
  ReEqBoolInt<VX,VB>::advise(Space&, Advisor&, const Delta& d) {
 
676
  ReEqBoolInt<VX,VB,rm>::advise(Space&, Advisor&, const Delta& d) {
670
677
    if (VX::one(d))
671
678
      c--;
672
679
    n_s--;
677
684
      return ES_FIX;
678
685
  }
679
686
 
680
 
  template<class VX, class VB>
 
687
  template<class VX, class VB, ReifyMode rm>
681
688
  ExecStatus
682
 
  ReEqBoolInt<VX,VB>::propagate(Space& home, const ModEventDelta&) {
 
689
  ReEqBoolInt<VX,VB,rm>::propagate(Space& home, const ModEventDelta&) {
683
690
    if (b.none()) {
684
691
      if ((c == 0) && (n_s == 0)) {
685
 
        GECODE_ME_CHECK(b.one_none(home));
 
692
        if (rm != RM_IMP)
 
693
          GECODE_ME_CHECK(b.one_none(home));
686
694
      } else {
687
 
        GECODE_ME_CHECK(b.zero_none(home));
 
695
        if (rm != RM_PMI)
 
696
          GECODE_ME_CHECK(b.zero_none(home));
688
697
      }
689
698
    } else {
690
699
      normalize();
691
700
      if (b.one()) {
692
 
        GECODE_REWRITE(*this,(EqBoolInt<VX>::post(home(*this),x,c)));
 
701
        if (rm != RM_PMI)
 
702
          GECODE_REWRITE(*this,(EqBoolInt<VX>::post(home(*this),x,c)));
693
703
      } else {
694
 
        GECODE_REWRITE(*this,(NqBoolInt<VX>::post(home(*this),x,c)));
 
704
        if (rm != RM_IMP)
 
705
          GECODE_REWRITE(*this,(NqBoolInt<VX>::post(home(*this),x,c)));
695
706
      }
696
707
    }
697
708
    return home.ES_SUBSUMED(*this);
698
709
  }
699
710
 
700
 
  template<class VX, class VB>
 
711
  template<class VX, class VB, ReifyMode rm>
701
712
  ExecStatus
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
704
715
 
705
716
    // Eliminate assigned views
713
724
    x.size(n_x);
714
725
    if ((n_x < c) || (c < 0)) {
715
726
      // RHS too large
716
 
      GECODE_ME_CHECK(b.zero_none(home));
 
727
      if (rm != RM_PMI)
 
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));
720
 
    } else if (c == 0) {
 
731
      if (rm != RM_IMP)
 
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));
733
746
    } else {
734
 
      (void) new (home) ReEqBoolInt<VX,VB>(home,x,c,b);
 
747
      (void) new (home) ReEqBoolInt<VX,VB,rm>(home,x,c,b);
735
748
    }
736
749
    return ES_OK;
737
750
  }