00001 /**** , [ NimFibo.cpp ], 00002 Copyright (c) 2007 Universite d'Orleans - Jeremie Vautard 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 *************************************************************************/ 00022 00023 #include "qsolver.hh" 00024 #include "implicative.hh" 00025 #include "SDFVariableHeuristic.hh" 00026 #include "NaiveValueHeuristics.hh" 00027 #include "FirstFailValueHeuristic.hh" 00028 00030 // This is a model of the nim-fibonacci game. We have a N matches set. First player may // 00031 // take between 1 and N-1 matches. Then, each player may take at most twice the number of// 00032 // matches taken by the last player. Take the last match to win ! // 00034 00035 int main() { 00036 int N = 20; // Initial number of matches 00037 00038 int* scopeSize = new int[N+2]; 00039 for (int i=0;i<N+2;i++) 00040 scopeSize[i] = 2; 00041 00042 Implicative p(N+2,QECODE_EXISTENTIAL,scopeSize); 00043 00044 p.QIntVar(0,1,N-1); 00045 p.QIntVar(1,0,N); 00046 post(p.space(),p.var(0) == p.var(1)); 00047 p.nextScope(); 00048 00049 for (int i=1;i<N+2;i++) { 00050 p.QIntVar(2*i , 1, N-1); 00051 p.QIntVar(2*i + 1, 0, N); 00052 post(p.space(), p.var(2*i) <= 2*p.var(2*(i-1))); 00053 post(p.space(), p.var(2*i + 1) == p.var(2*i) + p.var(2*i - 1)); 00054 p.nextScope(); 00055 } 00056 00057 p.makeStructure(); 00058 00059 SmallestDomainFirst heur; 00060 // SmallestValueFirst v_heur; 00061 FirstFailValue v_heur; 00062 QSolver s(&p,&heur,&v_heur); 00063 00064 unsigned long int nodes=0; 00065 unsigned long int propsteps=0; 00066 00067 bool outcome = s.solve(nodes,propsteps); 00068 00069 cout << " outcome: " << ( outcome ? "TRUE" : "FALSE") << endl; 00070 cout << " nodes visited: " << nodes << " " << propsteps << endl; 00071 00072 return outcome ? 10:20; 00073 }