this repo has no description
at develop 6.7 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Guido Tack <tack@gecode.org> 5 * 6 * Copyright: 7 * Guido Tack, 2008 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34#include "test/set.hh" 35 36using namespace Gecode; 37 38namespace Test { namespace Set { 39 40 /// %Tests for set variable conors 41 namespace Var { 42 43 /// %Test for cardinality constraint 44 class Construct : public SetTest { 45 public: 46 /// Create and register test 47 Construct(void) 48 : SetTest("Var::Construct",1,IntSet(0,0),false,0) {} 49 /// %Test whether \a x is solution 50 virtual bool solution(const SetAssignment&) const { 51 return true; 52 } 53 void con(Space& home, int glbMin, int glbMax, 54 int lubMin, int lubMax, 55 unsigned int minCard = 0, 56 unsigned int maxCard = Gecode::Set::Limits::card, 57 bool fail=true) { 58 bool ok = false; 59 try { 60 SetVar x(home, glbMin, glbMax, lubMin, lubMax, minCard, maxCard); 61 ok = true; 62 } catch (Gecode::Set::VariableEmptyDomain&) { 63 if (!fail) { 64 home.fail(); 65 return; 66 } 67 ok = true; 68 } 69 70 if (ok) { 71 try { 72 SetVarArray xs(home, 1, 73 glbMin, glbMax, lubMin, lubMax, minCard, maxCard); 74 } catch (Gecode::Set::VariableEmptyDomain&) { 75 if (!fail) { 76 home.fail(); 77 return; 78 } else { 79 return; 80 } 81 } 82 if (fail) { 83 home.fail(); 84 } 85 } 86 } 87 void con(Space& home, const IntSet& glb, int lubMin, int lubMax, 88 unsigned int minCard = 0, 89 unsigned int maxCard = Gecode::Set::Limits::card, 90 bool fail=true) { 91 bool ok = false; 92 try { 93 SetVar x(home, glb, lubMin, lubMax, minCard, maxCard); 94 ok = true; 95 } catch (Gecode::Set::VariableEmptyDomain&) { 96 if (!fail) { 97 home.fail(); 98 return; 99 } 100 ok = true; 101 } 102 if (ok) { 103 try { 104 SetVarArray xs(home, 1, 105 glb, lubMin, lubMax, minCard, maxCard); 106 } catch (Gecode::Set::VariableEmptyDomain&) { 107 if (!fail) { 108 home.fail(); 109 return; 110 } else { 111 return; 112 } 113 } 114 if (fail) { 115 home.fail(); 116 } 117 } 118 } 119 void con(Space& home, int glbMin, int glbMax, const IntSet& lub, 120 unsigned int minCard = 0, 121 unsigned int maxCard = Gecode::Set::Limits::card, 122 bool fail=true) { 123 bool ok = false; 124 try { 125 SetVar x(home, glbMin, glbMax, lub, minCard, maxCard); 126 ok = true; 127 } catch (Gecode::Set::VariableEmptyDomain&) { 128 if (!fail) { 129 home.fail(); 130 return; 131 } 132 ok = true; 133 } 134 if (ok) { 135 try { 136 SetVarArray xs(home, 1, 137 glbMin, glbMax, lub, minCard, maxCard); 138 } catch (Gecode::Set::VariableEmptyDomain&) { 139 if (!fail) { 140 home.fail(); 141 return; 142 } else { 143 return; 144 } 145 } 146 if (fail) { 147 home.fail(); 148 } 149 } 150 } 151 void con(Space& home, const IntSet& glb, const IntSet& lub, 152 unsigned int minCard = 0, 153 unsigned int maxCard = Gecode::Set::Limits::card, 154 bool fail=true) { 155 bool ok = false; 156 try { 157 SetVar x(home, glb, lub, minCard, maxCard); 158 ok = true; 159 } catch (Gecode::Set::VariableEmptyDomain&) { 160 if (!fail) { 161 home.fail(); 162 return; 163 } 164 ok = true; 165 } 166 if (ok) { 167 try { 168 SetVarArray xs(home, 1, 169 glb, lub, minCard, maxCard); 170 } catch (Gecode::Set::VariableEmptyDomain&) { 171 if (!fail) { 172 home.fail(); 173 return; 174 } else { 175 return; 176 } 177 } 178 if (fail) { 179 home.fail(); 180 } 181 } 182 } 183 /// Post constraint on \a x 184 virtual void post(Space& home, SetVarArray&, IntVarArray&) { 185 // Check non-empty lower, empty upper bound 186 con(home, 1,1, 1,0); 187 con(home, IntSet(1,1), 1,0); 188 con(home, 1,1, IntSet(1,0)); 189 con(home, IntSet(1,1), IntSet(1,0)); 190 191 // Check min cardinality 192 con(home, 1,0, 1,1, 2,3); 193 con(home, IntSet(1,0), 1,1, 2U,3U); 194 con(home, 1,0, IntSet(1,1), 2U,3U); 195 con(home, IntSet(1,0), IntSet(1,1), 2U,3U); 196 197 // Check max cardinality 198 con(home, 1,3, 1,4, 0,2); 199 con(home, IntSet(1,3), 1,4, 0U,2U); 200 con(home, 1,3, IntSet(1,4), 0U,2U); 201 con(home, IntSet(1,3), IntSet(1,4), 0U,2U); 202 203 // Check non-subset bounds 204 con(home, 1,3, 2,4); 205 con(home, IntSet(1,3), 2,4); 206 con(home, 1,3, IntSet(2,4)); 207 con(home, IntSet(1,3), IntSet(2,4)); 208 con(home, 1,4, 1,3); 209 con(home, IntSet(1,4), 1,3); 210 con(home, 1,4, IntSet(1,3)); 211 con(home, IntSet(1,4), IntSet(1,3)); 212 213 con(home, IntSet::empty, 2, 4, 0U, 10U, false); 214 } 215 }; 216 Construct _con; 217 218 219}}} 220 221// STATISTICS: test-set