From b4a13a5df99a6a6724c5fcedca300cb40cd53ab8 Mon Sep 17 00:00:00 2001 From: Vincent Danjean <Vincent.Danjean@ens-lyon.org> Date: Wed, 21 Jun 2006 22:44:29 +0000 Subject: [PATCH] Correction de FillHeight Calcul de la matrice d'un arbre git-svn-id: svn+ssh://imag/users/huron/danjean/svnroot/claire/altree/trunk@202 cf695345-040a-0410-a956-b889e835fe2e --- ALTree/Nanova.pm | 47 +++++++++++++++++++++++++++++++++-------------- ALTree/Tree.pm | 10 ++++++---- altree | 5 ++--- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/ALTree/Nanova.pm b/ALTree/Nanova.pm index c7a9db1..503ee6e 100644 --- a/ALTree/Nanova.pm +++ b/ALTree/Nanova.pm @@ -29,26 +29,45 @@ use Data::Dumper; 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); - } + my $present_node = shift; + my @vect=(); # dernier chenin parcouru + my @mat; + my $height=$present_node->{"height"}; + + print STDERR "heigh=", $present_node->{"height"}, "\n"; + for (my $i=0; $i<$height; $i++) { + push(@vect, -1); } + + my $tree2mat; + $tree2mat = sub { + my $present_node = shift; + + if ($present_node->NbChildren()==0) { + for (my $i=$present_node->{"level"}; $i<$height; $i++) { + $vect[$i]++; + } + my @tab=@vect; + push (@mat, \@tab); + } else { + for my $child ($present_node->GetChildrenList()) { + $vect[$present_node->{"level"}]++; + $tree2mat->($child); + } + } + }; + $tree2mat->($present_node); + return \@mat; } sub WriteMat { + my $mat = shift; - + + print STDERR Dumper($mat); + + return; for (my $i=0; $i<=$#$mat; $i++) { foreach my $elem (@{$mat->[$i]}) { print $elem, "\t"; diff --git a/ALTree/Tree.pm b/ALTree/Tree.pm index ced0739..5e87779 100644 --- a/ALTree/Tree.pm +++ b/ALTree/Tree.pm @@ -183,15 +183,17 @@ sub FillHeight my $set_height; $set_height=sub { my($present_node)=shift; - my($height)=shift; + my($height)=0; my($child); - $height+=1; foreach $child (@{$present_node->{"children"}}) { - $set_height->($child, $height); + my $min_height=$set_height->($child)+1; + if ($min_height > $height) { + $height=$min_height; + } } $present_node->{"height"}=$height; }; - $set_height->($self->GetRoot(), 0); + $set_height->($self->GetRoot()); } sub GetLevel0 { diff --git a/altree b/altree index 689f33f..25e2957 100755 --- a/altree +++ b/altree @@ -1517,10 +1517,9 @@ sub main my @children=$racine->GetChildrenList(); { - my $vect=(); - my $mat=(); + my $mat; print "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n"; - ALTree::Nanova::Tree2mat($tree->GetRoot(),$vect, $mat); + $mat=ALTree::Nanova::Tree2mat($tree->GetRoot()); ALTree::Nanova::WriteMat($mat); -- GitLab