creating PTrees and getting their total counts now working

git-svn-id: svn://anubis/gvsu@302 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-11-30 22:16:47 +00:00
parent 12a4d54bcc
commit 85ce8d7ca8
4 changed files with 22 additions and 5 deletions

View File

@ -32,6 +32,7 @@ PTree::PTree(const vector<Sequence *> & leaves)
(*myLevels[level_index-1])[2*i+1] (*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 << prefix;
out << myLevels[level][0][index]; out << myLevels[level][0][index];
out << endl;
if (level > 0) if (level > 0)
{ {
print(out, level - 1, index * 2, subprefix + "+-", subprefix + "| "); 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, "", ""); p.print(out, p.myLevels.size() - 1, 0, "", "");
return out; 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;
}

View File

@ -13,6 +13,7 @@ public:
~PTree(); ~PTree();
void print(std::ostream & out, int level, int index, void print(std::ostream & out, int level, int index,
std::string prefix, std::string subprefix) const; std::string prefix, std::string subprefix) const;
int getCount();
friend std::ostream & operator<<(std::ostream & out, const PTree & p); friend std::ostream & operator<<(std::ostream & out, const PTree & p);
}; };

View File

@ -17,6 +17,7 @@ public:
Sequence(int size); Sequence(int size);
Sequence(const char * initializer); Sequence(const char * initializer);
Sequence parent(const Sequence & other); Sequence parent(const Sequence & other);
int getCount() { return myMutationCount; }
friend std::ostream & operator<<(std::ostream & out, const Sequence & s); friend std::ostream & operator<<(std::ostream & out, const Sequence & s);
}; };

View File

@ -8,6 +8,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "Sequence.h" #include "Sequence.h"
#include "PTree.h"
using namespace std; using namespace std;
void usage() void usage()
@ -88,11 +89,10 @@ int main(int argc, char * argv[])
close(fd); close(fd);
cout << "Found " << sequences.size() << " sequences:" << endl; PTree tree(sequences);
for (int i = 0, sz = sequences.size(); i < sz; i++) cout << "tree:" << endl;
{ cout << tree;
cout << *sequences[i] << endl; cout << endl << "total count: " << tree.getCount() << endl;
}
MPI_Finalize(); MPI_Finalize();