pair.hpp
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/rel.hh>
00035
00036 namespace Gecode { namespace Int { namespace Element {
00037
00038 forceinline
00039 Pair::Pair(Home home, IntView x0, IntView x1, IntView x2, int w0)
00040 : TernaryPropagator<IntView,PC_INT_DOM>(home,x0,x1,x2), w(w0) {}
00041
00042 inline ExecStatus
00043 Pair::post(Home home, IntView x0, IntView x1, IntView x2,
00044 int w, int h) {
00045 GECODE_ME_CHECK(x0.gq(home,0)); GECODE_ME_CHECK(x0.le(home,w));
00046 GECODE_ME_CHECK(x1.gq(home,0)); GECODE_ME_CHECK(x1.le(home,h));
00047 GECODE_ME_CHECK(x2.gq(home,0)); GECODE_ME_CHECK(x2.le(home,w*h));
00048 if (x0.assigned() && x1.assigned()) {
00049 GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val()));
00050 } else if (x1.assigned()) {
00051 OffsetView x0x1w(x0,x1.val()*w);
00052 return Rel::EqDom<OffsetView,IntView>::post(home,x0x1w,x2);
00053 } else if (x2.assigned()) {
00054 GECODE_ME_CHECK(x0.eq(home,x2.val() % w));
00055 GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w)));
00056 } else {
00057 assert(!shared(x0,x2) && !shared(x1,x2));
00058 (void) new (home) Pair(home,x0,x1,x2,w);
00059 }
00060 return ES_OK;
00061 }
00062
00063 forceinline
00064 Pair::Pair(Space& home, Pair& p)
00065 : TernaryPropagator<IntView,PC_INT_DOM>(home,p), w(p.w) {}
00066
00067 }}}
00068
00069
00070