Generated on Thu Mar 22 10:39:37 2012 for Gecode by doxygen 1.6.3

pair.cpp

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, 2009
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-07-14 17:46:18 +0200 (Wed, 14 Jul 2010) $ by $Author: schulte $
00011  *     $Revision: 11192 $
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,static_cast<unsigned int>((x2.max() / w)+1));
00107       for (ViewValues<IntView> i(x2); i(); ++i) {
00108         d.set(static_cast<unsigned int>(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> 
00115         d(r,static_cast<unsigned int>((x2.max() / w)+1)), 
00116         m(r,static_cast<unsigned int>(w));
00117       for (ViewValues<IntView> i(x2); i(); ++i) {
00118         d.set(static_cast<unsigned int>(i.val() / w)); 
00119         m.set(static_cast<unsigned int>(i.val() % w));
00120       }
00121       Iter::Values::BitSet<Support::BitSet<Region> > im(m,x0.min(),x0.max());
00122       GECODE_ME_CHECK(x0.inter_v(home,im,false));
00123       Iter::Values::BitSet<Support::BitSet<Region> > id(d,x1.min(),x1.max());
00124       GECODE_ME_CHECK(x1.inter_v(home,id,false));
00125     }
00126 
00127     if (x0.assigned() && x1.assigned()) {
00128       GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val()));
00129       return home.ES_SUBSUMED(*this);
00130     } else if (x1.assigned()) {
00131       OffsetView x0x1w(x0,x1.val()*w);
00132       GECODE_REWRITE(*this,(Rel::EqDom<OffsetView,IntView>
00133                             ::post(home(*this),x0x1w,x2)));
00134     }
00135 
00136     PairValues xy(x0,x1,w);
00137     GECODE_ME_CHECK(x2.inter_v(home,xy,false));
00138 
00139     if (x2.assigned()) {
00140       GECODE_ME_CHECK(x0.eq(home,x2.val() % w));
00141       GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w)));
00142       return home.ES_SUBSUMED(*this);
00143     }
00144 
00145     return ES_NOFIX;
00146   }
00147 
00148 }}}
00149 
00150 // STATISTICS: int-prop
00151