diff --git a/cs677/pa4/maximum-parsimony.cc b/cs677/pa4/maximum-parsimony.cc index 3826007..2546da1 100644 --- a/cs677/pa4/maximum-parsimony.cc +++ b/cs677/pa4/maximum-parsimony.cc @@ -11,6 +11,14 @@ #include "PTree.h" using namespace std; +static vector sequences; +static int num_seqs; + +void permute(int * array, int index); +void usage(); +string getsequence(int fd); +void evalPermutation(int * array); + void usage() { cerr << "Usage: maximum-parsimony " << endl; @@ -77,7 +85,6 @@ int main(int argc, char * argv[]) exit(1); } - vector sequences; for (;;) { string seqstr = getsequence(fd); @@ -89,12 +96,47 @@ int main(int argc, char * argv[]) close(fd); - PTree tree(sequences); - cout << "tree:" << endl; - cout << tree; - cout << endl << "total count: " << tree.getCount() << endl; + num_seqs = sequences.size(); + int indices[num_seqs]; + for (int i = 0; i < num_seqs; i++) + indices[i] = 0; + permute(&indices[0], 0); MPI_Finalize(); return 0; } + +void evalPermutation(int * array) +{ + for (int i = 0; i < num_seqs; i++) + { + cout << array[i] << " "; + } + cout << endl; +} + +void permute(int * array, int index) +{ + static int level = -1; + level++; + array[index] = level; + + if (level == num_seqs) + { + evalPermutation(array); + } + else + { + for (int i = 0; i < num_seqs; i++) + { + if (array[i] == 0) + { + permute(array, i); + } + } + } + + level--; + array[index] = 0; +}