#include <queue>
#include <iterator>
#include <fstream>
+#include <cstdlib>
using namespace std;
#include "geneorder.h"
#include "modelidentifier.h"
#include "genesorter.h"
+#include "threadgenesorter.h"
#include "sortaction.h"
#include "genealgorithms.h"
#include "model.h"
//Parse command line arguments
int opt;
- while ((opt = getopt(argc, argv, "im:n:hp")) != -1) {
+ int threads = 0;
+ while ((opt = getopt(argc, argv, "im:n:t:hp")) != -1) {
switch (opt) {
case 'm':
model = Model::modelFactory(optarg);
case 'n':
ann = optarg;
break;
+ case 't':
+ threads = atoi(optarg);
+ break;
case 'i':
onlyIdentify = true;
break;
if (onlyIdentify){
return EXIT_SUCCESS;
}
- //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);
+ so.join();
+
+ ThreadGeneSorter::SolutionsQueue solutions = so.solutions();
+
+ while (solutions.size() > 0){
+ 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 << 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;
+ }
}
+ cout << "Avg score: " << score / al.size() << endl;
}
- cout << "Avg score: " << score / al.size() << endl;
return EXIT_SUCCESS;
}