/* * Main authors: * Christian Schulte * Gabor Szokoli * * Copyright: * Christian Schulte, 2003 * Gabor Szokoli, 2003 * * Last modified: * $Date: 2006-08-04 16:03:26 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $ * $Revision: 3512 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * See the file "LICENSE" for information on usage and * redistribution of this file, and for a * DISCLAIMER OF ALL WARRANTIES. * */ namespace Gecode { namespace Int { namespace Rel { /* * Less or equal propagator * */ template forceinline Lq::Lq(Space* home, View x0, View x1) : BinaryPropagator(home,x0,x1) {} template ExecStatus Lq::post(Space* home, View x0, View x1) { GECODE_ME_CHECK(x0.lq(home,x1.max())); GECODE_ME_CHECK(x1.gq(home,x0.min())); if (!same(x0,x1) && (x0.max() > x1.min())) (void) new (home) Lq(home,x0,x1); return ES_OK; } template forceinline Lq::Lq(Space* home, bool share, Lq& p) : BinaryPropagator(home,share,p) {} template Actor* Lq::copy(Space* home, bool share) { return new (home) Lq(home,share,*this); } template ExecStatus Lq::propagate(Space* home) { GECODE_ME_CHECK(x0.lq(home,x1.max())); GECODE_ME_CHECK(x1.gq(home,x0.min())); return (x0.max() <= x1.min()) ? ES_SUBSUMED : ES_FIX; } /* * Less propagator * */ template forceinline Le::Le(Space* home, View x0, View x1) : BinaryPropagator(home,x0,x1) {} template ExecStatus Le::post(Space* home, View x0, View x1) { if (same(x0,x1)) return ES_FAILED; GECODE_ME_CHECK(x0.le(home,x1.max())); GECODE_ME_CHECK(x1.gr(home,x0.min())); if (x0.max() >= x1.min()) (void) new (home) Le(home,x0,x1); return ES_OK; } template forceinline Le::Le(Space* home, bool share, Le& p) : BinaryPropagator(home,share,p) {} template Actor* Le::copy(Space* home, bool share) { return new (home) Le(home,share,*this); } template ExecStatus Le::propagate(Space* home) { GECODE_ME_CHECK(x0.le(home,x1.max())); GECODE_ME_CHECK(x1.gr(home,x0.min())); return (x0.max() < x1.min()) ? ES_SUBSUMED : ES_FIX; } /* * Reified less or equal propagator * */ template forceinline ReLq::ReLq(Space* home, View x0, View x1, CtrlView b) : ReBinaryPropagator(home,x0,x1,b) {} template ExecStatus ReLq::post(Space* home, View x0, View x1, CtrlView b) { if (b.one()) return Lq::post(home,x0,x1); if (b.zero()) return Le::post(home,x1,x0); if (!same(x0,x1)) { switch (rtest_lq(x0,x1)) { case RT_TRUE: b.t_one_none(home); break; case RT_FALSE: b.t_zero_none(home); break; case RT_MAYBE: (void) new (home) ReLq(home,x0,x1,b); break; default: GECODE_NEVER; } } else { b.t_one_none(home); } return ES_OK; } template forceinline ReLq::ReLq(Space* home, bool share, ReLq& p) : ReBinaryPropagator(home,share,p) {} template Actor* ReLq::copy(Space* home, bool share) { return new (home) ReLq(home,share,*this); } template ExecStatus ReLq::propagate(Space* home) { if (b.one()) { if (Lq::post(home,x0,x1) == ES_FAILED) return ES_FAILED; return ES_SUBSUMED; } if (b.zero()) { if (Le::post(home,x1,x0) == ES_FAILED) return ES_FAILED; return ES_SUBSUMED; } switch (rtest_lq(x0,x1)) { case RT_TRUE: b.t_one_none(home); return ES_SUBSUMED; case RT_FALSE: b.t_zero_none(home); return ES_SUBSUMED; case RT_MAYBE: break; default: GECODE_NEVER; } return ES_FIX; } /* * Reified less or equal propagator involving one variable * */ template forceinline ReLqInt::ReLqInt(Space* home, View x, int c0, CtrlView b) : ReUnaryPropagator(home,x,b), c(c0) {} template ExecStatus ReLqInt::post(Space* home, View x, int c, CtrlView b) { if (b.one()) { GECODE_ME_CHECK(x.lq(home,c)); } else if (b.zero()) { GECODE_ME_CHECK(x.gr(home,c)); } else { switch (rtest_lq(x,c)) { case RT_TRUE: b.t_one_none(home); break; case RT_FALSE: b.t_zero_none(home); break; case RT_MAYBE: (void) new (home) ReLqInt(home,x,c,b); break; default: GECODE_NEVER; } } return ES_OK; } template forceinline ReLqInt::ReLqInt(Space* home, bool share, ReLqInt& p) : ReUnaryPropagator(home,share,p), c(p.c) {} template Actor* ReLqInt::copy(Space* home, bool share) { return new (home) ReLqInt(home,share,*this); } template ExecStatus ReLqInt::propagate(Space* home) { if (b.one()) { GECODE_ME_CHECK(x0.lq(home,c)); return ES_SUBSUMED; } if (b.zero()) { GECODE_ME_CHECK(x0.gr(home,c)); return ES_SUBSUMED; } switch (rtest_lq(x0,c)) { case RT_TRUE: b.t_one_none(home); return ES_SUBSUMED; case RT_FALSE: b.t_zero_none(home); return ES_SUBSUMED; case RT_MAYBE: break; default: GECODE_NEVER; } return ES_FIX; } }}} // STATISTICS: int-prop