Generated on Wed Nov 1 15:04:29 2006 for Gecode by doxygen 1.4.5

eqv.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2004
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-25 10:15:00 +0200 (Fri, 25 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3566 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode { namespace Int { namespace Bool {
00023 
00024   template <class BVA, class BVB, class BVC>
00025   forceinline
00026   Eqv<BVA,BVB,BVC>::Eqv(Space* home, BVA b0, BVB b1, BVC b2)
00027     : BoolTernary<BVA,BVB,BVC>(home,b0,b1,b2) {}
00028 
00029   template <class BVA, class BVB, class BVC>
00030   forceinline
00031   Eqv<BVA,BVB,BVC>::Eqv(Space* home, bool share, Eqv<BVA,BVB,BVC>& p)
00032     : BoolTernary<BVA,BVB,BVC>(home,share,p) {}
00033 
00034   template <class BVA, class BVB, class BVC>
00035   inline ExecStatus
00036   Eqv<BVA,BVB,BVC>::post(Space* home, BVA b0, BVB b1, BVC b2){
00037     switch (bool_test(b0,b1)) {
00038     case BT_SAME:
00039       GECODE_ME_CHECK(b2.t_one(home));
00040       break;
00041     case BT_COMP:
00042       GECODE_ME_CHECK(b2.t_zero(home));
00043       break;
00044     case BT_NONE:
00045       if (b2.one())
00046         return Eq<BVA,BVB>::post(home,b0,b1);
00047       if (b0.one()) {
00048         if (b1.one()) {
00049           GECODE_ME_CHECK(b2.t_one(home));
00050           return ES_OK;
00051         } else if (b2.zero()) {
00052           GECODE_ME_CHECK(b2.t_zero(home));
00053           return ES_OK;
00054         }
00055       }
00056       if (b0.zero()) {
00057         if (b1.one()) {
00058           GECODE_ME_CHECK(b2.t_zero(home));
00059           return ES_OK;
00060         } else if (b2.zero()) {
00061           GECODE_ME_CHECK(b2.t_one(home));
00062           return ES_OK;
00063         }
00064       }
00065       (void) new (home) Eqv(home,b0,b1,b2);
00066       break;
00067     default: GECODE_NEVER;
00068     }
00069     return ES_OK;
00070   }
00071 
00072   template <class BVA, class BVB, class BVC>
00073   Actor*
00074   Eqv<BVA,BVB,BVC>::copy(Space* home, bool share) {
00075     return new (home) Eqv<BVA,BVB,BVC>(home,share,*this);
00076   }
00077 
00078   template <class BVA, class BVB, class BVC>
00079   ExecStatus
00080   Eqv<BVA,BVB,BVC>::propagate(Space* home) {
00081     if (x0.zero()) {
00082       if (x1.zero()) {
00083         GECODE_ES_CHECK(x2.t_one(home));
00084       } else if (x1.one()) {
00085         GECODE_ES_CHECK(x2.t_zero(home));
00086       } else if (x2.zero()) {
00087         x1.t_one_none(home);
00088       } else if (x2.one()) {
00089         x1.t_zero_none(home);
00090       } else {
00091         return ES_FIX;
00092       }
00093     } else if (x0.one()) {
00094       if (x1.zero()) {
00095         GECODE_ES_CHECK(x2.t_zero(home));
00096       } else if (x1.one()) {
00097         GECODE_ES_CHECK(x2.t_one(home));
00098       } else if (x2.zero()) {
00099         x1.t_zero_none(home);
00100       } else if (x2.one()) {
00101         x1.t_one_none(home);
00102       } else {
00103         return ES_FIX;
00104       }
00105     } else if (x1.zero()) {
00106       assert(!x0.zero() && !x0.one());
00107       if (x2.zero()) {
00108         x0.t_one_none(home);
00109       } else if (x2.one()) {
00110         x0.t_zero_none(home);
00111       } else {
00112         return ES_FIX;
00113       }
00114     } else if (x1.one()) {
00115       assert(!x0.zero() && !x0.one());
00116       if (x2.zero()) {
00117         x0.t_zero_none(home);
00118       } else if (x2.one()) {
00119         x0.t_one_none(home);
00120       } else {
00121         return ES_FIX;
00122       }
00123     } else {
00124       return ES_FIX;
00125     }
00126     return ES_SUBSUMED;
00127   }
00128 
00129 }}}
00130 
00131 // STATISTICS: int-prop
00132