diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/CMakeLists.txt b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/CMakeLists.txt index 298586c70..9a5a32ddf 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/CMakeLists.txt +++ b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/CMakeLists.txt @@ -32,6 +32,6 @@ SET( PHYLOMOEA_SOURCES eigensolver.cpp ADD_EXECUTABLE( PhyloMOEA-serial ${PHYLOMOEA_SOURCES} ) -TARGET_LINK_LIBRARIES(PhyloMOEA gsl gslcblas GTL eo eoutils ga moeo cma) +TARGET_LINK_LIBRARIES(PhyloMOEA-serial gsl gslcblas GTL eo eoutils ga moeo cma) -INSTALL( TARGETS PhyloMOEA RUNTIME DESTINATION bin) \ No newline at end of file +INSTALL( TARGETS PhyloMOEA-serial RUNTIME DESTINATION bin) diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/PhyloMOEA.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/PhyloMOEA.cpp index 1bac93848..7a4f36a8e 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/PhyloMOEA.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/PhyloMOEA.cpp @@ -22,7 +22,7 @@ RandomNr *rn; //Sequences *seq; long seed; //vector arbores; -string datafile,usertree, expid, path, algotype; +string datafile,usertree, expid, path, algotype, optimize_branch; 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; @@ -30,6 +30,9 @@ ofstream exp_data,evolution_data, best_media_scores, final_trees, final_pareto_t int main(int argc, char *argv[]) { + struct timeval tempo1, tempo2, result; + gettimeofday(&tempo1, NULL); + welcome_message(); eoParser parser(argc, argv); @@ -48,6 +51,7 @@ int main(int argc, char *argv[]) usertree = parser.createParam(string(), "treef", "Treefile", 't',"Param").value(); path = parser.createParam(string(), "path", "Treefile", 'p',"Param").value(); algotype = parser.createParam(string("nsgaii"), "algo", "Algorith, Type", 'b',"Param").value(); + optimize_branch = parser.createParam(string("yes"), "opt", "Optimize Branch Lenght", 'o',"Param").value(); ostringstream convert; convert << seed; expid = parser.createParam(convert.str(), "expid", "Experiment ID", 'e',"Param").value(); @@ -184,7 +188,7 @@ int main(int argc, char *argv[]) // optimize remaining solutions cout << "\nOptimizing tree branch lenghts...\n"; - optimize_solutions( finalsolutions, lik_calc ); + if(optimize_branch=="yes")optimize_solutions( finalsolutions, lik_calc ); cout << "\nReevaluating individuals \n"; apply ( byobj, finalsolutions ); @@ -214,8 +218,8 @@ int main(int argc, char *argv[]) // remove dominate solutions cout << "\nCalculating Pareto-optimal Solutions..."; - PhyloMOEOParetoSolutionsArchive paretosolutions; - paretosolutions.operator()(finalsolutions); + PhyloMOEOParetoSolutionsArchive paretosolutions; + paretosolutions.operator()(finalsolutions); paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores"); paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt"); cout << " done\n"; @@ -244,6 +248,8 @@ int main(int argc, char *argv[]) // delete probmatrixs; delete rn; cout << "\nPhyloMOEA execution finishes !\n"; + gettimeofday(&tempo2, NULL); + print_elapsed_time(&tempo1,&tempo2); return 0; } diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.cpp index 4a3c5e057..cf90078c7 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.cpp +++ b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.cpp @@ -34,6 +34,66 @@ extern string datafile,usertree, expid, path; extern double pcrossover, pmutation, kappa, alpha; extern unsigned int ngenerations, popsize, ncats; +int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y) +{ +/* Perform the carry for the later subtraction by updating y. */ + if (x->tv_usec < y->tv_usec) { + int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; + y->tv_usec -= 1000000 * nsec; + y->tv_sec += nsec; + } + + if (x->tv_usec - y->tv_usec > 1000000) { + int nsec = (x->tv_usec - y->tv_usec) / 1000000; + y->tv_usec += 1000000 * nsec; + y->tv_sec -= nsec; + } + + /* Compute the time remaining to wait. + tv_usec is certainly positive. */ + result->tv_sec = x->tv_sec - y->tv_sec; + result->tv_usec = x->tv_usec - y->tv_usec; + + /* Return 1 if result is negative. */ + return x->tv_sec < y->tv_sec; +} + + +void print_elapsed_time(struct timeval *x, struct timeval *y) +{ + struct timeval result; + timeval_subtract(&result,y,x); + long remainder = result.tv_sec % 3600; + long hours = (result.tv_sec - remainder)/3600; + long seconds = remainder % 60; + long minutes = (remainder - seconds) / 60; + cout << "Execution time : "; + cout.width(3); + cout.fill(' '); + cout << hours << ":"; + cout.width(2); + cout.fill('0'); + cout << minutes << ":"; + cout.width(2); + cout.fill('0'); + cout << seconds << "." << result.tv_usec << "(" << result.tv_sec << ")" << endl; +} + +void print_elapsed_time_short(struct timeval *x, struct timeval *y, ostream &os) +{ + struct timeval result; + timeval_subtract(&result,y,x); + os << " " << result.tv_sec << "." << result.tv_usec; +} + + +void print_cpu_time(clock_t start, clock_t end) +{ + double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + cout << " " << cpu_time_used << " "; +} + + void welcome_message() { cout << "\nPhyloMOEA, a program for multi-criteria phylogenetic inference\n"; diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.h b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.h index eb9f11077..ce2ccc57e 100644 --- a/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.h +++ b/contribution/branches/PhyloMOEA/PhyloMOEA-serial/PhyloMOEA/utils.h @@ -30,5 +30,9 @@ void welcome_message(); void save_exp_params(ostream &); void optimize_solutions( eoPop &, LikelihoodCalculator &); void readtrees(const char *, eoPop &); +int timeval_subtract (struct timeval *, struct timeval *, struct timeval *); +void print_cpu_time(clock_t ,clock_t); +void print_elapsed_time(struct timeval *, struct timeval *); +void print_elapsed_time_short(struct timeval *, struct timeval *, ostream &os=cout); #endif