Generated on Fri Oct 19 11:24:56 2018 for Gecode by doxygen 1.6.3

lq-le.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Gabor Szokoli <szokoli@gecode.org>
00006  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00007  *
00008  *  Copyright:
00009  *     Christian Schulte, 2003
00010  *     Gabor Szokoli, 2003
00011  *     Vincent Barichard, 2012
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Float { namespace Rel {
00039 
00040   /*
00041    * Less or equal propagator
00042    *
00043    */
00044 
00045   template<class View>
00046   forceinline
00047   Lq<View>::Lq(Home home, View x0, View x1)
00048     : BinaryPropagator<View,PC_FLOAT_BND>(home,x0,x1) {}
00049 
00050   template<class View>
00051   ExecStatus
00052   Lq<View>::post(Home home, View x0, View x1) {
00053     GECODE_ME_CHECK(x0.lq(home,x1.max()));
00054     GECODE_ME_CHECK(x1.gq(home,x0.min()));
00055     if ((x0 != x1) && (x0.max() > x1.min()))
00056       (void) new (home) Lq<View>(home,x0,x1);
00057     return ES_OK;
00058   }
00059 
00060   template<class View>
00061   forceinline
00062   Lq<View>::Lq(Space& home, Lq<View>& p)
00063     : BinaryPropagator<View,PC_FLOAT_BND>(home,p) {}
00064 
00065   template<class View>
00066   Actor*
00067   Lq<View>::copy(Space& home) {
00068     return new (home) Lq<View>(home,*this);
00069   }
00070 
00071   template<class View>
00072   ExecStatus
00073   Lq<View>::propagate(Space& home, const ModEventDelta&) {
00074     GECODE_ME_CHECK(x0.lq(home,x1.max()));
00075     GECODE_ME_CHECK(x1.gq(home,x0.min()));
00076     return (x0.assigned() || x1.assigned() || (x0.max() <= x1.min())) ? home.ES_SUBSUMED(*this) : ES_FIX;
00077   }
00078 
00079 
00080   /*
00081    * Less propagator
00082    *
00083    */
00084   template<class View>
00085   forceinline
00086   Le<View>::Le(Home home, View x0, View x1)
00087     : BinaryPropagator<View,PC_FLOAT_BND>(home,x0,x1) {}
00088 
00089   template<class View>
00090   ExecStatus
00091   Le<View>::post(Home home, View x0, View x1) {
00092     GECODE_ME_CHECK(x0.lq(home,x1.max()));
00093     GECODE_ME_CHECK(x1.gq(home,x0.min()));
00094     if (x0.assigned() && x1.assigned()) {
00095       if (x0.max() >= x1.min())
00096         return ES_FAILED;
00097     } else if (x0 == x1)
00098       return ES_FAILED;
00099     if (x0.max() >= x1.min())
00100       (void) new (home) Le<View>(home,x0,x1);
00101     return ES_OK;
00102   }
00103 
00104   template<class View>
00105   forceinline
00106   Le<View>::Le(Space& home, Le<View>& p)
00107     : BinaryPropagator<View,PC_FLOAT_BND>(home,p) {}
00108 
00109   template<class View>
00110   Actor*
00111   Le<View>::copy(Space& home) {
00112     return new (home) Le<View>(home,*this);
00113   }
00114 
00115   template<class View>
00116   ExecStatus
00117   Le<View>::propagate(Space& home, const ModEventDelta&) {
00118     GECODE_ME_CHECK(x0.lq(home,x1.max()));
00119     GECODE_ME_CHECK(x1.gq(home,x0.min()));
00120     if (x0.assigned() && x1.assigned()) {
00121       return (x0.max() >= x1.min()) ? ES_FAILED : home.ES_SUBSUMED(*this);
00122     }
00123     return (x0.max() < x1.min()) ? home.ES_SUBSUMED(*this) : ES_FIX;
00124   }
00125 
00126 
00127 
00128 
00129   /*
00130    * Reified less or equal propagator
00131    *
00132    */
00133 
00134   template<class View, class CtrlView, ReifyMode rm>
00135   forceinline
00136   ReLq<View,CtrlView,rm>::ReLq(Home home, View x0, View x1, CtrlView b)
00137     : Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x0,x1,b) {}
00138 
00139   template<class View, class CtrlView, ReifyMode rm>
00140   ExecStatus
00141   ReLq<View,CtrlView,rm>::post(Home home, View x0, View x1, CtrlView b) {
00142     if (b.one()) {
00143       if (rm == RM_PMI)
00144         return ES_OK;
00145       return Lq<View>::post(home,x0,x1);
00146     }
00147     if (b.zero()) {
00148       if (rm == RM_IMP)
00149         return ES_OK;
00150       return Le<View>::post(home,x1,x0);
00151     }
00152     if (x0 != x1) {
00153       switch (rtest_lq(x0,x1)) {
00154       case RT_TRUE:
00155         if (rm != RM_IMP)
00156           GECODE_ME_CHECK(b.one_none(home));
00157         break;
00158       case RT_FALSE:
00159         if (rm != RM_PMI)
00160           GECODE_ME_CHECK(b.zero_none(home));
00161         break;
00162       case RT_MAYBE:
00163         if (!x0.assigned() || !x1.assigned())
00164           (void) new (home) ReLq<View,CtrlView,rm>(home,x0,x1,b);
00165         else {
00166           if (rm != RM_IMP)
00167             GECODE_ME_CHECK(b.one_none(home));
00168         }
00169         break;
00170       default: GECODE_NEVER;
00171       }
00172     } else if (rm != RM_IMP) {
00173       GECODE_ME_CHECK(b.one_none(home));
00174     }
00175     return ES_OK;
00176   }
00177 
00178   template<class View, class CtrlView, ReifyMode rm>
00179   forceinline
00180   ReLq<View,CtrlView,rm>::ReLq(Space& home, ReLq& p)
00181     : Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,p) {}
00182 
00183   template<class View, class CtrlView, ReifyMode rm>
00184   Actor*
00185   ReLq<View,CtrlView,rm>::copy(Space& home) {
00186     return new (home) ReLq<View,CtrlView,rm>(home,*this);
00187   }
00188 
00189   template<class View, class CtrlView, ReifyMode rm>
00190   ExecStatus
00191   ReLq<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
00192     if (b.one()) {
00193       if (rm != RM_PMI)
00194         GECODE_REWRITE(*this,Lq<View>::post(home(*this),x0,x1));
00195     } else if (b.zero()) {
00196       if (rm != RM_IMP)
00197         GECODE_REWRITE(*this,Le<View>::post(home(*this),x1,x0));
00198     } else {
00199       switch (rtest_lq(x0,x1)) {
00200       case RT_TRUE:
00201         if (rm != RM_IMP)
00202           GECODE_ME_CHECK(b.one_none(home));
00203         break;
00204       case RT_FALSE:
00205         if (rm != RM_PMI)
00206           GECODE_ME_CHECK(b.zero_none(home));
00207         break;
00208       case RT_MAYBE:
00209         if (!x0.assigned() || !x1.assigned())
00210           return ES_FIX;
00211         else {
00212           if (rm != RM_IMP)
00213             GECODE_ME_CHECK(b.one_none(home));
00214           break;
00215         }
00216       default: GECODE_NEVER;
00217       }
00218     }
00219     return home.ES_SUBSUMED(*this);
00220   }
00221 
00222   /*
00223    * Reified less or equal propagator involving one variable
00224    *
00225    */
00226 
00227   template<class View, class CtrlView, ReifyMode rm>
00228   forceinline
00229   ReLqFloat<View,CtrlView,rm>::ReLqFloat(Home home, View x, FloatVal c0, CtrlView b)
00230     : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x,b), c(c0) {}
00231 
00232   template<class View, class CtrlView, ReifyMode rm>
00233   ExecStatus
00234   ReLqFloat<View,CtrlView,rm>::post(Home home, View x, FloatVal c, CtrlView b) {
00235     if (b.one()) {
00236       if (rm != RM_PMI)
00237         GECODE_ME_CHECK(x.lq(home,c.max()));
00238     } if (b.zero()) {
00239       if (rm != RM_IMP) {
00240         GECODE_ME_CHECK(x.gq(home,c.min()));
00241         if (x.assigned() && (x.min() <= c.max()))
00242           return ES_FAILED;
00243         (void) new (home) ReLqFloat<View,CtrlView,rm>(home,x,c,b);
00244       }
00245     } else {
00246       switch (rtest_lq(x,c)) {
00247       case RT_TRUE:
00248         if (rm != RM_IMP)
00249           GECODE_ME_CHECK(b.one(home));
00250         break;
00251       case RT_FALSE:
00252         if (rm != RM_PMI)
00253           GECODE_ME_CHECK(b.zero(home));
00254         break;
00255       case RT_MAYBE:
00256         (void) new (home) ReLqFloat<View,CtrlView,rm>(home,x,c,b);
00257         break;
00258       default: GECODE_NEVER;
00259       }
00260     }
00261     return ES_OK;
00262   }
00263 
00264 
00265   template<class View, class CtrlView, ReifyMode rm>
00266   forceinline
00267   ReLqFloat<View,CtrlView,rm>::ReLqFloat(Space& home, ReLqFloat& p)
00268     : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,p), c(p.c) {}
00269 
00270   template<class View, class CtrlView, ReifyMode rm>
00271   Actor*
00272   ReLqFloat<View,CtrlView,rm>::copy(Space& home) {
00273     return new (home) ReLqFloat<View,CtrlView,rm>(home,*this);
00274   }
00275 
00276   template<class View, class CtrlView, ReifyMode rm>
00277   ExecStatus
00278   ReLqFloat<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
00279     if (b.one()) {
00280       if (rm != RM_PMI)
00281         GECODE_ME_CHECK(x0.lq(home,c.max()));
00282     } else if (b.zero()) {
00283       if (rm != RM_IMP)
00284       {
00285         GECODE_ME_CHECK(x0.gq(home,c.min()));
00286         if (x0.assigned()) {
00287           return (x0.min() <= c.max()) ? ES_FAILED : home.ES_SUBSUMED(*this);
00288         }
00289       }
00290     } else {
00291       switch (rtest_lq(x0,c)) {
00292       case RT_TRUE:
00293         if (rm != RM_IMP)
00294           GECODE_ME_CHECK(b.one(home));
00295         break;
00296       case RT_FALSE:
00297         if (rm != RM_PMI)
00298           GECODE_ME_CHECK(b.zero(home));
00299         break;
00300       case RT_MAYBE:
00301         return ES_FIX;
00302       default: GECODE_NEVER;
00303       }
00304     }
00305     return home.ES_SUBSUMED(*this);
00306   }
00307 
00308 
00309   /*
00310    * Reified less
00311    *
00312    */
00313 
00314   template<class View, class CtrlView, ReifyMode rm>
00315   forceinline
00316   ReLeFloat<View,CtrlView,rm>::ReLeFloat(Home home, View x, FloatVal c0, CtrlView b)
00317     : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x,b), c(c0) {}
00318 
00319   template<class View, class CtrlView, ReifyMode rm>
00320   ExecStatus
00321   ReLeFloat<View,CtrlView,rm>::post(Home home, View x, FloatVal c, CtrlView b) {
00322     if (b.one()) {
00323       if (rm != RM_PMI)
00324       {
00325         GECODE_ME_CHECK(x.lq(home,c.max()));
00326         if (x.assigned() && (x.max() >= c.min()))
00327           return ES_FAILED;
00328         (void) new (home) ReLeFloat<View,CtrlView,rm>(home,x,c,b);
00329       }
00330     } else if (b.zero()) {
00331       if (rm != RM_IMP)
00332         GECODE_ME_CHECK(x.gq(home,c.min()));
00333     } else {
00334       switch (rtest_le(x,c)) {
00335       case RT_TRUE:
00336         if (rm != RM_IMP)
00337           GECODE_ME_CHECK(b.one(home));
00338         break;
00339       case RT_FALSE:
00340         if (rm != RM_PMI)
00341           GECODE_ME_CHECK(b.zero(home));
00342         break;
00343       case RT_MAYBE:
00344         (void) new (home) ReLeFloat<View,CtrlView,rm>(home,x,c,b);
00345         break;
00346       default: GECODE_NEVER;
00347       }
00348     }
00349     return ES_OK;
00350   }
00351 
00352 
00353   template<class View, class CtrlView, ReifyMode rm>
00354   forceinline
00355   ReLeFloat<View,CtrlView,rm>::ReLeFloat(Space& home, ReLeFloat& p)
00356     : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,p), c(p.c) {}
00357 
00358   template<class View, class CtrlView, ReifyMode rm>
00359   Actor*
00360   ReLeFloat<View,CtrlView,rm>::copy(Space& home) {
00361     return new (home) ReLeFloat<View,CtrlView,rm>(home,*this);
00362   }
00363 
00364   template<class View, class CtrlView, ReifyMode rm>
00365   ExecStatus
00366   ReLeFloat<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
00367     if (b.one()) {
00368       if (rm != RM_PMI)
00369       {
00370         GECODE_ME_CHECK(x0.lq(home,c.max()));
00371         if (x0.assigned()) {
00372           return (x0.max() >= c.min()) ? ES_FAILED : home.ES_SUBSUMED(*this);
00373         }
00374       }
00375     } else if (b.zero()) {
00376       if (rm != RM_IMP)
00377         GECODE_ME_CHECK(x0.gq(home,c.min()));
00378     } else {
00379       switch (rtest_le(x0,c)) {
00380       case RT_TRUE:
00381         if (rm != RM_IMP)
00382           GECODE_ME_CHECK(b.one(home));
00383         break;
00384       case RT_FALSE:
00385         if (rm != RM_PMI)
00386           GECODE_ME_CHECK(b.zero(home));
00387         break;
00388       case RT_MAYBE:
00389         return ES_FIX;
00390       default: GECODE_NEVER;
00391       }
00392     }
00393     return home.ES_SUBSUMED(*this);
00394   }
00395 
00396 }}}
00397 
00398 // STATISTICS: float-prop
00399