Generated on Tue Apr 18 10:21:45 2017 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  *  Last modified:
00010  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00011  *     $Revision: 14967 $
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 Int {
00039 
00040   /*
00041    * Testing equality
00042    *
00043    */
00044 
00045   template<class VX, class VY>
00046   forceinline RelTest
00047   rtest_eq_bnd(VX x, VY y) {
00048     if ((x.min() > y.max()) || (x.max() < y.min())) return RT_FALSE;
00049     return (x.assigned() && y.assigned()) ? RT_TRUE : RT_MAYBE;
00050   }
00051 
00052   template<class VX, class VY>
00053   RelTest
00054   rtest_eq_dom_check(VX x, VY y) {
00055     ViewRanges<VX> rx(x);
00056     ViewRanges<VY> ry(y);
00057     while (rx() && ry()) {
00058       if (rx.max() < ry.min()) {
00059         ++rx;
00060       } else if (ry.max() < rx.min()) {
00061         ++ry;
00062       } else return RT_MAYBE;
00063     }
00064     return RT_FALSE;
00065   }
00066 
00067   template<class VX, class VY>
00068   forceinline RelTest
00069   rtest_eq_dom(VX x, VY y) {
00070     RelTest rt = rtest_eq_bnd(x,y);
00071     if (rt != RT_MAYBE) return rt;
00072     return (x.range() && y.range()) ? RT_MAYBE : rtest_eq_dom_check(x,y);
00073   }
00074 
00075 
00076   template<class VX>
00077   forceinline RelTest
00078   rtest_eq_bnd(VX x, int n) {
00079     if ((n > x.max()) || (n < x.min())) return RT_FALSE;
00080     return x.assigned() ? RT_TRUE : RT_MAYBE;
00081   }
00082 
00083   template<class VX>
00084   RelTest
00085   rtest_eq_dom_check(VX x, int n) {
00086     ViewRanges<VX> rx(x);
00087     while (n > rx.max()) ++rx;
00088     return (n >= rx.min()) ? RT_MAYBE : RT_FALSE;
00089   }
00090 
00091   template<class VX>
00092   forceinline RelTest
00093   rtest_eq_dom(VX x, int n) {
00094     RelTest rt = rtest_eq_bnd(x,n);
00095     if (rt != RT_MAYBE) return rt;
00096     return x.range() ? RT_MAYBE : rtest_eq_dom_check(x,n);
00097   }
00098 
00099 
00100 
00101   /*
00102    * Testing disequality
00103    *
00104    */
00105 
00106   template<class VX, class VY>
00107   forceinline RelTest
00108   rtest_nq_bnd(VX x, VY y) {
00109     if ((x.min() > y.max()) || (x.max() < y.min())) return RT_TRUE;
00110     return (x.assigned() && y.assigned()) ? RT_FALSE : RT_MAYBE;
00111   }
00112 
00113   template<class VX, class VY>
00114   forceinline RelTest
00115   rtest_nq_dom_check(VX x, VY y) {
00116     ViewRanges<VX> rx(x);
00117     ViewRanges<VY> ry(y);
00118     while (rx() && ry()) {
00119       if (rx.max() < ry.min()) {
00120         ++rx;
00121       } else if (ry.max() < rx.min()) {
00122         ++ry;
00123       } else return RT_MAYBE;
00124     }
00125     return RT_TRUE;
00126   }
00127 
00128   template<class VX, class VY>
00129   forceinline RelTest
00130   rtest_nq_dom(VX x, VY y) {
00131     RelTest rt = rtest_nq_bnd(x,y);
00132     if (rt != RT_MAYBE) return rt;
00133     return (x.range() && y.range()) ? RT_MAYBE : rtest_nq_dom_check(x,y);
00134   }
00135 
00136 
00137   template<class VX>
00138   forceinline RelTest
00139   rtest_nq_bnd(VX x, int n) {
00140     if ((n > x.max()) || (n < x.min())) return RT_TRUE;
00141     return (x.assigned()) ? RT_FALSE : RT_MAYBE;
00142   }
00143 
00144   template<class VX>
00145   forceinline RelTest
00146   rtest_nq_dom_check(VX x, int n) {
00147     ViewRanges<VX> rx(x);
00148     while (n > rx.max()) ++rx;
00149     return (n >= rx.min()) ? RT_MAYBE : RT_TRUE;
00150   }
00151 
00152   template<class VX>
00153   forceinline RelTest
00154   rtest_nq_dom(VX x, int n) {
00155     RelTest rt = rtest_nq_bnd(x,n);
00156     if (rt != RT_MAYBE) return rt;
00157     return x.range() ? RT_MAYBE : rtest_nq_dom_check(x,n);
00158   }
00159 
00160 
00161   /*
00162    * Testing inequalities
00163    *
00164    */
00165 
00166   template<class VX, class VY>
00167   forceinline RelTest
00168   rtest_lq(VX x, VY y) {
00169     if (x.max() <= y.min()) return RT_TRUE;
00170     if (x.min() > y.max())  return RT_FALSE;
00171     return RT_MAYBE;
00172   }
00173 
00174   template<class VX>
00175   forceinline RelTest
00176   rtest_lq(VX x, int n) {
00177     if (x.max() <= n) return RT_TRUE;
00178     if (x.min() > n)  return RT_FALSE;
00179     return RT_MAYBE;
00180   }
00181 
00182   template<class VX, class VY>
00183   forceinline RelTest
00184   rtest_le(VX x, VY y) {
00185     if (x.max() <  y.min()) return RT_TRUE;
00186     if (x.min() >= y.max()) return RT_FALSE;
00187     return RT_MAYBE;
00188   }
00189 
00190   template<class VX>
00191   forceinline RelTest
00192   rtest_le(VX x, int n) {
00193     if (x.max() <  n) return RT_TRUE;
00194     if (x.min() >= n) return RT_FALSE;
00195     return RT_MAYBE;
00196   }
00197 
00198   template<class VX, class VY>
00199   forceinline RelTest
00200   rtest_gq(VX x, VY y) {
00201     if (x.max() <  y.min()) return RT_FALSE;
00202     if (x.min() >= y.max()) return RT_TRUE;
00203     return RT_MAYBE;
00204   }
00205 
00206   template<class VX>
00207   forceinline RelTest
00208   rtest_gq(VX x, int n) {
00209     if (x.max() <  n) return RT_FALSE;
00210     if (x.min() >= n) return RT_TRUE;
00211     return RT_MAYBE;
00212   }
00213 
00214   template<class VX, class VY>
00215   forceinline RelTest
00216   rtest_gr(VX x, VY y) {
00217     if (x.max() <= y.min()) return RT_FALSE;
00218     if (x.min() >  y.max()) return RT_TRUE;
00219     return RT_MAYBE;
00220   }
00221 
00222   template<class VX>
00223   forceinline RelTest
00224   rtest_gr(VX x, int n) {
00225     if (x.max() <= n) return RT_FALSE;
00226     if (x.min() >  n) return RT_TRUE;
00227     return RT_MAYBE;
00228   }
00229 
00230 }}
00231 
00232 // STATISTICS: int-var
00233