From 468a87789f61d0f6e9fabd75a4d34ac19d1e686f Mon Sep 17 00:00:00 2001 From: Vincent Danjean <Vincent.Danjean@ens-lyon.org> Date: Wed, 21 Jun 2006 16:19:38 +0000 Subject: [PATCH] ajout de nanova.pm git-svn-id: svn+ssh://imag/users/huron/danjean/svnroot/claire/altree/trunk@201 cf695345-040a-0410-a956-b889e835fe2e --- ALTree/Nanova.pm | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ALTree/Nanova.pm diff --git a/ALTree/Nanova.pm b/ALTree/Nanova.pm new file mode 100644 index 0000000..c7a9db1 --- /dev/null +++ b/ALTree/Nanova.pm @@ -0,0 +1,60 @@ +package ALTree::Nanova; + +use strict; + +BEGIN { + use Exporter (); + use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + + # set the version for version checking + #$VERSION = 1.00; + # if using RCS/CVS, this may be preferred + #$VERSION = do { my @r = (q$Revision: 153 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker + + @ISA = qw(Exporter); + @EXPORT = qw(); #(&func1 &func2 &func4); + %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], + + # your exported package globals go here, + # as well as any optionally exported functions + @EXPORT_OK = qw(); +} +use vars @EXPORT_OK; + +use ALTree::Utils qw(erreur); +use Data::Dumper; + + +# This function transforms the tree structure into the matrix used by the library NAnova + +sub Tree2mat +{ + my $present_node = shift; + my $vect = shift; # structure transitoire: chemin de la racine à une feuille + my $mat = shift; # The matrix which is filled by the function + + if ($present_node->NbChildren()==0) { + push (@{$mat}, $vect); + } else { + my $number=0; + for my $child ($present_node->GetChildrenList()) { + push(@{$vect}, $number); + $number ++; + Tree2mat($present_node, $vect, $mat); + } + } +} + +sub WriteMat +{ + my $mat = shift; + + for (my $i=0; $i<=$#$mat; $i++) { + foreach my $elem (@{$mat->[$i]}) { + print $elem, "\t"; + } + print "\n"; + } +} + +1; -- GitLab