lq.hpp
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: 2010-03-03 17:32:21 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $ 00011 * $Revision: 10364 $ 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(Home 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(Home 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, const 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 case GECODE_INT_STATUS(ZERO,NONE): 00090 case GECODE_INT_STATUS(ZERO,ZERO): 00091 case GECODE_INT_STATUS(ZERO,ONE): 00092 break; 00093 case GECODE_INT_STATUS(ONE,NONE): 00094 GECODE_ME_CHECK(x1.one_none(home)); break; 00095 case GECODE_INT_STATUS(ONE,ZERO): 00096 return ES_FAILED; 00097 case GECODE_INT_STATUS(ONE,ONE): 00098 break; 00099 default: 00100 GECODE_NEVER; 00101 } 00102 return home.ES_SUBSUMED(*this); 00103 #undef GECODE_INT_STATUS 00104 } 00105 00106 /* 00107 * Less posting 00108 * 00109 */ 00110 00111 template<class BV> 00112 forceinline ExecStatus 00113 Le<BV>::post(Home home, BV b0, BV b1) { 00114 GECODE_ME_CHECK(b0.zero(home)); 00115 GECODE_ME_CHECK(b1.one(home)); 00116 return ES_OK; 00117 } 00118 00119 }}} 00120 00121 // STATISTICS: int-prop 00122