| 131 | |
| 132 | |
| 133 | Strategy QWorker::rsolve(int scope,/*vector<int> assignments,*/Engine* L) { |
| 134 | access.acquire(); |
| 135 | bool forget = (stopandforget==2); |
| 136 | access.release(); |
| 137 | if (forget) { |
| 138 | delete L; |
| 139 | return Strategy::Dummy(); |
| 140 | } |
| 141 | |
| 142 | MySpace* sol = static_cast<MySpace*>(L->next()); |
| 143 | Strategy ret=Strategy::Dummy(); |
| 144 | bool LwasEmpty = true; |
| 145 | |
| 146 | |
| 147 | while ((sol != NULL) ) { |
| 148 | LwasEmpty=false; |
| 149 | vector<int> assignments = getTheValues(sol,0,sol->nbVars()-1); |
| 150 | Strategy result; |
| 151 | |
| 152 | if (scope == (problem->spaces() - 1) ) { // last scope reached. Verify the goal... |
| 153 | MySpace* g = problem->getGoal(); |
| 154 | for (int i=0;i<g->nbVars();i++) { |
| 155 | switch (g->type_of_v[i]) { |
| 156 | case VTYPE_INT : |
| 157 | rel(*g,*(static_cast<IntVar*>(g->v[i])) == assignments[i]); |
| 158 | break; |
| 159 | case VTYPE_BOOL : |
| 160 | rel(*g,*(static_cast<BoolVar*>(g->v[i])) == assignments[i]); |
| 161 | break; |
| 162 | default : |
| 163 | cout<<"Unknown variable type"<<endl; |
| 164 | abort(); |
| 165 | } |
| 166 | } |
| 167 | Gecode::DFS<MySpace> solutions(g); |
| 168 | MySpace* goalsol = solutions.next(); |
| 169 | if (goalsol == NULL) { |
| 170 | delete g; |
| 171 | delete L; |
| 172 | result = Strategy::SFalse(); |
| 173 | } |
| 174 | else { |
| 175 | int vmin = ( (scope==0)? 0 : (problem->nbVarInScope(scope-1)) ); |
| 176 | int vmax = (problem->nbVarInScope(scope))-1; |
| 177 | vector<int> zevalues=getTheValues(sol,vmin,vmax); |
| 178 | result=Strategy(problem->quantification(scope),vmin,vmax,scope,zevalues); |
| 179 | result.attach(Strategy::STrue()); |
| 180 | delete g; |
| 181 | // delete sol; |
| 182 | delete goalsol; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | else { // This is not the last scope... |
| 187 | MySpace* espace = problem->getSpace(scope+1); |
| 188 | for (int i=0;i<assignments.size();i++) { |
| 189 | switch (espace->type_of_v[i]) { |
| 190 | case VTYPE_INT : |