diff --git a/cs677/pa4/PTree.cc b/cs677/pa4/PTree.cc index bb08cc0..46c9388 100644 --- a/cs677/pa4/PTree.cc +++ b/cs677/pa4/PTree.cc @@ -32,6 +32,7 @@ PTree::PTree(const vector & leaves) (*myLevels[level_index-1])[2*i+1] ); } + myLevels.push_back(level); } } } @@ -49,6 +50,7 @@ void PTree::print(ostream & out, int level, int index, { out << prefix; out << myLevels[level][0][index]; + out << endl; if (level > 0) { print(out, level - 1, index * 2, subprefix + "+-", subprefix + "| "); @@ -61,3 +63,16 @@ ostream & operator<<(ostream & out, const PTree & p) p.print(out, p.myLevels.size() - 1, 0, "", ""); return out; } + +int PTree::getCount() +{ + int count = 0; + for (int i = 0, levels = myLevels.size(); i < levels; i++) + { + for (int j = 0, l_size = myLevels[i][0].size(); j < l_size; j++) + { + count += myLevels[i][0][j].getCount(); + } + } + return count; +} diff --git a/cs677/pa4/PTree.h b/cs677/pa4/PTree.h index 1626c59..bc4ecf2 100644 --- a/cs677/pa4/PTree.h +++ b/cs677/pa4/PTree.h @@ -13,6 +13,7 @@ public: ~PTree(); void print(std::ostream & out, int level, int index, std::string prefix, std::string subprefix) const; + int getCount(); friend std::ostream & operator<<(std::ostream & out, const PTree & p); }; diff --git a/cs677/pa4/Sequence.h b/cs677/pa4/Sequence.h index 3509f67..bfd441c 100644 --- a/cs677/pa4/Sequence.h +++ b/cs677/pa4/Sequence.h @@ -17,6 +17,7 @@ public: Sequence(int size); Sequence(const char * initializer); Sequence parent(const Sequence & other); + int getCount() { return myMutationCount; } friend std::ostream & operator<<(std::ostream & out, const Sequence & s); }; diff --git a/cs677/pa4/maximum-parsimony.cc b/cs677/pa4/maximum-parsimony.cc index 0dab163..3826007 100644 --- a/cs677/pa4/maximum-parsimony.cc +++ b/cs677/pa4/maximum-parsimony.cc @@ -8,6 +8,7 @@ #include #include #include "Sequence.h" +#include "PTree.h" using namespace std; void usage() @@ -88,11 +89,10 @@ int main(int argc, char * argv[]) close(fd); - cout << "Found " << sequences.size() << " sequences:" << endl; - for (int i = 0, sz = sequences.size(); i < sz; i++) - { - cout << *sequences[i] << endl; - } + PTree tree(sequences); + cout << "tree:" << endl; + cout << tree; + cout << endl << "total count: " << tree.getCount() << endl; MPI_Finalize();