this repo has no description
1/**** , [ stress_test.cpp ], 2Copyright (c) 2007 Universite d'Orleans - Jeremie Vautard 3 4Permission is hereby granted, free of charge, to any person obtaining a copy 5of this software and associated documentation files (the "Software"), to deal 6in the Software without restriction, including without limitation the rights 7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8copies of the Software, and to permit persons to whom the Software is 9furnished to do so, subject to the following conditions: 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20THE SOFTWARE. 21*************************************************************************/ 22 23#include "qsolver_qcop.hh" 24#include "QCOPPlus.hh" 25#include "qsolver_qcsp.hh" 26#include <iostream> 27 28using namespace std; 29 30// This function prints a winning strategy. 31void printStr(Strategy s,int depth=0) { 32 StrategyNode plop = s.getTag(); 33 for (int glou=0;glou<depth;glou++) cout<<" "; 34 if (s.isTrue()) cout<<"TRUE"<<endl; 35 else if (s.isFalse()) cout<<"FALSE"<<endl; 36 else cout<<"type "<<plop.type<<" qt "<<plop.quantifier<<" vmin "<<plop.Vmin<<" vmax "<<plop.Vmax<<" scope "<<plop.scope<<" - "; 37 for (int i=0;i<s.getTag().valeurs.size();i++) cout<<s.getTag().valeurs[i]<<" "; 38 cout<<endl; 39 for (int glou=0;glou<depth;glou++) cout<<" "; 40 cout<<s.degree()<<" child(ren)"<<endl; 41 for (int i=0;i<s.degree();i++) { 42 for (int glou=0;glou<depth;glou++) cout<<" "; 43 cout<<"Child "<<i<<" : "<<endl; 44 printStr(s.getChild(i),depth+1); 45 } 46} 47 48// This is a set of tiny problems which are used to dtect errors in QeCode. 49// This set is likely to progressively enlarge... 50 51int main() { 52 unsigned long int nodes; 53 unsigned long int steps; 54 55 // Ax in 1..3 [] -> x=1 56 int sc1[] = {1}; 57 bool q1[] = {QECODE_UNIVERSAL}; 58 Qcop test1(1,q1,sc1); 59 test1.QIntVar(0,1,3); 60 IntVarArgs b1(1); 61 b1[0] = test1.var(0); 62 branch(*(test1.space()),b1,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 63 test1.nextScope(); 64 rel(*(test1.space()),test1.var(0) == 1); 65 test1.makeStructure(); 66 QCSP_Solver s1(&test1); 67 nodes=0; 68 Strategy ret1=s1.solve(nodes,INT_MAX,true); 69 cout<<"Problem 1 : result = "<<(ret1.isFalse()?"FALSE":"TRUE")<<", sould be FALSE."<<endl; 70 cout<<nodes<<" nodes."<<endl; 71 printStr(ret1); 72 73 //Ex in 1..3 [] st x=1 74 int sc2[] = {1}; 75 bool q2[] = {QECODE_EXISTENTIAL}; 76 Qcop test2(1,q2,sc2); 77 test2.QIntVar(0,1,3); 78 79 IntVarArgs b2(1); 80 b2[0] = test2.var(0); 81 branch(*(test2.space()),b2,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 82 83 test2.nextScope(); 84 rel(*(test2.space()),test2.var(0) == 1); 85 test2.makeStructure(); 86 QCSP_Solver s2(&test2); 87 nodes=0; 88 Strategy ret2=s2.solve(nodes,INT_MAX,true); 89 cout<<"Problem 2 : result = "<<(ret2.isFalse()?"FALSE":"TRUE")<<", sould be TRUE."<<endl; 90 cout<<nodes<<" nodes."<<endl; 91 printStr(ret2); 92 93 94 95 //Ax in 1..3 [x=1] -> x=2 96 int sc3[] = {1}; 97 bool q3[] = {QECODE_UNIVERSAL}; 98 Qcop test3(1,q3,sc3); 99 test3.QIntVar(0,1,3); 100 rel(*(test3.space()),test3.var(0) == 1); 101 102 IntVarArgs b3(1); 103 b3[0] = test3.var(0); 104 branch(*(test3.space()),b3,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 105 106 test3.nextScope(); 107 rel(*(test3.space()),test3.var(0) == 2); 108 test3.makeStructure();; 109 QCSP_Solver s3(&test3); 110 nodes=0; 111 steps=0; 112 Strategy ret3=s3.solve(nodes,INT_MAX,true); 113 cout<<"Problem 3 : result = "<<(ret3.isFalse()?"FALSE":"TRUE")<<", sould be FALSE."<<endl; 114 cout<<nodes<<" nodes."<<endl; 115 printStr(ret3); 116 117 118 // Ex in 1..3 [x=1] st x=2 119 int sc4[] = {1}; 120 bool q4[] = {QECODE_EXISTENTIAL}; 121 Qcop test4(1,q4,sc4); 122 test4.QIntVar(0,1,3); 123 rel(*(test4.space()),test4.var(0) == 1); 124 125 IntVarArgs b4(1); 126 b4[0] = test4.var(0); 127 branch(*(test4.space()),b4,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 128 129 test4.nextScope(); 130 rel(*(test4.space()),test4.var(0) == 2); 131 test4.makeStructure(); 132 QCSP_Solver s4(&test4); 133 nodes=0; 134 Strategy ret4=s4.solve(nodes,INT_MAX,true); 135 cout<<"Problem 4 : result = "<<(ret4.isFalse()?"FALSE":"TRUE")<<", sould be FALSE."<<endl; 136 cout<<nodes<<" nodes."<<endl; 137 printStr(ret4); 138 139 140 141 // Ax in 1..3 [x=1] -> Ey in 1..3 [x=2] -> y=1 142 int sc5[] = {1,1}; 143 bool q5[] = {QECODE_UNIVERSAL,QECODE_EXISTENTIAL}; 144 Qcop test5(2,q5,sc5); 145 test5.QIntVar(0,1,3); 146 test5.QIntVar(1,1,3); 147 rel(*(test5.space()),test5.var(0) == 1); 148 149 IntVarArgs b5(1); 150 b5[0] = test5.var(0); 151 branch(*(test5.space()),b5,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 152 153 test5.nextScope(); 154 rel(*(test5.space()),test5.var(0) == 2); 155 156 IntVarArgs b52(2); 157 b52[0] = test5.var(0); 158 b52[1] = test5.var(1); 159 branch(*(test5.space()),b52,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 160 161 test5.nextScope(); 162 rel(*(test5.space()),test5.var(1) == 1); 163 test5.makeStructure(); 164 QCSP_Solver s5(&test5); 165 nodes=0; 166 steps=0; 167 Strategy ret5=s5.solve(nodes,INT_MAX,true); 168 cout<<"Problem 5 : result = "<<(ret5.isFalse()?"FALSE":"TRUE")<<", sould be FALSE."<<endl; 169 cout<<nodes<<" nodes."<<endl; 170 printStr(ret5); 171 172 173 // Ax in 1..3 [x=1] -> Ey in 1..3 [x=1] -> x=2 174 int sc6[] = {1,1}; 175 bool q6[] = {QECODE_UNIVERSAL,QECODE_EXISTENTIAL}; 176 Qcop test6(2,q6,sc6); 177 test6.QIntVar(0,1,3); 178 test6.QIntVar(1,1,3); 179 rel(*(test6.space()),test6.var(0) == 1); 180 181 IntVarArgs b6(1); 182 b6[0] = test6.var(0); 183 branch(*(test6.space()),b6,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 184 185 test6.nextScope(); 186 rel(*(test6.space()),test6.var(0) == 1); 187 188 IntVarArgs b62(2); 189 b62[0] = test6.var(0); 190 b62[1] = test6.var(1); 191 branch(*(test6.space()),b62,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 192 193 test6.nextScope(); 194 rel(*(test6.space()),test6.var(0) == 2); 195 test6.makeStructure(); 196 QCSP_Solver s6(&test6); 197 nodes=0; 198 steps=0; 199 Strategy ret6=s6.solve(nodes,INT_MAX,true); 200 cout<<"Problem 6 : result = "<<(ret6.isFalse()?"FALSE":"TRUE")<<", sould be FALSE."<<endl; 201 cout<<nodes<<" nodes."<<endl; 202 printStr(ret6); 203 204 205 //Ex in 1..3 [] Ay in 0..3 [y<2] -> y=0 206 int sc7[] = {1,1}; 207 bool q7[] = {QECODE_EXISTENTIAL,QECODE_UNIVERSAL}; 208 Qcop test7(2,q7,sc7); 209 test7.QIntVar(0,1,3); 210 test7.QIntVar(1,0,3); 211 212 IntVarArgs b7(1); 213 b7[0] = test7.var(0); 214 branch(*(test7.space()),b7,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 215 216 test7.nextScope(); 217 rel(*(test7.space()),test7.var(1) <= 2); 218 219 IntVarArgs b72(2); 220 b72[0] = test7.var(0); 221 b72[1] = test7.var(1); 222 branch(*(test7.space()),b72,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 223 224 test7.nextScope(); 225 rel(*(test7.space()),test7.var(1) == 0); 226 test7.makeStructure(); 227 QCSP_Solver s7(&test7); 228 nodes=0; 229 steps=0; 230 Strategy ret7=s7.solve(nodes,INT_MAX,true); 231 cout<<"Problem 7 : result = "<<(ret7.isFalse()?"FALSE":"TRUE")<<", sould be FALSE."<<endl; 232 cout<<nodes<<" nodes."<<endl; 233 printStr(ret7); 234 235 236 //Ex in 1..3 [] Ay in 0..3 [y=0] -> y=0 237 int sc8[] = {1,1}; 238 bool q8[] = {QECODE_EXISTENTIAL,QECODE_UNIVERSAL}; 239 Qcop test8(2,q8,sc8); 240 test8.QIntVar(0,1,3); 241 test8.QIntVar(1,0,3); 242 243 IntVarArgs b8(1); 244 b8[0] = test8.var(0); 245 branch(*(test8.space()),b8,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 246 247 test8.nextScope(); 248 rel(*(test8.space()),test8.var(1) == 0); 249 250 IntVarArgs b82(2); 251 b82[0] = test8.var(0); 252 b82[1] = test8.var(1); 253 branch(*(test8.space()),b82,INT_VAR_SIZE_MIN(),INT_VAL_MIN()); 254 255 test8.nextScope(); 256 rel(*(test8.space()),test8.var(1) == 0); 257 test8.makeStructure(); 258 QCSP_Solver s8(&test8); 259 nodes=0; 260 steps=0; 261 Strategy ret8=s8.solve(nodes,INT_MAX,true); 262 cout<<"Problem 8 : result = "<<(ret8.isFalse()?"FALSE":"TRUE")<<", sould be TRUE."<<endl; 263 cout<<nodes<<" nodes."<<endl; 264 printStr(ret8); 265 266} 267 268