diff --git a/cs677/pa4/ElementSet.cc b/cs677/pa4/ElementSet.cc index 6a6c252..ed751d2 100644 --- a/cs677/pa4/ElementSet.cc +++ b/cs677/pa4/ElementSet.cc @@ -46,3 +46,12 @@ ostream & operator<<(std::ostream & out, const ElementSet & e) out << '}'; return out; } + +void ElementSet::label() +{ + set::iterator it = mySet.begin(); + if (it == mySet.end()) + return; + it++; + mySet.erase(it, mySet.end()); +} diff --git a/cs677/pa4/ElementSet.h b/cs677/pa4/ElementSet.h index 62eadeb..bcec4c8 100644 --- a/cs677/pa4/ElementSet.h +++ b/cs677/pa4/ElementSet.h @@ -16,6 +16,7 @@ public: int size() { return mySet.size(); } ElementSet Union(const ElementSet & other); ElementSet Intersection(const ElementSet & other); + void label(); friend std::ostream & operator<<(std::ostream & out, const ElementSet & e); }; diff --git a/cs677/pa4/PTree.cc b/cs677/pa4/PTree.cc index 46c9388..fbcbfaf 100644 --- a/cs677/pa4/PTree.cc +++ b/cs677/pa4/PTree.cc @@ -76,3 +76,14 @@ int PTree::getCount() } return count; } + +void PTree::label() +{ + for (int i = 0, levels = myLevels.size(); i < levels; i++) + { + for (int j = 0, l_size = myLevels[i][0].size(); j < l_size; j++) + { + myLevels[i][0][j].label(); + } + } +} diff --git a/cs677/pa4/PTree.h b/cs677/pa4/PTree.h index bc4ecf2..701803e 100644 --- a/cs677/pa4/PTree.h +++ b/cs677/pa4/PTree.h @@ -14,6 +14,7 @@ public: void print(std::ostream & out, int level, int index, std::string prefix, std::string subprefix) const; int getCount(); + void label(); friend std::ostream & operator<<(std::ostream & out, const PTree & p); }; diff --git a/cs677/pa4/Sequence.cc b/cs677/pa4/Sequence.cc index aa30446..f92dad0 100644 --- a/cs677/pa4/Sequence.cc +++ b/cs677/pa4/Sequence.cc @@ -53,3 +53,9 @@ ostream & operator<<(ostream & out, const Sequence & s) out << s.myElements[i]; return out; } + +void Sequence::label() +{ + for (int i = 0, sz = myElements.size(); i < sz; i++) + myElements[i].label(); +} diff --git a/cs677/pa4/Sequence.h b/cs677/pa4/Sequence.h index bfd441c..a074539 100644 --- a/cs677/pa4/Sequence.h +++ b/cs677/pa4/Sequence.h @@ -18,6 +18,7 @@ public: Sequence(const char * initializer); Sequence parent(const Sequence & other); int getCount() { return myMutationCount; } + void label(); 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 a26458f..b87a4c4 100644 --- a/cs677/pa4/maximum-parsimony.cc +++ b/cs677/pa4/maximum-parsimony.cc @@ -134,6 +134,9 @@ int main(int argc, char * argv[]) if (my_rank == min_process) { cout << "Process " << my_rank << " lowest-cost tree:" << endl; + cout << (*lowest_cost_tree) << endl << endl; + cout << "Labeled:" << endl; + lowest_cost_tree->label(); cout << (*lowest_cost_tree) << endl; } delete lowest_cost_tree;