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 #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
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
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
00147