/************************************************************ WorkManager.cc Copyright (c) 2010 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 "WorkManager.hh" bool isPrefix(vector prefix,vector a) { if (a.size() < prefix.size()) return false; else for (unsigned int i=0;i::iterator i = l.begin(); while (i != l.end() && cmp->cmp((*i),q)) i++; l.insert(i,q); } QWork WorkPool::pop() { QWork ret=l.front(); l.pop_front(); return ret; } void WorkPool::trash(vector prefix) { // cout<<" WPT called on "; //if (prefix.empty()) cout<<"empty"; //for (int i=0;i< prefix.size();i++) cout<::iterator i=l.begin(); while (!(i == l.end())) { // cout<<"| "; // cout.flush(); bool avance=true; vector root = (*i).root(); if (isPrefix(prefix,root)) { (*i).clean(); i=l.erase(i); avance = false; // cout<<"erased"; } if (avance) i++; } //cout<::iterator i=l.begin();i != l.end();i++) { //vector root = (*i).root(); //if (isPrefix(prefix,root)) { // cout<<" trashing "; // if (root.empty()) cout<<"empty"; // for (int j=0;j< root.size();j++) cout<stopAndReturn(); } WorkManager::WorkManager(Qcop* p,WorkComparator* c) : Todos(c) { problem=p; vector v; MySpace* espace=p->getSpace(0); Options o; Engine* solutions = new WorkerToEngine(espace,/*sizeof(MySpace),*/o); QWork first(0,v,solutions); Todos.push(first); finished=false; S = Strategy::Dummy(); S.attach(Strategy::Stodo()); } QWork WorkManager::getWork(AQWorker* worker) { // clock_t start = clock(); // cout< todo,vector position) { // If the worker is not among the actives ones, ignore his job. Else, withdraw it from the active workers // and process its result // clock_t start = clock(); // cout<::iterator i = actives.begin(); while (!(i == actives.end()) && !ok) { bool avance=true; if ((*i) == worker) { // cout<<"RW Worker found in actives. Deleting"<::iterator j = todo.begin();j != todo.end();j++) { (*j).clean(); } // cout<<"RW release"< checkPosition = father.getPosition(); // if (checkPosition.empty()) cout<<"empty"; // for (int i=0;i< checkPosition.size();i++) cout<::iterator j = todo.begin();j != todo.end();j++) { // cout<<"WM todo + 1"<wake(); } // cout<<"RW Adding work in Todos : "; // if ((*j).root().empty()) cout<<"empty"; // for (int i=0;i< (*j).root().size();i++) cout<<(*j).root()[i]<<" "; // cout<qt_of_var(position.size() + 1); if (myscope) { // if ret was a forall node, the father itself is false // cout<<"RW work is A -> father is false"<::iterator j = todo.begin();j != todo.end();j++) { (*j).clean(); } } // cout<<"RW release"< hihi = s.getPosition(); // if (hihi.empty()) cout<<"empty"; // for (int i=0;i< hihi.size();i++) cout< hihi = s.getPosition(); // if (hihi.empty()) cout<<"empty"; // for (int i=0;i< hihi.size();i++) cout< prefix) { // cout<<" TW called on "; // if (prefix.empty()) cout<<"empty"; // for (int i=0;i< prefix.size();i++) cout<::iterator i=actives.begin();i!=actives.end();i++) { if (isPrefix(prefix,(*i)->workPosition())) { // cout<<" TW stopping worker on"; // vector plop = (*i)->workPosition(); // if (plop.empty()) cout<<"empty"; // for (int j=0;j< plop.size();j++) cout<stopAndForget(); i=actives.erase(i); i--; } } } void WorkManager::printStatus() { mex.acquire(); cout<<(finished?"Problem solved":"Problem not solved")<