/**** , [ QSolverUnblockable.cc ], Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *************************************************************************/ #include "qsolver_unblockable.hh" #include QSolverUnblockable::QSolverUnblockable(QcspUnblockable* sp) { this->sp = sp; nbRanges=new int; } Strategy QSolverUnblockable::solve(unsigned long int& nodes) { vector plop; plop.clear(); return rSolve(sp,0,plop,nodes); } Strategy QSolverUnblockable::rSolve(QcspUnblockable* qs,int scope, vector assignments, unsigned long int& nodes) { nodes++; //cout<<"rSolve for scope "<getGoal(); if (g == NULL) {return Strategy(StrategyNode::SFalse());} for (int i=0;itype_of_v[i]) { case VTYPE_INT : rel(*g,*(static_cast(g->v[i])) == assignments[i]); break; case VTYPE_BOOL : rel(*g,*(static_cast(g->v[i])) == assignments[i]); break; default : cout<<"1Unknown variable type"<status() == SS_FAILED) { delete g; return Strategy(StrategyNode::SFalse()); } delete g; if (scope == qs->spaces()) { return Strategy(StrategyNode::STrue()); } ///////////////////////////////////////////////////////////////////////////////////////// // Second case : we are in the middle of the problem... // ///////////////////////////////////////////////////////////////////////////////////////// else { MySpace* espace = qs->getSpace(scope); if (espace == NULL) cout<<"I caught a NULL for scope "<type_of_v[i]) { case VTYPE_INT : rel(*espace,*(static_cast(espace->v[i])) == assignments[i]); break; case VTYPE_BOOL : rel(*espace,*(static_cast(espace->v[i])) == assignments[i]); break; default : cout<<"2Unknown variable type"<quantification(scope)) { if (espace->status() == SS_FAILED) { delete espace; return Strategy(StrategyNode::STrue()); } DFS solutions(espace); MySpace* sol = solutions.next(); if (sol == NULL) { delete espace; return Strategy(StrategyNode::STrue()); } Strategy retour = StrategyNode::Dummy(); while (sol != NULL) { vector assign; for (int i = 0; inbVarInScope(scope);i++) { switch (sol->type_of_v[i]) { case VTYPE_INT : assign.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : assign.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"3Unknown variable type"<nbVarInScope(scope-1)) ); int vmax = (qs->nbVarInScope(scope))-1; vector zevalues; for (int i = vmin; i<=vmax;i++) { switch (sol->type_of_v[i]) { case VTYPE_INT : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"4Unknown variable type"<status()) == SS_FAILED) { delete espace; return Strategy(StrategyNode::SFalse()); } DFS solutions(espace); MySpace* sol =solutions.next(); if (sol == NULL) { delete espace; return Strategy(StrategyNode::SFalse()); } while (sol != NULL) { vector assign; for (int i = 0; inbVarInScope(scope);i++) { // cout << "i = "<type_of_v[i]) { case VTYPE_INT : assign.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : assign.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"5Unknown variable type"<nbVarInScope(scope-1) ); int vmax = qs->nbVarInScope(scope)-1; vector zevalues; for (int i = vmin; i<=vmax;i++) { switch (sol->type_of_v[i]) { case VTYPE_INT : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"6unknown Variable type"<sp = sp; nbRanges=new int; } Strategy QSolverUnblockable2::solve(unsigned long int& nodes) { vector plop; plop.clear(); return rSolve(sp,0,plop,nodes); } Strategy QSolverUnblockable2::rSolve(Qcop* qs,int scope, vector assignments, unsigned long int& nodes) { nodes++; //cout<<"rSolve for scope "<getGoal(); if (g == NULL) {return Strategy(StrategyNode::SFalse());} for (int i=0;itype_of_v[i]) { case VTYPE_INT : rel(*g,*(static_cast(g->v[i])) == assignments[i]); break; case VTYPE_BOOL : rel(*g,*(static_cast(g->v[i])) == assignments[i]); break; default : cout<<"1Unknown variable type"<status() == SS_FAILED) { delete g; return Strategy(StrategyNode::SFalse()); } delete g; if (scope == qs->spaces()) { return Strategy(StrategyNode::STrue()); } ///////////////////////////////////////////////////////////////////////////////////////// // Second case : we are in the middle of the problem... // ///////////////////////////////////////////////////////////////////////////////////////// else { MySpace* espace = qs->getSpace(scope); if (espace == NULL) cout<<"I caught a NULL for scope "<type_of_v[i]) { case VTYPE_INT : rel(*espace,*(static_cast(espace->v[i])) == assignments[i]); break; case VTYPE_BOOL : rel(*espace,*(static_cast(espace->v[i])) == assignments[i]); break; default : cout<<"2Unknown variable type"<quantification(scope)) { if (espace->status() == SS_FAILED) { delete espace; return Strategy(StrategyNode::STrue()); } DFS solutions(espace); MySpace* sol = solutions.next(); if (sol == NULL) { delete espace; return Strategy(StrategyNode::STrue()); } Strategy retour = StrategyNode::Dummy(); while (sol != NULL) { vector assign; for (int i = 0; inbVarInScope(scope);i++) { switch (sol->type_of_v[i]) { case VTYPE_INT : assign.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : assign.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"3Unknown variable type"<nbVarInScope(scope-1)) ); int vmax = (qs->nbVarInScope(scope))-1; vector zevalues; for (int i = vmin; i<=vmax;i++) { switch (sol->type_of_v[i]) { case VTYPE_INT : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"4Unknown variable type"<status()) == SS_FAILED) { delete espace; return Strategy(StrategyNode::SFalse()); } DFS solutions(espace); MySpace* sol =solutions.next(); if (sol == NULL) { delete espace; return Strategy(StrategyNode::SFalse()); } while (sol != NULL) { vector assign; for (int i = 0; inbVarInScope(scope);i++) { // cout << "i = "<type_of_v[i]) { case VTYPE_INT : assign.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : assign.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"5Unknown variable type"<nbVarInScope(scope-1) ); int vmax = qs->nbVarInScope(scope)-1; vector zevalues; for (int i = vmin; i<=vmax;i++) { switch (sol->type_of_v[i]) { case VTYPE_INT : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; case VTYPE_BOOL : zevalues.push_back( (static_cast(sol->v[i]))->val() ); break; default : cout<<"6unknown Variable type"<