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

rel-test.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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2003
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int {
00035 
00036   /*
00037    * Testing equality
00038    *
00039    */
00040 
00041   template<class VX, class VY>
00042   forceinline RelTest
00043   rtest_eq_bnd(VX x, VY y) {
00044     if ((x.min() > y.max()) || (x.max() < y.min())) return RT_FALSE;
00045     return (x.assigned() && y.assigned()) ? RT_TRUE : RT_MAYBE;
00046   }
00047 
00048   template<class VX, class VY>
00049   RelTest
00050   rtest_eq_dom_check(VX x, VY y) {
00051     ViewRanges<VX> rx(x);
00052     ViewRanges<VY> ry(y);
00053     while (rx() && ry()) {
00054       if (rx.max() < ry.min()) {
00055         ++rx;
00056       } else if (ry.max() < rx.min()) {
00057         ++ry;
00058       } else return RT_MAYBE;
00059     }
00060     return RT_FALSE;
00061   }
00062 
00063   template<class VX, class VY>
00064   forceinline RelTest
00065   rtest_eq_dom(VX x, VY y) {
00066     RelTest rt = rtest_eq_bnd(x,y);
00067     if (rt != RT_MAYBE) return rt;
00068     return (x.range() && y.range()) ? RT_MAYBE : rtest_eq_dom_check(x,y);
00069   }
00070 
00071 
00072   template<class VX>
00073   forceinline RelTest
00074   rtest_eq_bnd(VX x, int n) {
00075     if ((n > x.max()) || (n < x.min())) return RT_FALSE;
00076     return x.assigned() ? RT_TRUE : RT_MAYBE;
00077   }
00078 
00079   template<class VX>
00080   RelTest
00081   rtest_eq_dom_check(VX x, int n) {
00082     ViewRanges<VX> rx(x);
00083     while (n > rx.max()) ++rx;
00084     return (n >= rx.min()) ? RT_MAYBE : RT_FALSE;
00085   }
00086 
00087   template<class VX>
00088   forceinline RelTest
00089   rtest_eq_dom(VX x, int n) {
00090     RelTest rt = rtest_eq_bnd(x,n);
00091     if (rt != RT_MAYBE) return rt;
00092     return x.range() ? RT_MAYBE : rtest_eq_dom_check(x,n);
00093   }
00094 
00095 
00096 
00097   /*
00098    * Testing disequality
00099    *
00100    */
00101 
00102   template<class VX, class VY>
00103   forceinline RelTest
00104   rtest_nq_bnd(VX x, VY y) {
00105     if ((x.min() > y.max()) || (x.max() < y.min())) return RT_TRUE;
00106     return (x.assigned() && y.assigned()) ? RT_FALSE : RT_MAYBE;
00107   }
00108 
00109   template<class VX, class VY>
00110   forceinline RelTest
00111   rtest_nq_dom_check(VX x, VY y) {
00112     ViewRanges<VX> rx(x);
00113     ViewRanges<VY> ry(y);
00114     while (rx() && ry()) {
00115       if (rx.max() < ry.min()) {
00116         ++rx;
00117       } else if (ry.max() < rx.min()) {
00118         ++ry;
00119       } else return RT_MAYBE;
00120     }
00121     return RT_TRUE;
00122   }
00123 
00124   template<class VX, class VY>
00125   forceinline RelTest
00126   rtest_nq_dom(VX x, VY y) {
00127     RelTest rt = rtest_nq_bnd(x,y);
00128     if (rt != RT_MAYBE) return rt;
00129     return (x.range() && y.range()) ? RT_MAYBE : rtest_nq_dom_check(x,y);
00130   }
00131 
00132 
00133   template<class VX>
00134   forceinline RelTest
00135   rtest_nq_bnd(VX x, int n) {
00136     if ((n > x.max()) || (n < x.min())) return RT_TRUE;
00137     return (x.assigned()) ? RT_FALSE : RT_MAYBE;
00138   }
00139 
00140   template<class VX>
00141   forceinline RelTest
00142   rtest_nq_dom_check(VX x, int n) {
00143     ViewRanges<VX> rx(x);
00144     while (n > rx.max()) ++rx;
00145     return (n >= rx.min()) ? RT_MAYBE : RT_TRUE;
00146   }
00147 
00148   template<class VX>
00149   forceinline RelTest
00150   rtest_nq_dom(VX x, int n) {
00151     RelTest rt = rtest_nq_bnd(x,n);
00152     if (rt != RT_MAYBE) return rt;
00153     return x.range() ? RT_MAYBE : rtest_nq_dom_check(x,n);
00154   }
00155 
00156 
00157   /*
00158    * Testing inequalities
00159    *
00160    */
00161 
00162   template<class VX, class VY>
00163   forceinline RelTest
00164   rtest_lq(VX x, VY y) {
00165     if (x.max() <= y.min()) return RT_TRUE;
00166     if (x.min() > y.max())  return RT_FALSE;
00167     return RT_MAYBE;
00168   }
00169 
00170   template<class VX>
00171   forceinline RelTest
00172   rtest_lq(VX x, int n) {
00173     if (x.max() <= n) return RT_TRUE;
00174     if (x.min() > n)  return RT_FALSE;
00175     return RT_MAYBE;
00176   }
00177 
00178   template<class VX, class VY>
00179   forceinline RelTest
00180   rtest_le(VX x, VY y) {
00181     if (x.max() <  y.min()) return RT_TRUE;
00182     if (x.min() >= y.max()) return RT_FALSE;
00183     return RT_MAYBE;
00184   }
00185 
00186   template<class VX>
00187   forceinline RelTest
00188   rtest_le(VX x, int n) {
00189     if (x.max() <  n) return RT_TRUE;
00190     if (x.min() >= n) return RT_FALSE;
00191     return RT_MAYBE;
00192   }
00193 
00194   template<class VX, class VY>
00195   forceinline RelTest
00196   rtest_gq(VX x, VY y) {
00197     if (x.max() <  y.min()) return RT_FALSE;
00198     if (x.min() >= y.max()) return RT_TRUE;
00199     return RT_MAYBE;
00200   }
00201 
00202   template<class VX>
00203   forceinline RelTest
00204   rtest_gq(VX x, int n) {
00205     if (x.max() <  n) return RT_FALSE;
00206     if (x.min() >= n) return RT_TRUE;
00207     return RT_MAYBE;
00208   }
00209 
00210   template<class VX, class VY>
00211   forceinline RelTest
00212   rtest_gr(VX x, VY y) {
00213     if (x.max() <= y.min()) return RT_FALSE;
00214     if (x.min() >  y.max()) return RT_TRUE;
00215     return RT_MAYBE;
00216   }
00217 
00218   template<class VX>
00219   forceinline RelTest
00220   rtest_gr(VX x, int n) {
00221     if (x.max() <= n) return RT_FALSE;
00222     if (x.min() >  n) return RT_TRUE;
00223     return RT_MAYBE;
00224   }
00225 
00226 }}
00227 
00228 // STATISTICS: int-var
00229