- //Sort
- GeneSorter so;
- GeneSorter::ActionList al = so.sort(go,model);
-
- //Print the result
- double score = 0;
-
- GeneOrder temp(go);
- for (GeneSorter::ActionList::iterator sa = al.begin(); sa != al.end(); ++sa){
- cout << "Action: " << sa->toString() << " model score: " << model.score(*sa,temp) << endl;
- (*sa)(temp);
- score += model.score(*sa,temp);
-
- if (printPerm){
- copy(temp.begin(), temp.end(), ostream_iterator<int>(cout, " "));
- cout << endl;
+ if (threads){
+ ThreadGeneSorter so(model, threads);
+ so.start(go);
+ cout << "Press CTRL+C to stop" << endl;
+ while (!g_cancel && so.running()){
+ double score = so.wait(5,1000);
+ cout << "\r" << "Solutions: " << so.size()
+ << " Best score: " << score / dist;
+ cout.flush();
+ }
+ cout << endl << "DONE: Waiting for threads to stop." << endl;
+ so.stop();
+ so.join();
+
+ ThreadGeneSorter::SolutionsQueue solutions = so.solutions();
+
+ for (int i = 0; i < 10 && solutions.size() > 0; ++i){
+ pair<double,GeneSorter::ActionList> s = solutions.top();
+ solutions.pop();
+
+ cout << "Actions: ";
+ for (GeneSorter::ActionList::iterator sa = s.second.begin();
+ sa != s.second.end(); ++sa){
+ cout << sa->toString() << " ";
+ }
+ cout << endl << "Score: " << s.first / dist << endl;
+ }
+ }else{
+ //Sort
+ GeneSorter so;
+ GeneSorter::ActionList al = so.sort(go,model);
+
+ //Print the result
+ double score = 0;
+
+ GeneOrder temp(go);
+ for (GeneSorter::ActionList::iterator sa = al.begin(); sa != al.end(); ++sa){
+ cout << "Action: " << sa->toString() << " model score: " << model.score(*sa,temp) << endl;
+ (*sa)(temp);
+ score += model.score(*sa,temp);
+
+ if (printPerm){
+ copy(temp.begin(), temp.end(), ostream_iterator<int>(cout, " "));
+ cout << endl;
+ }