00001 /*****************************************************************[qecore.hh] 00002 Copyright (c) 2007, Universite d'Orleans - Jeremie Vautard, Marco Benedetti, 00003 Arnaud Lallouet. 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 *****************************************************************************/ 00023 #ifndef qecore 00024 #define qecore 00025 00026 00027 00028 #include <cstdlib> 00029 #include <vector> 00030 #include <list> 00031 #include <stack> 00032 #include "extensivecomparator.hh" 00033 #include "heap.cc" 00034 #include "gecode/minimodel.hh" 00035 00036 using namespace Gecode; 00037 using namespace std; 00038 using namespace Gecode::Int; 00039 00040 00041 class BranchingHeuristic; 00042 00043 00047 class QSpace { 00048 protected: 00049 unsigned int n; 00050 unsigned long int ps; 00051 public: 00052 00054 QSpace(unsigned int nv); 00055 00056 00058 QSpace(QSpace& qs); 00059 00060 virtual ~QSpace() {} 00061 00062 00066 int nv() {return n;} 00067 00068 00072 IntVarArgs v; 00073 00074 00079 virtual bool quantification(int v)=0; 00080 00081 00082 00088 virtual int status(int var, unsigned long int& propsteps)=0; 00089 00094 virtual int finalStatus(unsigned long int& propsteps)=0; 00095 00100 virtual bool subsumed(int var)=0; 00101 00102 00105 virtual QSpace* clone()=0; 00106 00107 00113 virtual void assign(int var,int** vals,int nbVals)=0; // assigne la valeur val a la variable d'indice var 00114 virtual void remove(int var,int** vals,int nbVals)=0; // poste var != val 00115 00119 virtual void backtrack()=0; 00120 00121 00125 virtual void indicateBranchingHeuristic(BranchingHeuristic* bh)=0; 00126 00129 virtual void print()=0; 00130 }; 00131 00132 00133 00137 class ScoreAttribuer { 00138 public: 00139 00145 virtual int score(QSpace* qs,int var)=0; 00146 }; 00147 00148 00149 typedef Heap<ExtensiveComparator> cheap; 00150 typedef stack<int> stackint; 00151 00152 00153 00157 class BranchingHeuristic { 00158 private : 00159 int size; 00160 int blocks; 00161 int* bloc; 00162 stackint treated; 00163 cheap* heaps; 00164 stackint touched; 00165 int* score; 00166 int curHeap; 00167 ScoreAttribuer* eval; 00168 00169 public : 00170 void updateVar(int pos, QSpace* qs); 00171 00177 BranchingHeuristic(QSpace* qs, ScoreAttribuer* ev); 00178 00182 int nextVar(QSpace* qs); 00183 00184 00188 void backtrack(QSpace* qs); 00189 00190 00191 00195 void vartouched(int pos,QSpace* qs); 00196 }; 00197 00198 00199 00200 00201 #endif