Generated on Wed Nov 1 15:04:41 2006 for Gecode by doxygen 1.4.5

rtest.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2003
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-06-08 14:20:28 +0200 (Thu, 08 Jun 2006) $ by $Author: schulte $
00010  *     $Revision: 3275 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode { namespace Int {
00023 
00024   /*
00025    * Testing equality
00026    *
00027    */
00028 
00029   template <class View>
00030   forceinline RelTest
00031   rtest_eq_bnd(View x, View y) {
00032     if ((x.min() > y.max()) || (x.max() < y.min())) return RT_FALSE;
00033     return (x.assigned() && y.assigned()) ? RT_TRUE : RT_MAYBE;
00034   }
00035 
00036   template <class View>
00037   RelTest
00038   rtest_eq_dom_check(View x, View y) {
00039     ViewRanges<View> rx(x), ry(y);
00040     while (rx() && ry()) {
00041       if (rx.max() < ry.min()) {
00042         ++rx;
00043       } else if (ry.max() < rx.min()) {
00044         ++ry;
00045       } else return RT_MAYBE;
00046     }
00047     return RT_FALSE;
00048   }
00049 
00050   template <class View>
00051   forceinline RelTest
00052   rtest_eq_dom(View x, View y) {
00053     RelTest rt = rtest_eq_bnd(x,y);
00054     if (rt != RT_MAYBE) return rt;
00055     return (x.range() && y.range()) ? RT_MAYBE : rtest_eq_dom_check(x,y);
00056   }
00057 
00058 
00059   template <class View>
00060   forceinline RelTest
00061   rtest_eq_bnd(View x, int n) {
00062     if ((n > x.max()) || (n < x.min())) return RT_FALSE;
00063     return x.assigned() ? RT_TRUE : RT_MAYBE;
00064   }
00065 
00066   template <class View>
00067   RelTest
00068   rtest_eq_dom_check(View x, int n) {
00069     ViewRanges<View> rx(x);
00070     while (n > rx.max()) ++rx;
00071     return (n >= rx.min()) ? RT_MAYBE : RT_FALSE;
00072   }
00073 
00074   template <class View>
00075   forceinline RelTest
00076   rtest_eq_dom(View x, int n) {
00077     RelTest rt = rtest_eq_bnd(x,n);
00078     if (rt != RT_MAYBE) return rt;
00079     return x.range() ? RT_MAYBE : rtest_eq_dom_check(x,n);
00080   }
00081 
00082 
00083 
00084   /*
00085    * Testing disequality
00086    *
00087    */
00088 
00089   template <class View>
00090   forceinline RelTest
00091   rtest_nq_bnd(View x, View y) {
00092     if ((x.min() > y.max()) || (x.max() < y.min())) return RT_TRUE;
00093     return (x.assigned() && y.assigned()) ? RT_FALSE : RT_MAYBE;
00094   }
00095 
00096   template <class View>
00097   forceinline RelTest
00098   rtest_nq_dom_check(View x, View y) {
00099     ViewRanges<View> rx(x), ry(y);
00100     while (rx() && ry()) {
00101       if (rx.max() < ry.min()) {
00102         ++rx;
00103       } else if (ry.max() < rx.min()) {
00104         ++ry;
00105       } else return RT_MAYBE;
00106     }
00107     return RT_TRUE;
00108   }
00109 
00110   template <class View>
00111   forceinline RelTest
00112   rtest_nq_dom(View x, View y) {
00113     RelTest rt = rtest_nq_bnd(x,y);
00114     if (rt != RT_MAYBE) return rt;
00115     return (x.range() && y.range()) ? RT_MAYBE : rtest_nq_dom_check(x,y);
00116   }
00117 
00118 
00119   template <class View>
00120   forceinline RelTest
00121   rtest_nq_bnd(View x, int n) {
00122     if ((n > x.max()) || (n < x.min())) return RT_TRUE;
00123     return (x.assigned()) ? RT_FALSE : RT_MAYBE;
00124   }
00125 
00126   template <class View>
00127   forceinline RelTest
00128   rtest_nq_dom_check(View x, int n) {
00129     ViewRanges<View> rx(x);
00130     while (n > rx.max()) ++rx;
00131     return (n >= rx.min()) ? RT_MAYBE : RT_TRUE;
00132   }
00133 
00134   template <class View>
00135   forceinline RelTest
00136   rtest_nq_dom(View x, int n) {
00137     RelTest rt = rtest_nq_bnd(x,n);
00138     if (rt != RT_MAYBE) return rt;
00139     return x.range() ? RT_MAYBE : rtest_nq_dom_check(x,n);
00140   }
00141 
00142 
00143   /*
00144    * Testing inequalities
00145    *
00146    */
00147 
00148   template <class View>
00149   forceinline RelTest
00150   rtest_lq(View x, int n) {
00151     if (x.max() <= n) return RT_TRUE;
00152     if (x.min() > n)  return RT_FALSE;
00153     return RT_MAYBE;
00154   }
00155 
00156   template <class View>
00157   forceinline RelTest
00158   rtest_lq(View x, View y) {
00159     if (x.max() <= y.min()) return RT_TRUE;
00160     if (x.min() > y.max())  return RT_FALSE;
00161     return RT_MAYBE;
00162   }
00163 
00164   template <class View>
00165   forceinline RelTest
00166   rtest_le(View x, int n) {
00167     if (x.max() <  n) return RT_TRUE;
00168     if (x.min() >= n) return RT_FALSE;
00169     return RT_MAYBE;
00170   }
00171 
00172   template <class View>
00173   forceinline RelTest
00174   rtest_le(View x, View y) {
00175     if (x.max() <  y.min()) return RT_TRUE;
00176     if (x.min() >= y.max()) return RT_FALSE;
00177     return RT_MAYBE;
00178   }
00179 
00180   template <class View>
00181   forceinline RelTest
00182   rtest_gq(View x, int n) {
00183     if (x.max() <  n) return RT_FALSE;
00184     if (x.min() >= n) return RT_TRUE;
00185     return RT_MAYBE;
00186   }
00187 
00188   template <class View>
00189   forceinline RelTest
00190   rtest_gq(View x, View y) {
00191     if (x.max() <  y.min()) return RT_FALSE;
00192     if (x.min() >= y.max()) return RT_TRUE;
00193     return RT_MAYBE;
00194   }
00195 
00196   template <class View>
00197   forceinline RelTest
00198   rtest_gr(View x, int n) {
00199     if (x.max() <= n) return RT_FALSE;
00200     if (x.min() >  n) return RT_TRUE;
00201     return RT_MAYBE;
00202   }
00203 
00204   template <class View>
00205   forceinline RelTest
00206   rtest_gr(View x, View y) {
00207     if (x.max() <= y.min()) return RT_FALSE;
00208     if (x.min() >  y.max()) return RT_TRUE;
00209     return RT_MAYBE;
00210   }
00211 
00212 }}
00213 
00214 // STATISTICS: int-var
00215