rel.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: 2009-10-12 17:36:53 +0200 (Mon, 12 Oct 2009) $ by $Author: schulte $ 00011 * $Revision: 9878 $ 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 #include <gecode/int/rel.hh> 00039 00040 namespace Gecode { namespace Int { namespace Count { 00041 00042 /* 00043 * Counting domain consistent equality 00044 * 00045 */ 00046 00047 template<class VX> 00048 forceinline RelTest 00049 holds(VX x, ConstIntView y) { 00050 return rtest_eq_dom(x,y.val()); 00051 } 00052 template<class VX> 00053 forceinline RelTest 00054 holds(VX x, ZeroIntView) { 00055 return rtest_eq_dom(x,0); 00056 } 00057 template<class VX> 00058 forceinline RelTest 00059 holds(VX x, VX y) { 00060 return rtest_eq_dom(x,y); 00061 } 00062 template<class VX> 00063 forceinline bool 00064 post_true(Home home, VX x, ConstIntView y) { 00065 return me_failed(x.eq(home,y.val())); 00066 } 00067 template<class VX> 00068 forceinline bool 00069 post_true(Home home, VX x, ZeroIntView) { 00070 return me_failed(x.eq(home,0)); 00071 } 00072 template<class VX> 00073 forceinline bool 00074 post_true(Home home, ViewArray<VX>& x, ConstIntView y) { 00075 for (int i = x.size(); i--; ) 00076 if (me_failed(x[i].eq(home,y.val()))) 00077 return true; 00078 return false; 00079 } 00080 template<class VX> 00081 forceinline bool 00082 post_true(Home home, ViewArray<VX>& x, ZeroIntView) { 00083 for (int i = x.size(); i--; ) 00084 if (me_failed(x[i].eq(home,0))) 00085 return true; 00086 return false; 00087 } 00088 template<class VX> 00089 forceinline bool 00090 post_false(Home home, VX x, ConstIntView y) { 00091 return me_failed(x.nq(home,y.val())); 00092 } 00093 template<class VX> 00094 forceinline bool 00095 post_false(Home home, VX x, ZeroIntView) { 00096 return me_failed(x.nq(home,0)); 00097 } 00098 template<class VX> 00099 forceinline bool 00100 post_false(Home home, ViewArray<VX>& x, ConstIntView y) { 00101 for (int i = x.size(); i--; ) 00102 if (me_failed(x[i].nq(home,y.val()))) 00103 return true; 00104 return false;; 00105 } 00106 template<class VX> 00107 forceinline bool 00108 post_false(Home home, ViewArray<VX>& x, ZeroIntView) { 00109 for (int i = x.size(); i--; ) 00110 if (me_failed(x[i].nq(home,0))) 00111 return true; 00112 return false;; 00113 } 00114 template<class VX> 00115 forceinline bool 00116 post_true(Home home, ViewArray<VX>& x, VX y) { 00117 ViewArray<VX> z(home,x.size()+1); 00118 z[x.size()] = y; 00119 for (int i = x.size(); i--; ) 00120 z[i] = x[i]; 00121 return Rel::NaryEqDom<VX>::post(home,z) == ES_FAILED; 00122 } 00123 template<class VX> 00124 forceinline bool 00125 post_true(Home home, VX x, VX y) { 00126 return Rel::EqDom<VX,VX>::post(home,x,y) == ES_FAILED; 00127 } 00128 template<class VX> 00129 forceinline bool 00130 post_false(Home home, ViewArray<VX>& x, VX y) { 00131 for (int i = x.size(); i--; ) 00132 if (Rel::Nq<VX>::post(home,x[i],y) == ES_FAILED) 00133 return true; 00134 return false; 00135 } 00136 template<class VX> 00137 forceinline bool 00138 post_false(Home home, VX x, VX y) { 00139 return Rel::Nq<VX>::post(home,x,y) == ES_FAILED; 00140 } 00141 00142 }}} 00143 00144 // STATISTICS: int-prop