gecode » int » element

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, 2009 00008 * 00009 * Last modified: 00010 * $Date: 2009-10-29 14:58:00 +0100 (Thu, 29 Oct 2009) $ by $Author: schulte $ 00011 * $Revision: 10000 $ 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 #include <gecode/int/element.hh> 00039 00040 namespace Gecode { namespace Int { namespace Element { 00041 00042 Actor* 00043 Pair::copy(Space& home, bool share) { 00044 return new (home) Pair(home,share,*this); 00045 } 00046 00048 class PairValues { 00049 private: 00051 IntView x; 00053 ViewValues<IntView> xv; 00055 ViewValues<IntView> yv; 00057 int w; 00058 public: 00060 00061 00062 PairValues(IntView x, IntView y, int w); 00064 00066 00067 00068 bool operator ()(void) const; 00070 void operator ++(void); 00072 00074 00075 00076 int val(void) const; 00078 }; 00079 00080 forceinline 00081 PairValues::PairValues(IntView x0, IntView y0, int w0) 00082 : x(x0), xv(x0), yv(y0), w(w0) {} 00083 forceinline void 00084 PairValues::operator ++(void) { 00085 ++xv; 00086 if (!xv()) { 00087 xv.init(x); ++yv; 00088 } 00089 } 00090 forceinline bool 00091 PairValues::operator ()(void) const { 00092 return yv(); 00093 } 00094 forceinline int 00095 PairValues::val(void) const { 00096 return xv.val()+w*yv.val(); 00097 } 00098 00099 00100 ExecStatus 00101 Pair::propagate(Space& home, const ModEventDelta&) { 00102 Region r(home); 00103 00104 if (x0.assigned()) { 00105 // Bitset for supported div and mod values 00106 Support::BitSet<Region> d(r,(x2.max() / w)+1); 00107 for (ViewValues<IntView> i(x2); i(); ++i) { 00108 d.set(i.val() / w); 00109 } 00110 Iter::Values::BitSet<Support::BitSet<Region> > id(d,x1.min(),x1.max()); 00111 GECODE_ME_CHECK(x1.inter_v(home,id,false)); 00112 } else { 00113 // Bitset for supported div and mod values 00114 Support::BitSet<Region> d(r,(x2.max() / w)+1), m(r,w); 00115 for (ViewValues<IntView> i(x2); i(); ++i) { 00116 d.set(i.val() / w); m.set(i.val() % w); 00117 } 00118 Iter::Values::BitSet<Support::BitSet<Region> > im(m,x0.min(),x0.max()); 00119 GECODE_ME_CHECK(x0.inter_v(home,im,false)); 00120 Iter::Values::BitSet<Support::BitSet<Region> > id(d,x1.min(),x1.max()); 00121 GECODE_ME_CHECK(x1.inter_v(home,id,false)); 00122 } 00123 00124 if (x0.assigned() && x1.assigned()) { 00125 GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val())); 00126 return ES_SUBSUMED(*this,sizeof(*this)); 00127 } else if (x1.assigned()) { 00128 OffsetView x0x1w(x0,x1.val()*w); 00129 GECODE_REWRITE(*this,(Rel::EqDom<OffsetView,IntView> 00130 ::post(home(*this),x0x1w,x2))); 00131 } 00132 00133 PairValues xy(x0,x1,w); 00134 GECODE_ME_CHECK(x2.inter_v(home,xy,false)); 00135 00136 if (x2.assigned()) { 00137 GECODE_ME_CHECK(x0.eq(home,x2.val() % w)); 00138 GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w))); 00139 return ES_SUBSUMED(*this,sizeof(*this)); 00140 } 00141 00142 return ES_NOFIX; 00143 } 00144 00145 }}} 00146 00147 // STATISTICS: int-prop 00148