From 75675fb66bbe12fdf9e4c692b1ddfc4e1fbe4f8d Mon Sep 17 00:00:00 2001 From: wcancino Date: Tue, 3 Feb 2009 14:33:04 +0000 Subject: [PATCH] Pack and unpack functions git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1394 331e1502-861f-0410-8da2-ba01fb791d7f --- .../PhyloMOEA/PhyloMOEO_packunpack.cpp | 69 +++++++++++++++++++ .../PhyloMOEA/PhyloMOEO_packunpack.h | 21 ++++++ 2 files changed, 90 insertions(+) create mode 100644 contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp create mode 100644 contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.h diff --git a/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp new file mode 100644 index 000000000..0ad7748c2 --- /dev/null +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.cpp @@ -0,0 +1,69 @@ +// +// C++ Implementation: PhyloMOEO_packunpack +// +// Description: +// +// +// Author: <>, (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include + +void pack( PhyloMOEO & ind) +{ + cout << "packing individual" << endl; + phylotreeIND & tree = ind.get_tree(); + string s = tree.newick_traverse2( false, false); + ::pack(s); + + edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() ); + node root_traverse = edgeaux.opposite( tree.taxon_number(0) ); + 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 )]; + int top = tree.TREE.number_of_edges() -1; + // reverse order ..... for GTL internals + for( ; it!=it2; top--) + { + if( *it != root_traverse ) + + blens[top] = tree.get_branch_length( it.branch() ); + ++it; + } + for(int i=0; i< (2*tree.number_of_taxons() -3 ) ; i++) ::pack(blens[i]); + delete [] blens; + cout << "packing finished..." << endl; + //::pack(blens); +} + +void unpack( PhyloMOEO &ind ) +{ + cout << "unpacking individual" << endl; + phylotreeIND tree = ind.get_tree(); + + string newickstring; + ::unpack(newickstring); + + tree.read_newick2( newickstring ); + + edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() ); + node root_traverse = edgeaux.opposite( tree.taxon_number(0) ); + postorder_Iterator it = tree.postorder_begin( root_traverse ); + postorder_Iterator it2 = tree.postorder_end( root_traverse ); + //double blens[2*Tind->number_of_taxons() -3]; + + //MPI_Unpack(buffer, bufsize, pos, blens, 2*Tind->number_of_taxons() -3, MPI_DOUBLE, com); + // reverse order ..... for GTL internals + while(it!=it2) + { + double blen; + ::unpack(blen); + if( *it != root_traverse ) + tree.set_branch_length( it.branch(), blen ); + ++it; + } + cout << "unpacking finished..." << 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 new file mode 100644 index 000000000..4c554845c --- /dev/null +++ b/contribution/branches/PhyloMOEA/PhyloMOEA/PhyloMOEO_packunpack.h @@ -0,0 +1,21 @@ +// +// C++ Interface: PhyloMOEO_packunpack +// +// Description: +// +// +// Author: <>, (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef PHYLOMOEO_PACKUNPACK_H_ +#define PHYLOMOEO_PACKUNPACK_H_ +#include +#include + +void pack( PhyloMOEO &); +void unpack( PhyloMOEO & ); + +#endif +