linear-bool.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, 2006 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 #include <gecode/int/linear.hh> 00039 00040 namespace Gecode { 00041 00042 using namespace Int; 00043 00044 void 00045 linear(Home home, const BoolVarArgs& x, IntRelType r, int c, 00046 IntConLevel icl) { 00047 if (home.failed()) return; 00048 00049 int n=x.size(); 00050 Region re(home); 00051 Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView> >(n); 00052 for (int i=n; i--; ) { 00053 t[i].a=1; t[i].x=x[i]; 00054 } 00055 00056 Linear::post(home,t,n,r,c,icl); 00057 } 00058 00059 void 00060 linear(Home home, const BoolVarArgs& x, IntRelType r, IntVar y, 00061 IntConLevel icl) { 00062 if (home.failed()) return; 00063 00064 int n=x.size(); 00065 Region re(home); 00066 Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView> >(n); 00067 for (int i=n; i--; ) { 00068 t[i].a=1; t[i].x=x[i]; 00069 } 00070 00071 Linear::post(home,t,n,r,y,0,icl); 00072 } 00073 00074 void 00075 linear(Home home, 00076 const IntArgs& a, const BoolVarArgs& x, IntRelType r, int c, 00077 IntConLevel icl) { 00078 if (a.size() != x.size()) 00079 throw ArgumentSizeMismatch("Int::linear"); 00080 if (home.failed()) 00081 return; 00082 00083 int n=x.size(); 00084 Region re(home); 00085 Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView> >(n); 00086 for (int i=n; i--; ) { 00087 t[i].a=a[i]; t[i].x=x[i]; 00088 } 00089 00090 Linear::post(home,t,n,r,c,icl); 00091 } 00092 00093 void 00094 linear(Home home, 00095 const IntArgs& a, const BoolVarArgs& x, IntRelType r, IntVar y, 00096 IntConLevel icl) { 00097 if (a.size() != x.size()) 00098 throw ArgumentSizeMismatch("Int::linear"); 00099 if (home.failed()) 00100 return; 00101 00102 int n=x.size(); 00103 Region re(home); 00104 Linear::Term<BoolView>* t = 00105 re.alloc<Linear::Term<BoolView> >(n); 00106 for (int i=n; i--; ) { 00107 t[i].a=a[i]; t[i].x=x[i]; 00108 } 00109 int min, max; 00110 estimate(t,n,0,min,max); 00111 IntView v(y); 00112 switch (r) { 00113 case IRT_EQ: 00114 GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max)); 00115 break; 00116 case IRT_GQ: 00117 GECODE_ME_FAIL(v.lq(home,max)); 00118 break; 00119 case IRT_LQ: 00120 GECODE_ME_FAIL(v.gq(home,min)); 00121 break; 00122 default: ; 00123 } 00124 if (home.failed()) return; 00125 Linear::post(home,t,n,r,y,0,icl); 00126 } 00127 00128 void 00129 linear(Home home, const BoolVarArgs& x, IntRelType r, int c, 00130 BoolVar b, IntConLevel icl) { 00131 if (home.failed()) return; 00132 00133 int n=x.size(); 00134 Region re(home); 00135 Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView> >(n); 00136 for (int i=n; i--; ) { 00137 t[i].a=1; t[i].x=x[i]; 00138 } 00139 00140 Linear::post(home,t,n,r,c,b,icl); 00141 } 00142 00143 void 00144 linear(Home home, const BoolVarArgs& x, IntRelType r, IntVar y, 00145 BoolVar b, IntConLevel icl) { 00146 if (home.failed()) return; 00147 00148 int n=x.size(); 00149 Region re(home); 00150 Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView> >(n); 00151 for (int i=n; i--; ) { 00152 t[i].a=1; t[i].x=x[i]; 00153 } 00154 00155 Linear::post(home,t,n,r,y,b,icl); 00156 } 00157 00158 void 00159 linear(Home home, 00160 const IntArgs& a, const BoolVarArgs& x, IntRelType r, int c, 00161 BoolVar b, IntConLevel icl) { 00162 if (a.size() != x.size()) 00163 throw ArgumentSizeMismatch("Int::linear"); 00164 if (home.failed()) return; 00165 00166 int n=x.size(); 00167 Region re(home); 00168 Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView> >(n); 00169 for (int i=n; i--; ) { 00170 t[i].a=a[i]; t[i].x=x[i]; 00171 } 00172 00173 Linear::post(home,t,n,r,c,b,icl); 00174 } 00175 00176 void 00177 linear(Home home, 00178 const IntArgs& a, const BoolVarArgs& x, IntRelType r, IntVar y, 00179 BoolVar b, IntConLevel icl) { 00180 if (a.size() != x.size()) 00181 throw ArgumentSizeMismatch("Int::linear"); 00182 if (home.failed()) return; 00183 00184 int n=x.size(); 00185 Region re(home); 00186 Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView> >(n); 00187 for (int i=n; i--; ) { 00188 t[i].a=a[i]; t[i].x=x[i]; 00189 } 00190 00191 Linear::post(home,t,n,r,y,b,icl); 00192 } 00193 00194 } 00195 00196 // STATISTICS: int-post