construct.cpp
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Guido Tack <tack@gecode.org> 00005 * 00006 * Copyright: 00007 * Guido Tack, 2008 00008 * 00009 * Last modified: 00010 * $Date: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $ 00011 * $Revision: 10684 $ 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 "test/set.hh" 00039 00040 using namespace Gecode; 00041 00042 namespace Test { namespace Set { 00043 00045 namespace Var { 00046 00048 class Construct : public SetTest { 00049 public: 00051 Construct(void) 00052 : SetTest("Var::Construct",1,IntSet(0,0),false,0) {} 00054 virtual bool solution(const SetAssignment&) const { 00055 return true; 00056 } 00057 void con(Space& home, int glbMin, int glbMax, 00058 int lubMin, int lubMax, 00059 unsigned int minCard = 0, 00060 unsigned int maxCard = Gecode::Set::Limits::card, 00061 bool fail=true) { 00062 bool ok = false; 00063 try { 00064 SetVar x(home, glbMin, glbMax, lubMin, lubMax, minCard, maxCard); 00065 ok = true; 00066 } catch (Gecode::Set::VariableEmptyDomain&) { 00067 if (!fail) { 00068 home.fail(); 00069 return; 00070 } 00071 ok = true; 00072 } 00073 00074 if (ok) { 00075 try { 00076 SetVarArray xs(home, 1, 00077 glbMin, glbMax, lubMin, lubMax, minCard, maxCard); 00078 } catch (Gecode::Set::VariableEmptyDomain&) { 00079 if (!fail) { 00080 home.fail(); 00081 return; 00082 } else { 00083 return; 00084 } 00085 } 00086 if (fail) { 00087 home.fail(); 00088 } 00089 } 00090 } 00091 void con(Space& home, const IntSet& glb, int lubMin, int lubMax, 00092 unsigned int minCard = 0, 00093 unsigned int maxCard = Gecode::Set::Limits::card, 00094 bool fail=true) { 00095 bool ok = false; 00096 try { 00097 SetVar x(home, glb, lubMin, lubMax, minCard, maxCard); 00098 ok = true; 00099 } catch (Gecode::Set::VariableEmptyDomain&) { 00100 if (!fail) { 00101 home.fail(); 00102 return; 00103 } 00104 ok = true; 00105 } 00106 if (ok) { 00107 try { 00108 SetVarArray xs(home, 1, 00109 glb, lubMin, lubMax, minCard, maxCard); 00110 } catch (Gecode::Set::VariableEmptyDomain&) { 00111 if (!fail) { 00112 home.fail(); 00113 return; 00114 } else { 00115 return; 00116 } 00117 } 00118 if (fail) { 00119 home.fail(); 00120 } 00121 } 00122 } 00123 void con(Space& home, int glbMin, int glbMax, const IntSet& lub, 00124 unsigned int minCard = 0, 00125 unsigned int maxCard = Gecode::Set::Limits::card, 00126 bool fail=true) { 00127 bool ok = false; 00128 try { 00129 SetVar x(home, glbMin, glbMax, lub, minCard, maxCard); 00130 ok = true; 00131 } catch (Gecode::Set::VariableEmptyDomain&) { 00132 if (!fail) { 00133 home.fail(); 00134 return; 00135 } 00136 ok = true; 00137 } 00138 if (ok) { 00139 try { 00140 SetVarArray xs(home, 1, 00141 glbMin, glbMax, lub, minCard, maxCard); 00142 } catch (Gecode::Set::VariableEmptyDomain&) { 00143 if (!fail) { 00144 home.fail(); 00145 return; 00146 } else { 00147 return; 00148 } 00149 } 00150 if (fail) { 00151 home.fail(); 00152 } 00153 } 00154 } 00155 void con(Space& home, const IntSet& glb, const IntSet& lub, 00156 unsigned int minCard = 0, 00157 unsigned int maxCard = Gecode::Set::Limits::card, 00158 bool fail=true) { 00159 bool ok = false; 00160 try { 00161 SetVar x(home, glb, lub, minCard, maxCard); 00162 ok = true; 00163 } catch (Gecode::Set::VariableEmptyDomain&) { 00164 if (!fail) { 00165 home.fail(); 00166 return; 00167 } 00168 ok = true; 00169 } 00170 if (ok) { 00171 try { 00172 SetVarArray xs(home, 1, 00173 glb, lub, minCard, maxCard); 00174 } catch (Gecode::Set::VariableEmptyDomain&) { 00175 if (!fail) { 00176 home.fail(); 00177 return; 00178 } else { 00179 return; 00180 } 00181 } 00182 if (fail) { 00183 home.fail(); 00184 } 00185 } 00186 } 00188 virtual void post(Space& home, SetVarArray&, IntVarArray&) { 00189 // Check non-empty lower, empty upper bound 00190 con(home, 1,1, 1,0); 00191 con(home, IntSet(1,1), 1,0); 00192 con(home, 1,1, IntSet(1,0)); 00193 con(home, IntSet(1,1), IntSet(1,0)); 00194 00195 // Check min cardinality 00196 con(home, 1,0, 1,1, 2,3); 00197 con(home, IntSet(1,0), 1,1, 2,3); 00198 con(home, 1,0, IntSet(1,1), 2,3); 00199 con(home, IntSet(1,0), IntSet(1,1), 2,3); 00200 00201 // Check max cardinality 00202 con(home, 1,3, 1,4, 0,2); 00203 con(home, IntSet(1,3), 1,4, 0,2); 00204 con(home, 1,3, IntSet(1,4), 0,2); 00205 con(home, IntSet(1,3), IntSet(1,4), 0,2); 00206 00207 // Check non-subset bounds 00208 con(home, 1,3, 2,4); 00209 con(home, IntSet(1,3), 2,4); 00210 con(home, 1,3, IntSet(2,4)); 00211 con(home, IntSet(1,3), IntSet(2,4)); 00212 con(home, 1,4, 1,3); 00213 con(home, IntSet(1,4), 1,3); 00214 con(home, 1,4, IntSet(1,3)); 00215 con(home, IntSet(1,4), IntSet(1,3)); 00216 00217 con(home, IntSet::empty, 2, 4, 0, 10, false); 00218 } 00219 }; 00220 Construct _con; 00221 00222 00223 }}} 00224 00225 // STATISTICS: test-set