X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Fmain.cpp;h=1c6a85ecc85790716e6a8559e1ea86117d716922;hb=90e2c43b99205b0d7a300209011231cd8d11f7a0;hp=5e6a5c99902915cd28e344b4d63eecec0ed8f375;hpb=5f37e9f08f736f4fe4576dd530c60ecb87017907;p=germs.git diff --git a/src/main.cpp b/src/main.cpp index 5e6a5c9..1c6a85e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,8 +2,12 @@ #include #include #include +#include + using namespace std; +#include + #include "geneorder.h" #include "modelidentifier.h" #include "genesorter.h" @@ -11,20 +15,69 @@ using namespace std; typedef pair modelpair; -int main(){ +struct ScoreCmp { + template + bool operator()(T s1, T s2){ + return s1.first < s2.first; + } +}; + +int main(int argc, char** argv){ + + string ann = "default.ann"; + int opt; + while ((opt = getopt(argc, argv, "n:h")) != -1) { + switch (opt) { + case 'n': + ann = optarg; + break; + case 'h': + cout << "Usage: " << argv[0] << " [OPTION] [FILE]" << endl + << endl << " -n Specifies which artificial neural network to use for identification. '" << ann << "' is used by default" + << endl << " -h Prints this help message" + << endl << endl + << "With no FILE, or if FILE is '-', stdin will be used" + << endl; + exit(EXIT_SUCCESS); + break; + default: /* '?' */ + cerr << "Usage: " << argv[0] << " [-n ] [-h] [FILE]" << endl; + exit(EXIT_FAILURE); + } + } + + istream* in; + ifstream file; + if (optind == argc || *argv[optind] == '-'){ + in = &cin; + }else{ + file.open(argv[optind]); + if (file.fail()){ + cerr << "Could not open file: '" << argv[optind] << "'" << endl; + exit(EXIT_FAILURE); + } + in = &file; + } //TODO: Parse vector g; - copy(istream_iterator(cin), istream_iterator(), + copy(istream_iterator(*in), istream_iterator(), back_inserter(g)); GeneOrder go(g.begin(),g.end()); //TODO: Identify - ModelIdentifier mi("default.ann"); + ModelIdentifier mi(ann); map scores = mi.identify(go); + priority_queue,vector >, ScoreCmp > pq; for (map::iterator m = scores.begin(); m != scores.end(); ++m){ - cout << "Model: " << m->first << " score: " << m->second << endl; + if (m->second > 0){ + pq.push(pair(m->second,m->first)); + } + } + while (pq.size() > 0){ + cout << "Model: " << mi.modelName(pq.top().second) << " score: " << pq.top().first << endl; + pq.pop(); } //TODO: Chose a sorter @@ -32,5 +85,5 @@ int main(){ //TODO: Sort GeneSorter::ActionList al = so.sort(go); //TODO: Print result - return 0; + return EXIT_SUCCESS; }