]> ruin.nu Git - germs.git/blob - src/main.cpp
started a refactoring with Model class to score different sort actions
[germs.git] / src / main.cpp
1 #include <iostream>
2 #include <vector>
3 #include <queue>
4 #include <iterator>
5 #include <fstream>
6
7 using namespace std;
8
9 #include <unistd.h>
10
11 #include "geneorder.h"
12 #include "modelidentifier.h"
13 #include "genesorter.h"
14 #include "sortaction.h"
15 #include "model.h"
16
17 int main(int argc, char** argv){
18
19         string ann = "default.ann";
20
21         int opt;
22         while ((opt = getopt(argc, argv, "n:h")) != -1) {
23                 switch (opt) {
24                         case 'n':
25                                 ann = optarg;
26                                 break;
27                         case 'h':
28                                 cout << "Usage: " << argv[0] << " [OPTION] [FILE]" << endl
29                                         << endl << "  -n <ann>   Specifies which artificial neural network to use for identification. '" << ann << "' is used by default"
30                                         << endl << "  -h         Prints this help message"
31                                         << endl << endl
32                                         << "With no FILE, or if FILE is '-', stdin will be used"
33                                         << endl;
34                                 exit(EXIT_SUCCESS);
35                                 break;
36                         default: /* '?' */
37                                 cerr << "Usage:  " << argv[0] << " [-n <ann>] [-h] [FILE]" << endl;
38                                 exit(EXIT_FAILURE);
39                 }
40         }
41
42         istream* in;
43         ifstream file;
44         if (optind == argc || *argv[optind] == '-'){
45                 in = &cin;
46         }else{
47                 file.open(argv[optind]);
48                 if (file.fail()){
49                         cerr << "Could not open file: '" << argv[optind] << "'" << endl;
50                         exit(EXIT_FAILURE);
51                 }
52                 in = &file;
53         }
54         //TODO: Parse
55         vector<Gene> g;
56         copy(istream_iterator<int>(*in), istream_iterator<int>(),
57                      back_inserter(g));   
58         GeneOrder go(g.begin(),g.end());
59
60         //TODO: Identify
61         ModelIdentifier mi(ann);
62         priority_queue<pair<double,Model> > pq = mi.identify(go);
63         while (pq.size() > 0){
64                 cout << "Model: " << pq.top().second.name() << " score: " << pq.top().first << endl;
65                 pq.pop();
66         }
67
68         //TODO: Chose a sorter
69         GeneSorter so;
70         //TODO: Sort
71         GeneSorter::ActionList al = so.sort(go);
72         //TODO: Print result
73         return EXIT_SUCCESS;
74 }