Generated on Thu Jul 6 07:06:41 2006 for Gecode by doxygen 1.4.7

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: 2005-11-04 21:37:34 +0100 (Fri, 04 Nov 2005) $ by $Author: schulte $
00010  *     $Revision: 2504 $
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   forceinline 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     }
00068     return ES_OK;
00069   }
00070 
00071   template <class BVA, class BVB, class BVC>
00072   Actor*
00073   Eqv<BVA,BVB,BVC>::copy(Space* home, bool share) {
00074     return new (home) Eqv<BVA,BVB,BVC>(home,share,*this);
00075   }
00076 
00077   template <class BVA, class BVB, class BVC>
00078   ExecStatus
00079   Eqv<BVA,BVB,BVC>::propagate(Space* home) {
00080     if (x0.zero()) {
00081       if (x1.zero()) {
00082         GECODE_ES_CHECK(x2.t_one(home));
00083       } else if (x1.one()) {
00084         GECODE_ES_CHECK(x2.t_zero(home));
00085       } else if (x2.zero()) {
00086         x1.t_one_none(home);
00087       } else if (x2.one()) {
00088         x1.t_zero_none(home);
00089       } else {
00090         return ES_FIX;
00091       }
00092     } else if (x0.one()) {
00093       if (x1.zero()) {
00094         GECODE_ES_CHECK(x2.t_zero(home));
00095       } else if (x1.one()) {
00096         GECODE_ES_CHECK(x2.t_one(home));
00097       } else if (x2.zero()) {
00098         x1.t_zero_none(home);
00099       } else if (x2.one()) {
00100         x1.t_one_none(home);
00101       } else {
00102         return ES_FIX;
00103       }
00104     } else if (x1.zero()) {
00105       assert(!x0.zero() && !x0.one());
00106       if (x2.zero()) {
00107         x0.t_one_none(home);
00108       } else if (x2.one()) {
00109         x0.t_zero_none(home);
00110       } else {
00111         return ES_FIX;
00112       }
00113     } else if (x1.one()) {
00114       assert(!x0.zero() && !x0.one());
00115       if (x2.zero()) {
00116         x0.t_zero_none(home);
00117       } else if (x2.one()) {
00118         x0.t_one_none(home);
00119       } else {
00120         return ES_FIX;
00121       }
00122     } else {
00123       return ES_FIX;
00124     }
00125     return ES_SUBSUMED;
00126   }
00127 
00128 }}}
00129 
00130 // STATISTICS: int-prop
00131