added permutation calculations to maximum-parsimony.cc
git-svn-id: svn://anubis/gvsu@303 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
85ce8d7ca8
commit
abeca4599d
@ -11,6 +11,14 @@
|
|||||||
#include "PTree.h"
|
#include "PTree.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static vector<Sequence *> sequences;
|
||||||
|
static int num_seqs;
|
||||||
|
|
||||||
|
void permute(int * array, int index);
|
||||||
|
void usage();
|
||||||
|
string getsequence(int fd);
|
||||||
|
void evalPermutation(int * array);
|
||||||
|
|
||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
cerr << "Usage: maximum-parsimony <sequence-file>" << endl;
|
cerr << "Usage: maximum-parsimony <sequence-file>" << endl;
|
||||||
@ -77,7 +85,6 @@ int main(int argc, char * argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Sequence *> sequences;
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
string seqstr = getsequence(fd);
|
string seqstr = getsequence(fd);
|
||||||
@ -89,12 +96,47 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
PTree tree(sequences);
|
num_seqs = sequences.size();
|
||||||
cout << "tree:" << endl;
|
int indices[num_seqs];
|
||||||
cout << tree;
|
for (int i = 0; i < num_seqs; i++)
|
||||||
cout << endl << "total count: " << tree.getCount() << endl;
|
indices[i] = 0;
|
||||||
|
permute(&indices[0], 0);
|
||||||
|
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user