gecode » set » rel

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 * 00007 * Copyright: 00008 * Guido Tack, 2004 00009 * Christian Schulte, 2004 00010 * 00011 * Last modified: 00012 * $Date: 2009-10-14 12:19:49 +0200 (Wed, 14 Oct 2009) $ by $Author: schulte $ 00013 * $Revision: 9909 $ 00014 * 00015 * This file is part of Gecode, the generic constraint 00016 * development environment: 00017 * http://www.gecode.org 00018 * 00019 * Permission is hereby granted, free of charge, to any person obtaining 00020 * a copy of this software and associated documentation files (the 00021 * "Software"), to deal in the Software without restriction, including 00022 * without limitation the rights to use, copy, modify, merge, publish, 00023 * distribute, sublicense, and/or sell copies of the Software, and to 00024 * permit persons to whom the Software is furnished to do so, subject to 00025 * the following conditions: 00026 * 00027 * The above copyright notice and this permission notice shall be 00028 * included in all copies or substantial portions of the Software. 00029 * 00030 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00031 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00032 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00033 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00034 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00035 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00036 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00037 * 00038 */ 00039 00040 namespace Gecode { namespace Set { namespace Rel { 00041 00042 template<class View0, class View1> 00043 forceinline 00044 ReSubset<View0,View1>::ReSubset(Home home, View0 y0, 00045 View1 y1, Gecode::Int::BoolView y2) 00046 : Propagator(home), x0(y0), x1(y1), b(y2) { 00047 b.subscribe(home,*this, Gecode::Int::PC_INT_VAL); 00048 x0.subscribe(home,*this, PC_SET_ANY); 00049 x1.subscribe(home,*this, PC_SET_ANY); 00050 } 00051 00052 template<class View0, class View1> 00053 forceinline 00054 ReSubset<View0,View1>::ReSubset(Space& home, bool share, ReSubset& p) 00055 : Propagator(home,share,p) { 00056 x0.update(home,share,p.x0); 00057 x1.update(home,share,p.x1); 00058 b.update(home,share,p.b); 00059 } 00060 00061 template<class View0, class View1> 00062 PropCost 00063 ReSubset<View0,View1>::cost(const Space&, const ModEventDelta&) const { 00064 return PropCost::ternary(PropCost::LO); 00065 } 00066 00067 template<class View0, class View1> 00068 size_t 00069 ReSubset<View0,View1>::dispose(Space& home) { 00070 assert(!home.failed()); 00071 b.cancel(home,*this, Gecode::Int::PC_INT_VAL); 00072 x0.cancel(home,*this, PC_SET_ANY); 00073 x1.cancel(home,*this, PC_SET_ANY); 00074 (void) Propagator::dispose(home); 00075 return sizeof(*this); 00076 } 00077 00078 template<class View0, class View1> 00079 ExecStatus 00080 ReSubset<View0,View1>::post(Home home, View0 x0, View1 x1, 00081 Gecode::Int::BoolView b) { 00082 (void) new (home) ReSubset<View0,View1>(home,x0,x1,b); 00083 return ES_OK; 00084 } 00085 00086 template<class View0, class View1> 00087 Actor* 00088 ReSubset<View0,View1>::copy(Space& home, bool share) { 00089 return new (home) ReSubset<View0,View1>(home,share,*this); 00090 } 00091 00092 template<class View0, class View1> 00093 ExecStatus 00094 ReSubset<View0,View1>::propagate(Space& home, const ModEventDelta&) { 00095 if (b.one()) 00096 GECODE_REWRITE(*this,(Subset<View0,View1>::post(home(*this),x0,x1))); 00097 if (b.zero()) 00098 GECODE_REWRITE(*this,(NoSubset<View0,View1>::post(home(*this),x0,x1))); 00099 00100 // check whether cardinalities still allow subset 00101 if (x0.cardMin() > x1.cardMax()) { 00102 GECODE_ME_CHECK(b.zero_none(home)); 00103 return ES_SUBSUMED(*this,home); 00104 } 00105 00106 // check lub(x0) subset glb(x1) 00107 { 00108 LubRanges<View0> x0ub(x0); 00109 GlbRanges<View1> x1lb(x1); 00110 Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> > d(x0ub,x1lb); 00111 if (!d()) { 00112 GECODE_ME_CHECK(b.one_none(home)); 00113 return ES_SUBSUMED(*this,home); 00114 } 00115 } 00116 00117 // check glb(x0) subset lub(x1) 00118 { 00119 GlbRanges<View0> x0lb(x0); 00120 LubRanges<View1> x1ub(x1); 00121 Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View1> > d(x0lb,x1ub); 00122 if (d()) { 00123 GECODE_ME_CHECK(b.zero_none(home)); 00124 return ES_SUBSUMED(*this,home); 00125 } else if (x0.assigned() && x1.assigned()) { 00126 GECODE_ME_CHECK(b.one_none(home)); 00127 return ES_SUBSUMED(*this,home); 00128 } 00129 } 00130 00131 if (x0.cardMin() > 0) { 00132 LubRanges<View0> x0ub(x0); 00133 LubRanges<View1> x1ub(x1); 00134 Iter::Ranges::Inter<LubRanges<View0>,LubRanges<View1> > 00135 i(x0ub,x1ub); 00136 if (!i()) { 00137 GECODE_ME_CHECK(b.zero_none(home)); 00138 return ES_SUBSUMED(*this,home); 00139 } 00140 } 00141 00142 return ES_FIX; 00143 } 00144 00145 }}} 00146 00147 // STATISTICS: set-prop