/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * Gabor Szokoli * Vincent Barichard * * Copyright: * Christian Schulte, 2003 * Gabor Szokoli, 2003 * Vincent Barichard, 2012 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ namespace Gecode { namespace Float { namespace Rel { /* * Less or equal propagator * */ template forceinline Lq::Lq(Home home, View x0, View x1) : BinaryPropagator(home,x0,x1) {} template ExecStatus Lq::post(Home home, View x0, View x1) { GECODE_ME_CHECK(x0.lq(home,x1.max())); GECODE_ME_CHECK(x1.gq(home,x0.min())); if ((x0 != x1) && (x0.max() > x1.min())) (void) new (home) Lq(home,x0,x1); return ES_OK; } template forceinline Lq::Lq(Space& home, Lq& p) : BinaryPropagator(home,p) {} template Actor* Lq::copy(Space& home) { return new (home) Lq(home,*this); } template ExecStatus Lq::propagate(Space& home, const ModEventDelta&) { GECODE_ME_CHECK(x0.lq(home,x1.max())); GECODE_ME_CHECK(x1.gq(home,x0.min())); return (x0.assigned() || x1.assigned() || (x0.max() <= x1.min())) ? home.ES_SUBSUMED(*this) : ES_FIX; } /* * Less propagator * */ template forceinline Le::Le(Home home, View x0, View x1) : BinaryPropagator(home,x0,x1) {} template ExecStatus Le::post(Home home, View x0, View x1) { GECODE_ME_CHECK(x0.lq(home,x1.max())); GECODE_ME_CHECK(x1.gq(home,x0.min())); if (x0.assigned() && x1.assigned()) { if (x0.max() >= x1.min()) return ES_FAILED; } else if (x0 == x1) return ES_FAILED; if (x0.max() >= x1.min()) (void) new (home) Le(home,x0,x1); return ES_OK; } template forceinline Le::Le(Space& home, Le& p) : BinaryPropagator(home,p) {} template Actor* Le::copy(Space& home) { return new (home) Le(home,*this); } template ExecStatus Le::propagate(Space& home, const ModEventDelta&) { GECODE_ME_CHECK(x0.lq(home,x1.max())); GECODE_ME_CHECK(x1.gq(home,x0.min())); if (x0.assigned() && x1.assigned()) { return (x0.max() >= x1.min()) ? ES_FAILED : home.ES_SUBSUMED(*this); } return (x0.max() < x1.min()) ? home.ES_SUBSUMED(*this) : ES_FIX; } /* * Reified less or equal propagator * */ template forceinline ReLq::ReLq(Home home, View x0, View x1, CtrlView b) : Int::ReBinaryPropagator(home,x0,x1,b) {} template ExecStatus ReLq::post(Home home, View x0, View x1, CtrlView b) { if (b.one()) { if (rm == RM_PMI) return ES_OK; return Lq::post(home,x0,x1); } if (b.zero()) { if (rm == RM_IMP) return ES_OK; return Le::post(home,x1,x0); } if (x0 != x1) { switch (rtest_lq(x0,x1)) { case RT_TRUE: if (rm != RM_IMP) GECODE_ME_CHECK(b.one_none(home)); break; case RT_FALSE: if (rm != RM_PMI) GECODE_ME_CHECK(b.zero_none(home)); break; case RT_MAYBE: if (!x0.assigned() || !x1.assigned()) (void) new (home) ReLq(home,x0,x1,b); else { if (rm != RM_IMP) GECODE_ME_CHECK(b.one_none(home)); } break; default: GECODE_NEVER; } } else if (rm != RM_IMP) { GECODE_ME_CHECK(b.one_none(home)); } return ES_OK; } template forceinline ReLq::ReLq(Space& home, ReLq& p) : Int::ReBinaryPropagator(home,p) {} template Actor* ReLq::copy(Space& home) { return new (home) ReLq(home,*this); } template ExecStatus ReLq::propagate(Space& home, const ModEventDelta&) { if (b.one()) { if (rm != RM_PMI) GECODE_REWRITE(*this,Lq::post(home(*this),x0,x1)); } else if (b.zero()) { if (rm != RM_IMP) GECODE_REWRITE(*this,Le::post(home(*this),x1,x0)); } else { switch (rtest_lq(x0,x1)) { case RT_TRUE: if (rm != RM_IMP) GECODE_ME_CHECK(b.one_none(home)); break; case RT_FALSE: if (rm != RM_PMI) GECODE_ME_CHECK(b.zero_none(home)); break; case RT_MAYBE: if (!x0.assigned() || !x1.assigned()) return ES_FIX; else { if (rm != RM_IMP) GECODE_ME_CHECK(b.one_none(home)); break; } default: GECODE_NEVER; } } return home.ES_SUBSUMED(*this); } /* * Reified less or equal propagator involving one variable * */ template forceinline ReLqFloat::ReLqFloat(Home home, View x, FloatVal c0, CtrlView b) : Int::ReUnaryPropagator(home,x,b), c(c0) {} template ExecStatus ReLqFloat::post(Home home, View x, FloatVal c, CtrlView b) { if (b.one()) { if (rm != RM_PMI) GECODE_ME_CHECK(x.lq(home,c.max())); } if (b.zero()) { if (rm != RM_IMP) { GECODE_ME_CHECK(x.gq(home,c.min())); if (x.assigned() && (x.min() <= c.max())) return ES_FAILED; (void) new (home) ReLqFloat(home,x,c,b); } } else { switch (rtest_lq(x,c)) { case RT_TRUE: if (rm != RM_IMP) GECODE_ME_CHECK(b.one(home)); break; case RT_FALSE: if (rm != RM_PMI) GECODE_ME_CHECK(b.zero(home)); break; case RT_MAYBE: (void) new (home) ReLqFloat(home,x,c,b); break; default: GECODE_NEVER; } } return ES_OK; } template forceinline ReLqFloat::ReLqFloat(Space& home, ReLqFloat& p) : Int::ReUnaryPropagator(home,p), c(p.c) {} template Actor* ReLqFloat::copy(Space& home) { return new (home) ReLqFloat(home,*this); } template ExecStatus ReLqFloat::propagate(Space& home, const ModEventDelta&) { if (b.one()) { if (rm != RM_PMI) GECODE_ME_CHECK(x0.lq(home,c.max())); } else if (b.zero()) { if (rm != RM_IMP) { GECODE_ME_CHECK(x0.gq(home,c.min())); if (x0.assigned()) { return (x0.min() <= c.max()) ? ES_FAILED : home.ES_SUBSUMED(*this); } } } else { switch (rtest_lq(x0,c)) { case RT_TRUE: if (rm != RM_IMP) GECODE_ME_CHECK(b.one(home)); break; case RT_FALSE: if (rm != RM_PMI) GECODE_ME_CHECK(b.zero(home)); break; case RT_MAYBE: return ES_FIX; default: GECODE_NEVER; } } return home.ES_SUBSUMED(*this); } /* * Reified less * */ template forceinline ReLeFloat::ReLeFloat(Home home, View x, FloatVal c0, CtrlView b) : Int::ReUnaryPropagator(home,x,b), c(c0) {} template ExecStatus ReLeFloat::post(Home home, View x, FloatVal c, CtrlView b) { if (b.one()) { if (rm != RM_PMI) { GECODE_ME_CHECK(x.lq(home,c.max())); if (x.assigned() && (x.max() >= c.min())) return ES_FAILED; (void) new (home) ReLeFloat(home,x,c,b); } } else if (b.zero()) { if (rm != RM_IMP) GECODE_ME_CHECK(x.gq(home,c.min())); } else { switch (rtest_le(x,c)) { case RT_TRUE: if (rm != RM_IMP) GECODE_ME_CHECK(b.one(home)); break; case RT_FALSE: if (rm != RM_PMI) GECODE_ME_CHECK(b.zero(home)); break; case RT_MAYBE: (void) new (home) ReLeFloat(home,x,c,b); break; default: GECODE_NEVER; } } return ES_OK; } template forceinline ReLeFloat::ReLeFloat(Space& home, ReLeFloat& p) : Int::ReUnaryPropagator(home,p), c(p.c) {} template Actor* ReLeFloat::copy(Space& home) { return new (home) ReLeFloat(home,*this); } template ExecStatus ReLeFloat::propagate(Space& home, const ModEventDelta&) { if (b.one()) { if (rm != RM_PMI) { GECODE_ME_CHECK(x0.lq(home,c.max())); if (x0.assigned()) { return (x0.max() >= c.min()) ? ES_FAILED : home.ES_SUBSUMED(*this); } } } else if (b.zero()) { if (rm != RM_IMP) GECODE_ME_CHECK(x0.gq(home,c.min())); } else { switch (rtest_le(x0,c)) { case RT_TRUE: if (rm != RM_IMP) GECODE_ME_CHECK(b.one(home)); break; case RT_FALSE: if (rm != RM_PMI) GECODE_ME_CHECK(b.zero(home)); break; case RT_MAYBE: return ES_FIX; default: GECODE_NEVER; } } return home.ES_SUBSUMED(*this); } }}} // STATISTICS: float-prop