nosubset.hpp
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Guido Tack <tack@gecode.org> 00005 * Christian Schulte <schulte@gecode.org> 00006 * Gabor Szokoli <szokoli@gecode.org> 00007 * 00008 * Copyright: 00009 * Guido Tack, 2004 00010 * Christian Schulte, 2004 00011 * Gabor Szokoli, 2004 00012 * 00013 * Last modified: 00014 * $Date: 2010-03-03 17:32:21 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $ 00015 * $Revision: 10364 $ 00016 * 00017 * This file is part of Gecode, the generic constraint 00018 * development environment: 00019 * http://www.gecode.org 00020 * 00021 * Permission is hereby granted, free of charge, to any person obtaining 00022 * a copy of this software and associated documentation files (the 00023 * "Software"), to deal in the Software without restriction, including 00024 * without limitation the rights to use, copy, modify, merge, publish, 00025 * distribute, sublicense, and/or sell copies of the Software, and to 00026 * permit persons to whom the Software is furnished to do so, subject to 00027 * the following conditions: 00028 * 00029 * The above copyright notice and this permission notice shall be 00030 * included in all copies or substantial portions of the Software. 00031 * 00032 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00033 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00034 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00035 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00036 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00037 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00038 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00039 * 00040 */ 00041 00042 namespace Gecode { namespace Set { namespace Rel { 00043 00044 /* 00045 * "No Subset" propagator 00046 * 00047 */ 00048 00049 template<class View0, class View1> 00050 forceinline 00051 NoSubset<View0,View1>::NoSubset(Home home, View0 y0, View1 y1) 00052 : MixBinaryPropagator<View0,PC_SET_CLUB, 00053 View1,PC_SET_CGLB>(home,y0,y1) {} 00054 00055 template<class View0, class View1> 00056 forceinline 00057 NoSubset<View0,View1>::NoSubset(Space& home, bool share, 00058 NoSubset<View0,View1>& p) 00059 : MixBinaryPropagator<View0,PC_SET_CLUB, 00060 View1,PC_SET_CGLB>(home,share,p) {} 00061 00062 template<class View0, class View1> 00063 ExecStatus 00064 NoSubset<View0,View1>::post(Home home, View0 x, View1 y) { 00065 if (me_failed(x.cardMin(home,1))) 00066 return ES_FAILED; 00067 (void) new (home) NoSubset<View0,View1>(home,x,y); 00068 return ES_OK; 00069 } 00070 00071 template<class View0, class View1> 00072 Actor* 00073 NoSubset<View0,View1>::copy(Space& home, bool share) { 00074 return new (home) NoSubset<View0,View1>(home,share,*this); 00075 } 00076 00077 template<class View0, class View1> 00078 ExecStatus 00079 NoSubset<View0,View1>::propagate(Space& home, const ModEventDelta&) { 00080 GlbRanges<View0> x0lb(x0); 00081 LubRanges<View1> x1ub(x1); 00082 if (!Iter::Ranges::subset(x0lb, x1ub)) 00083 return home.ES_SUBSUMED(*this); 00084 if (x0.cardMin()>x1.cardMax()) { return home.ES_SUBSUMED(*this); } 00085 LubRanges<View0> x0ub(x0); 00086 GlbRanges<View1> x1lb(x1); 00087 Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> > 00088 breakers(x0ub,x1lb); 00089 if (!breakers()) { return ES_FAILED; } 00090 if (breakers.min() == breakers.max()) { 00091 int b1 = breakers.min(); 00092 ++breakers; 00093 if (breakers()) { return ES_FIX; } 00094 //Only one subsetness-breaker element left: 00095 GECODE_ME_CHECK( x0.include(home,b1) ); 00096 GECODE_ME_CHECK( x1.exclude(home,b1) ); 00097 return home.ES_SUBSUMED(*this); 00098 } 00099 return ES_FIX; 00100 } 00101 00102 }}} 00103 00104 // STATISTICS: set-prop