Generated on Fri Oct 19 11:25:05 2018 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/int/element.hh>
00035 
00036 namespace Gecode { namespace Int { namespace Element {
00037 
00038   Actor*
00039   Pair::copy(Space& home) {
00040     return new (home) Pair(home,*this);
00041   }
00042 
00044   class PairValues {
00045   private:
00047     IntView x;
00049     ViewValues<IntView> xv;
00051     ViewValues<IntView> yv;
00053     int w;
00054   public:
00056 
00057 
00058     PairValues(IntView x, IntView y, int w);
00060 
00062 
00063 
00064     bool operator ()(void) const;
00066     void operator ++(void);
00068 
00070 
00071 
00072     int val(void) const;
00074   };
00075 
00076   forceinline
00077   PairValues::PairValues(IntView x0, IntView y0, int w0)
00078     : x(x0), xv(x0), yv(y0), w(w0) {}
00079   forceinline void
00080   PairValues::operator ++(void) {
00081     ++xv;
00082     if (!xv()) {
00083       xv.init(x); ++yv;
00084     }
00085   }
00086   forceinline bool
00087   PairValues::operator ()(void) const {
00088     return yv();
00089   }
00090   forceinline int
00091   PairValues::val(void) const {
00092     return xv.val()+w*yv.val();
00093   }
00094 
00095 
00096   ExecStatus
00097   Pair::propagate(Space& home, const ModEventDelta&) {
00098     Region r;
00099 
00100     if (x0.assigned()) {
00101       // Bitset for supported div and mod values
00102       Support::BitSet<Region> d(r,static_cast<unsigned int>((x2.max() / w)+1));
00103       for (ViewValues<IntView> i(x2); i(); ++i) {
00104         d.set(static_cast<unsigned int>(i.val() / w));
00105       }
00106       Iter::Values::BitSet<Support::BitSet<Region> > id(d,x1.min(),x1.max());
00107       GECODE_ME_CHECK(x1.inter_v(home,id,false));
00108     } else {
00109       // Bitset for supported div and mod values
00110       Support::BitSet<Region>
00111         d(r,static_cast<unsigned int>((x2.max() / w)+1)),
00112         m(r,static_cast<unsigned int>(w));
00113       for (ViewValues<IntView> i(x2); i(); ++i) {
00114         d.set(static_cast<unsigned int>(i.val() / w));
00115         m.set(static_cast<unsigned int>(i.val() % w));
00116       }
00117       Iter::Values::BitSet<Support::BitSet<Region> > im(m,x0.min(),x0.max());
00118       GECODE_ME_CHECK(x0.inter_v(home,im,false));
00119       Iter::Values::BitSet<Support::BitSet<Region> > id(d,x1.min(),x1.max());
00120       GECODE_ME_CHECK(x1.inter_v(home,id,false));
00121     }
00122 
00123     if (x0.assigned() && x1.assigned()) {
00124       GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val()));
00125       return home.ES_SUBSUMED(*this);
00126     } else if (x1.assigned()) {
00127       OffsetView x0x1w(x0,x1.val()*w);
00128       GECODE_REWRITE(*this,(Rel::EqDom<OffsetView,IntView>
00129                             ::post(home(*this),x0x1w,x2)));
00130     }
00131 
00132     PairValues xy(x0,x1,w);
00133     GECODE_ME_CHECK(x2.inter_v(home,xy,false));
00134 
00135     if (x2.assigned()) {
00136       GECODE_ME_CHECK(x0.eq(home,x2.val() % w));
00137       GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w)));
00138       return home.ES_SUBSUMED(*this);
00139     }
00140 
00141     return ES_NOFIX;
00142   }
00143 
00144 }}}
00145 
00146 // STATISTICS: int-prop
00147