dom.cpp
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, 2004 00008 * 00009 * Last modified: 00010 * $Date: 2010-03-03 17:40:32 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $ 00011 * $Revision: 10365 $ 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 00039 #include <gecode/int/dom.hh> 00040 #include <gecode/int/rel.hh> 00041 00042 namespace Gecode { 00043 00044 using namespace Int; 00045 00046 void 00047 dom(Home home, IntVar x, int n, IntConLevel) { 00048 Limits::check(n,"Int::dom"); 00049 if (home.failed()) return; 00050 IntView xv(x); 00051 GECODE_ME_FAIL(xv.eq(home,n)); 00052 } 00053 00054 void 00055 dom(Home home, const IntVarArgs& x, int n, IntConLevel) { 00056 Limits::check(n,"Int::dom"); 00057 if (home.failed()) return; 00058 for (int i=x.size(); i--; ) { 00059 IntView xv(x[i]); 00060 GECODE_ME_FAIL(xv.eq(home,n)); 00061 } 00062 } 00063 00064 void 00065 dom(Home home, IntVar x, int min, int max, IntConLevel) { 00066 Limits::check(min,"Int::dom"); 00067 Limits::check(max,"Int::dom"); 00068 if (home.failed()) return; 00069 IntView xv(x); 00070 GECODE_ME_FAIL(xv.gq(home,min)); 00071 GECODE_ME_FAIL(xv.lq(home,max)); 00072 } 00073 00074 void 00075 dom(Home home, const IntVarArgs& x, int min, int max, IntConLevel) { 00076 Limits::check(min,"Int::dom"); 00077 Limits::check(max,"Int::dom"); 00078 if (home.failed()) return; 00079 for (int i=x.size(); i--; ) { 00080 IntView xv(x[i]); 00081 GECODE_ME_FAIL(xv.gq(home,min)); 00082 GECODE_ME_FAIL(xv.lq(home,max)); 00083 } 00084 } 00085 00086 void 00087 dom(Home home, IntVar x, const IntSet& is, IntConLevel) { 00088 Limits::check(is.min(),"Int::dom"); 00089 Limits::check(is.max(),"Int::dom"); 00090 if (home.failed()) return; 00091 IntView xv(x); 00092 IntSetRanges ris(is); 00093 GECODE_ME_FAIL(xv.inter_r(home,ris,false)); 00094 } 00095 00096 void 00097 dom(Home home, const IntVarArgs& x, const IntSet& is, IntConLevel) { 00098 Limits::check(is.min(),"Int::dom"); 00099 Limits::check(is.max(),"Int::dom"); 00100 if (home.failed()) return; 00101 for (int i = x.size(); i--; ) { 00102 IntSetRanges ris(is); 00103 IntView xv(x[i]); 00104 GECODE_ME_FAIL(xv.inter_r(home,ris,false)); 00105 } 00106 } 00107 00108 void 00109 dom(Home home, IntVar x, int n, BoolVar b, IntConLevel) { 00110 Limits::check(n,"Int::dom"); 00111 if (home.failed()) return; 00112 GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView>::post(home,x,n,b))); 00113 } 00114 00115 void 00116 dom(Home home, IntVar x, int min, int max, BoolVar b, IntConLevel) { 00117 Limits::check(min,"Int::dom"); 00118 Limits::check(max,"Int::dom"); 00119 if (home.failed()) return; 00120 GECODE_ES_FAIL(Dom::ReRange<IntView>::post(home,x,min,max,b)); 00121 } 00122 00123 00124 void 00125 dom(Home home, IntVar x, const IntSet& is, BoolVar b, IntConLevel) { 00126 Limits::check(is.min(),"Int::dom"); 00127 Limits::check(is.max(),"Int::dom"); 00128 if (home.failed()) return; 00129 GECODE_ES_FAIL(Dom::ReIntSet<IntView>::post(home,x,is,b)); 00130 } 00131 00132 } 00133 00134 // STATISTICS: int-post 00135