From 8aa685d740ae221f5208361bafe6d11c95e37fac Mon Sep 17 00:00:00 2001 From: wcancino Date: Mon, 22 Jun 2009 15:55:55 +0000 Subject: [PATCH] Insert commit message here git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1589 331e1502-861f-0410-8da2-ba01fb791d7f --- .../PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp | 2 + .../PhyloMOEA/PhyloMOEA/SplitCalculator.h | 109 ++++++++++++++++++ .../PhyloMOEA/PhyloMOEA/SubsModel.cpp | 4 +- .../branches/PhyloMOEA/PhyloMOEA/functors.h | 97 ++++++++++++++++ .../PhyloMOEA/likelihoodcalculator.cpp | 2 +- 5 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 contribution/branches/PhyloMOEA/PhyloMOEA/SplitCalculator.h create mode 100644 contribution/branches/PhyloMOEA/PhyloMOEA/functors.h diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp index 74c809017..fba7bd127 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/SplitCalculator.h b/contribution/branches/PhyloMOEA/PhyloMOEA/SplitCalculator.h new file mode 100644 index 000000000..5fd8d0e1e --- /dev/null +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/SplitCalculator.h @@ -0,0 +1,109 @@ +#ifndef _SPLITCALCULATOR_H_ +#define _SPLITCALCULATOR_H_ + +#include + +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 +{ + +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 interior_node(tree.TREE, NULL); + edge_map 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; ileft = 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 \ No newline at end of file diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/SubsModel.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA/SubsModel.cpp index ac66efc27..43b498bc3 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/SubsModel.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/SubsModel.cpp @@ -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); diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/functors.h b/contribution/branches/PhyloMOEA/PhyloMOEA/functors.h new file mode 100644 index 000000000..8ec81c065 --- /dev/null +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/functors.h @@ -0,0 +1,97 @@ +#ifndef _FUNCTORS_h +#define _FUNCTORS_h + +#include + +/** 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 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 FunctorUnary : public FunctorBase, public std::unary_function +{ +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 FunctorBinary : public FunctorBase, public std::binary_function +{ +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 diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/likelihoodcalculator.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA/likelihoodcalculator.cpp index 22399699b..de32c549f 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/likelihoodcalculator.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/likelihoodcalculator.cpp @@ -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(); }