pair.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
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
00148