diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp index a59d55b06..2db46165a 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEA.cpp @@ -29,7 +29,8 @@ string datafile,usertree, expid, path, algotype; double pcrossover, pmutation, kappa, alpha; unsigned int ngenerations, popsize, ncats; ofstream exp_data,evolution_data, best_media_scores, final_trees, final_pareto_trees, clades_pareto, clades_final,final_scores,pareto_scores; - +LikelihoodCalculator *lik_calc_ptr; +phylotreeIND *templatetree_ptr; int main(int argc, char *argv[]) @@ -81,6 +82,7 @@ int main(int argc, char *argv[]) rn2 = gsl_rng_alloc(gsl_rng_default); rn = new RandomNr(seed); phylotreeIND templatetree( rn, seq, rn2); + templatetree_ptr = &templatetree; ParsimonyCalculator parsi_calc(templatetree); SubstModel modelHKY( seq, SubstModel::HKY85); modelHKY.init(); @@ -89,14 +91,18 @@ int main(int argc, char *argv[]) LikelihoodCalculator lik_calc(templatetree, modelHKY, probmatrixs,ncats); lik_calc.set_alpha(alpha); modelHKY.init(); + PhyloEval byobj( parsi_calc, lik_calc ); Phyloraninit initializer(templatetree); eoPop population(popsize, initializer); + peoMoeoPopEval eval(byobj); + // Only the master node read the initial trees and writes ouput files if(getNodeRank()==1) { + cout << "\n\nReading Initial Trees..."; if( usertree.size() >0) { @@ -183,7 +189,7 @@ int main(int argc, char *argv[]) if(algotype == "ibea") { moeoAdditiveEpsilonBinaryMetric < ObjectiveVector > metric; - moeoIBEA < PhyloMOEO > algo (cp, byobj, operadores, metric); + moeoIBEA < PhyloMOEO > algo (cp, eval, operadores, metric); if(getNodeRank()==1){ cout << "\n\nRunning IBEA ..." << endl; } peoWrapper parallelEA( algo, population); @@ -194,7 +200,7 @@ int main(int argc, char *argv[]) } else { - moeoNSGAII < PhyloMOEO > algo (cp, byobj, operadores); + moeoNSGAII < PhyloMOEO > algo (cp, eval, operadores); if(getNodeRank()==1){ cout << "\n\nRunning NSGA-II ..." << endl; } peoWrapper parallelEA( algo, population); @@ -218,12 +224,29 @@ int main(int argc, char *argv[]) cout << "\nCalculating Final Solutions..."; cout << " done\n"; - PhyloMOEOFinalSolutionsArchive finalsolutions; - finalsolutions.operator()(population); + } + + PhyloMOEOFinalSolutionsArchive finalsolutions; + if(getNodeRank()==1)finalsolutions.operator()(population); + //cout << "en el nodo " << getNodeRank() << " popsize " << population.size() << endl; + //cout << "en el nodo " << getNodeRank() << " archsize " << finalsolutions.size() << endl; + //finalsolutions[0].get_tree().printNewick(cout); + lik_calc_ptr = &lik_calc; + // make the optimization phase also in parallel + peo :: init (argc, argv); + peoMultiStart ParallelLKOptimizationInit (optimize_solution); + peoWrapper ParallelLKOptimization (ParallelLKOptimizationInit, finalsolutions); + ParallelLKOptimizationInit.setOwner(ParallelLKOptimization); + if (getNodeRank()==1) cout << "\nOptimizing tree branch lenghts...\n"; + peo :: run( ); + peo :: finalize( ); + + if (getNodeRank()==1) + { //remove_final_solutions( population ); // optimize remaining solutions - cout << "\nOptimizing tree branch lenghts...\n"; + //optimize_solutions( finalsolutions, lik_calc ); cout << "\nReevaluating individuals \n"; diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_eval.h b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_eval.h index b80fe30be..5c3c88b2f 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_eval.h +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_eval.h @@ -23,6 +23,8 @@ #include #include #include +//#include +#include class PhyloEval : public moeoEvalFunc < PhyloMOEO > { @@ -32,8 +34,9 @@ public: void operator () (PhyloMOEO & _sol) { - if (_sol.invalidObjectiveVector()) - { + //cout << "hello im evaluating in the node " << getNodeRank() << endl; + //if (_sol.invalidObjectiveVector()) + //{ ObjectiveVector objVec; //if(! (_sol.get_tree().splits_valid() ) ) _sol.get_tree().calculate_splits(); @@ -44,7 +47,7 @@ public: objVec[0] = parseval.fitch(); objVec[1] = -likeval.calculate_likelihood(); _sol.objectiveVector(objVec); - } + //} } private: diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp index 0ad7748c2..8e53c3fb7 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp @@ -14,13 +14,14 @@ void pack( PhyloMOEO & ind) { - cout << "packing individual" << endl; + //cout << "packing individual" << endl; phylotreeIND & tree = ind.get_tree(); - string s = tree.newick_traverse2( false, false); + string s = tree.newick_traverse2( true, false); + ::pack(s); - - edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() ); + /*edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() ); node root_traverse = edgeaux.opposite( tree.taxon_number(0) ); + //tree.convert_graph_to_tree( root_traverse, NULL); postorder_Iterator it = tree.postorder_begin( root_traverse ); postorder_Iterator it2 = tree.postorder_end( root_traverse ); double *blens = new double[(2*tree.number_of_taxons() -3 )]; @@ -34,23 +35,29 @@ void pack( PhyloMOEO & ind) ++it; } for(int i=0; i< (2*tree.number_of_taxons() -3 ) ; i++) ::pack(blens[i]); - delete [] blens; - cout << "packing finished..." << endl; + delete [] blens; + + /*cout << "\nenviado " << endl; + cout << tree.newick_traverse2(false,false) << endl;*/ + + //cout << "packing finished..." << endl; //::pack(blens); } void unpack( PhyloMOEO &ind ) { - cout << "unpacking individual" << endl; - phylotreeIND tree = ind.get_tree(); - + //cout << "unpacking individual" << endl; string newickstring; ::unpack(newickstring); - + //cout << newickstring << endl; + ind.set_tree_template( *templatetree_ptr); + phylotreeIND &tree = ind.get_tree(); + tree.read_newick2( newickstring ); - - edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() ); + ind.invalidate(); + /*edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() ); node root_traverse = edgeaux.opposite( tree.taxon_number(0) ); + tree.convert_graph_to_tree( root_traverse, NULL); postorder_Iterator it = tree.postorder_begin( root_traverse ); postorder_Iterator it2 = tree.postorder_end( root_traverse ); //double blens[2*Tind->number_of_taxons() -3]; @@ -60,10 +67,15 @@ void unpack( PhyloMOEO &ind ) while(it!=it2) { double blen; - ::unpack(blen); if( *it != root_traverse ) + { + ::unpack(blen); tree.set_branch_length( it.branch(), blen ); + } ++it; - } - cout << "unpacking finished..." << endl; + } + /*cout << "\n unpacking finished..." << endl; + cout << "recibido \n" << endl; + cout << newickstring << endl; + cout << tree.newick_traverse2(false,false) << endl; */ } \ No newline at end of file diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.h b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.h index 4c554845c..8a1368888 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.h +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.h @@ -14,6 +14,7 @@ #include #include +extern phylotreeIND * templatetree_ptr; void pack( PhyloMOEO &); void unpack( PhyloMOEO & ); diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/utils.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA/utils.cpp index 17b1818be..fa3eda77a 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/utils.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/utils.cpp @@ -33,6 +33,7 @@ extern long seed; extern string datafile,usertree, expid, path; extern double pcrossover, pmutation, kappa, alpha; extern unsigned int ngenerations, popsize, ncats; +extern LikelihoodCalculator *lik_calc_ptr; void welcome_message() { @@ -62,17 +63,19 @@ void save_exp_params(ostream &of=cout) -void optimize_solutions( eoPop &pop, LikelihoodCalculator &lik_calc) +void optimize_solutions( eoPop &pop) { + cout << "entrando a optimize_solutions con " << pop.size() << " arvores " << endl; int n = pop.size(); + for(int i=0; iset_tree(sol); cout << "\noptimizaing tree " << i+1 << " of " << n; // cout << endl << "likelihood inicial:" << lik_calc->calculate_likelihood() << endl; - Newton_LikOptimizer test(lik_calc); - test.optimize(); + Newton_LikOptimizer test(*lik_calc_ptr); + //test.optimize(); pop[i].invalidate(); //lik_calc->maximizelikelihood(); @@ -83,6 +86,23 @@ void optimize_solutions( eoPop &pop, LikelihoodCalculator &lik_calc) } +void optimize_solution( PhyloMOEO &indi) +{ + phylotreeIND &sol = indi.get_tree(); + lik_calc_ptr->set_tree(sol); + //cout << "\noptimizaing tree " << i+1 << " of " << n; +// cout << endl << "likelihood inicial:" << lik_calc->calculate_likelihood() << endl; + Newton_LikOptimizer test(*lik_calc_ptr); + test.optimize(); + indi.invalidate(); + //pop[i].invalidate(); + //lik_calc->maximizelikelihood(); + //lik_calc->set_tree(*sol); +// lik_calc->set_tree( *sol); +// cout << endl << "likelihood final:" << lik_calc->calculate_likelihood() << endl; + //} +} + void readtrees(const char *fname, eoPop &poptree) { int ntrees; diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/utils.h b/contribution/branches/PhyloMOEA/PhyloMOEA/utils.h index eb9f11077..a276151c8 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA/utils.h +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/utils.h @@ -28,7 +28,8 @@ void welcome_message(); void save_exp_params(ostream &); -void optimize_solutions( eoPop &, LikelihoodCalculator &); +void optimize_solutions( eoPop &); +void optimize_solution( PhyloMOEO &); void readtrees(const char *, eoPop &); #endif