Generated on Mon Aug 25 11:35:35 2008 for Gecode by doxygen 1.5.6

lq.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 6017 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Int { namespace Bool {
00039 
00040   /*
00041    * Less or equal propagator
00042    *
00043    */
00044 
00045   template<class BV>
00046   forceinline
00047   Lq<BV>::Lq(Space* home, BV b0, BV b1)
00048     : BoolBinary<BV,BV>(home,b0,b1) {}
00049 
00050   template<class BV>
00051   forceinline
00052   Lq<BV>::Lq(Space* home, bool share, Lq<BV>& p)
00053     : BoolBinary<BV,BV>(home,share,p) {}
00054 
00055   template<class BV>
00056   Actor*
00057   Lq<BV>::copy(Space* home, bool share) {
00058     return new (home) Lq<BV>(home,share,*this);
00059   }
00060 
00061   template<class BV>
00062   inline ExecStatus
00063   Lq<BV>::post(Space* home, BV b0, BV b1) {
00064     if (b0.zero()) {
00065       return ES_OK;
00066     } else if (b0.one()) {
00067       GECODE_ME_CHECK(b1.one(home));
00068     } else if (b1.zero()) {
00069       GECODE_ME_CHECK(b0.zero(home));
00070     } else if (b1.one()) {
00071       return ES_OK;
00072     } else {
00073       (void) new (home) Lq<BV>(home,b0,b1);
00074     }
00075     return ES_OK;
00076   }
00077 
00078   template<class BV>
00079   ExecStatus
00080   Lq<BV>::propagate(Space* home, ModEventDelta) {
00081 #define GECODE_INT_STATUS(S0,S1) \
00082   ((BV::S0<<(1*BV::BITS))|(BV::S1<<(0*BV::BITS)))
00083     switch ((x0.status()<<(1*BV::BITS)) | (x1.status()<<(0*BV::BITS))) {
00084     case GECODE_INT_STATUS(NONE,NONE):
00085       GECODE_NEVER;
00086     case GECODE_INT_STATUS(NONE,ZERO):
00087       GECODE_ME_CHECK(x0.zero_none(home)); break;
00088     case GECODE_INT_STATUS(NONE,ONE):
00089       x0.cancel(home,this,PC_BOOL_VAL); break;
00090     case GECODE_INT_STATUS(ZERO,NONE):
00091       x1.cancel(home,this,PC_BOOL_VAL); break;
00092     case GECODE_INT_STATUS(ZERO,ZERO):
00093       break;
00094     case GECODE_INT_STATUS(ZERO,ONE):
00095       break;
00096     case GECODE_INT_STATUS(ONE,NONE):
00097       GECODE_ME_CHECK(x1.one_none(home)); break;
00098     case GECODE_INT_STATUS(ONE,ZERO):
00099       return ES_FAILED;
00100     case GECODE_INT_STATUS(ONE,ONE):
00101       break;
00102     default:
00103       GECODE_NEVER;
00104     }
00105     return ES_SUBSUMED(this,sizeof(*this));
00106 #undef GECODE_INT_STATUS
00107   }
00108 
00109   template<class BV>
00110   inline Support::Symbol
00111   Lq<BV>::ati(void) {
00112     return Reflection::mangle<BV>("Gecode::Int::Bool::Lq");
00113   }
00114 
00115   template<class BV>
00116   Reflection::ActorSpec
00117   Lq<BV>::spec(const Space* home, Reflection::VarMap& m) const {
00118     return BoolBinary<BV,BV>::spec(home, m, ati());
00119   }
00120 
00121   template<class BV>
00122   void
00123   Lq<BV>::post(Space* home, Reflection::VarMap& vars,
00124                const Reflection::ActorSpec& spec) {
00125     spec.checkArity(2);
00126     BV b0(home, vars, spec[0]);
00127     BV b1(home, vars, spec[1]);
00128     (void) new (home) Lq<BV>(home,b0,b1);
00129   }
00130 
00131   /*
00132    * Less posting
00133    *
00134    */
00135 
00136   template<class BV>
00137   forceinline ExecStatus
00138   Le<BV>::post(Space* home, BV b0, BV b1) {
00139     GECODE_ME_CHECK(b0.zero(home));
00140     GECODE_ME_CHECK(b1.one(home));
00141     return ES_OK;
00142   }
00143 
00144 }}}
00145 
00146 // STATISTICS: int-prop
00147