Insert commit message here
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1589 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
7a257679e2
commit
8aa685d740
5 changed files with 211 additions and 3 deletions
|
|
@ -15,6 +15,8 @@
|
|||
#include <eoCountedFileMonitor.h>
|
||||
#include <eoSingleFileCountedStateSaver.h>
|
||||
#include <vectorSortIndex.h>
|
||||
#include <functors.h>
|
||||
#include <SplitCalculator.h>
|
||||
|
||||
#include <utils.h>
|
||||
#include <apply.h>
|
||||
|
|
|
|||
109
contribution/branches/PhyloMOEA/PhyloMOEA/SplitCalculator.h
Normal file
109
contribution/branches/PhyloMOEA/PhyloMOEA/SplitCalculator.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#ifndef _SPLITCALCULATOR_H_
|
||||
#define _SPLITCALCULATOR_H_
|
||||
|
||||
#include <phylotreeIND.h>
|
||||
|
||||
struct split_info
|
||||
{
|
||||
int left, right, num_nodes;
|
||||
split_info() {};
|
||||
split_info(int n) : left(n), right(-1), num_nodes(0) {};
|
||||
};
|
||||
|
||||
|
||||
class SplitCalculator : public TreeCalculator <split_info>
|
||||
{
|
||||
|
||||
private :
|
||||
|
||||
struct split_info temp;
|
||||
|
||||
public :
|
||||
|
||||
/// virtual dtor here so there is no need to define it in derived classes
|
||||
virtual ~SplitCalculator() {}
|
||||
|
||||
/// The pure virtual function that needs to be implemented by the subclass
|
||||
struct split_info operator()(phylotreeIND &tree)
|
||||
{
|
||||
// hash table
|
||||
int n = tree.number_of_taxons();
|
||||
struct split_info **hash_table; // hash that points struct info
|
||||
struct split_info *interior_node_info = new struct split_info[n-1];
|
||||
|
||||
int idx_interior = 0;
|
||||
node_map<struct split_info*> interior_node(tree.TREE, NULL);
|
||||
edge_map<struct split_info*> interior_edge(tree.TREE, NULL);
|
||||
// node mapes
|
||||
int *map_nodes;
|
||||
int node_count = 0;
|
||||
int good_edges = 0;
|
||||
|
||||
|
||||
// allocate memory
|
||||
hash_table = new struct split_info*[n];
|
||||
for(int i=0; i<n; i++)hash_table[i] = NULL;
|
||||
map_nodes = new int[n];
|
||||
|
||||
// step 1
|
||||
// select last taxon as root
|
||||
node invalid_node;
|
||||
node root1 = tree.taxon_number( n-1);
|
||||
|
||||
// step 2 and 3
|
||||
postorder_Iterator it = tree.postorder_begin( root1);
|
||||
|
||||
int l, r;
|
||||
while( *it != root1 )
|
||||
{
|
||||
struct split_info *father_info = interior_node [ it.ancestor() ] ;
|
||||
struct split_info *current_info = interior_node [ *it ] ;
|
||||
|
||||
//cout << " node " << *it << " ancestral" << it.ancestor() << endl;
|
||||
if( tree.istaxon(*it) )
|
||||
{
|
||||
// update the map
|
||||
map_nodes[ tree.taxon_id( *it) ] = r = node_count;
|
||||
|
||||
// check if is the leftmost
|
||||
if( father_info == NULL )
|
||||
{
|
||||
interior_node [ it.ancestor() ] = father_info = &interior_node_info[idx_interior];
|
||||
idx_interior++;
|
||||
//father_info.left_most = *it;
|
||||
father_info->left = node_count;
|
||||
}
|
||||
//else father_info.right = node_count;
|
||||
node_count++;
|
||||
++it;
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx;
|
||||
l = current_info->left;
|
||||
interior_edge[ it.branch() ] = current_info;
|
||||
|
||||
if( father_info == NULL )
|
||||
{
|
||||
interior_node [ it.ancestor() ] = father_info = &interior_node_info[idx_interior];
|
||||
idx_interior++;
|
||||
father_info->left = current_info->left;
|
||||
}
|
||||
|
||||
++it;
|
||||
if (tree.istaxon(*it) || *it==root1) idx = r;
|
||||
else idx = l;
|
||||
|
||||
current_info->right = r;
|
||||
// fill hash table
|
||||
hash_table[ idx ] = current_info;
|
||||
}
|
||||
}
|
||||
delete [] interior_node_info;
|
||||
delete [] map_nodes;
|
||||
delete [] hash_table;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
@ -197,8 +197,8 @@ void SubstModel::k2p()
|
|||
void SubstModel::gtr()
|
||||
{
|
||||
|
||||
a=1.23767538; b=3.58902963;
|
||||
c=2.16811705; d=0.73102339; e=6.91039679;
|
||||
// a=1.23767538; b=3.58902963;
|
||||
// c=2.16811705; d=0.73102339; e=6.91039679;
|
||||
set_rate(0,1, a);
|
||||
set_rate(1,0, a);
|
||||
set_rate(0,2, b);
|
||||
|
|
|
|||
97
contribution/branches/PhyloMOEA/PhyloMOEA/functors.h
Normal file
97
contribution/branches/PhyloMOEA/PhyloMOEA/functors.h
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#ifndef _FUNCTORS_h
|
||||
#define _FUNCTORS_h
|
||||
|
||||
#include <functional>
|
||||
|
||||
/** Base class for functors to get a nice hierarchy diagram
|
||||
|
||||
That's actually quite an understatement as it does quite a bit more than
|
||||
just that. By having all functors derive from the same base class, we can
|
||||
do some memory management that would otherwise be very hard.
|
||||
|
||||
The memory management base class is called eoFunctorStore, and it supports
|
||||
a member add() to add a pointer to a functor. When the functorStore is
|
||||
destroyed, it will delete all those pointers. So beware: do not delete
|
||||
the functorStore before you are done with anything that might have been allocated.
|
||||
|
||||
@see eoFunctorStore
|
||||
|
||||
*/
|
||||
class FunctorBase
|
||||
{
|
||||
public :
|
||||
/// virtual dtor here so there is no need to define it in derived classes
|
||||
virtual ~FunctorBase() {}
|
||||
};
|
||||
|
||||
/**
|
||||
Basic Function. Derive from this class when defining
|
||||
any procedure. It defines a result_type that can be used
|
||||
to determine the return type
|
||||
Argument and result types can be any type including void for
|
||||
result_type
|
||||
**/
|
||||
template <class R>
|
||||
class Functor : public FunctorBase
|
||||
{
|
||||
public :
|
||||
|
||||
/// virtual dtor here so there is no need to define it in derived classes
|
||||
virtual ~Functor() {}
|
||||
|
||||
/// the return type - probably useless ....
|
||||
typedef R result_type;
|
||||
|
||||
/// The pure virtual function that needs to be implemented by the subclass
|
||||
virtual R operator()() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Basic Unary Functor. Derive from this class when defining
|
||||
any unary function. First template argument is the first_argument_type,
|
||||
second result_type.
|
||||
Argument and result types can be any type including void for
|
||||
result_type
|
||||
**/
|
||||
template <class A1, class R>
|
||||
class FunctorUnary : public FunctorBase, public std::unary_function<A1, R>
|
||||
{
|
||||
public :
|
||||
|
||||
/// virtual dtor here so there is no need to define it in derived classes
|
||||
virtual ~FunctorUnary() {}
|
||||
|
||||
/// The pure virtual function that needs to be implemented by the subclass
|
||||
virtual R operator()(A1) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Basic Binary Functor. Derive from this class when defining
|
||||
any binary function. First template argument is result_type, second
|
||||
is first_argument_type, third is second_argument_type.
|
||||
Argument and result types can be any type including void for
|
||||
result_type
|
||||
**/
|
||||
template <class A1, class A2, class R>
|
||||
class FunctorBinary : public FunctorBase, public std::binary_function<A1, A2, R>
|
||||
{
|
||||
public :
|
||||
/// virtual dtor here so there is no need to define it in derived classes
|
||||
virtual ~FunctorBinary() {}
|
||||
|
||||
//typedef R result_type;
|
||||
//typedef A1 first_argument_type;
|
||||
//typedef A2 second_argument_type;
|
||||
|
||||
/// The pure virtual function that needs to be implemented by the subclass
|
||||
virtual R operator()(A1, A2) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -86,7 +86,7 @@ LikelihoodCalculator::LikelihoodCalculator( phylotreeIND &ind, Sequences &Seqs,
|
|||
probmatrixs = &p;
|
||||
invalid_partials_taxons = true;
|
||||
set_data( Seqs);
|
||||
set_tree(ind);
|
||||
set_tree( ind );
|
||||
build_rates_sites();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue