in reply to Re: generating a Tree from Array and find the best way
in thread generating a Tree from Array and find the best way
thx for the hint im now reading the Graph::Easy::Parser, and maybe my question is somkind of challenge for someone who is borred at the moment ;D
well the Graph thing looks good i made somthing quick and dirty
use Graph::Easy::Parser; my $parser = Graph::Easy::Parser->new(); my $graph = $parser->from_text( '[ 0 ] -> [ 1 ]'. '[ 1 ] -> [ 202 ]'. '[ 1 ] -> [ 300 ]'. '[ 1 ] -> [ 344 ]'. '[ 2 ] -> [ 3 ]'. '[ 3 ] -> [ 4 ]'. '[ 4 ] -> [ 202 ]'. '[ 4 ] -> [ 345 ]'. '[ 4 ] -> [ 5 ]'. '[ 4 ] -> [ 6 ]'. '[ 5 ] -> [ 440 ]'. '[ 5 ] -> [ 500 ]'. '[ 5 ] -> [ 505 ]'. '[ 5 ] -> [ 508 ]'. '[ 5 ] -> [ 6 ]'. '[ 6 ] -> [ 201 ]'. '[ 6 ] -> [ 503 ]'. '[ 6 ] -> [ 507 ]'. '[ 6 ] -> [ 7 ]'. '[ 7 ] -> [ 2 ]'. '[ 7 ] -> [ 200 ]'. '[ 7 ] -> [ 503 ]'. '[ 7 ] -> [ 507 ]'. '[ 200 ] -> [ 202 ]'. '[ 202 ] -> [ 2 ]'. '[ 202 ] -> [ 201 ]'. '[ 300 ] -> [ 2 ]'. '[ 300 ] -> [ 202 ]'. '[ 300 ] -> [ 344 ]'. '[ 300 ] -> [ 502 ]'. '[ 300 ] -> [ 506 ]'. '[ 344 ] -> [ 300 ]'. '[ 345 ] -> [ 4 ]'. '[ 440 ] -> [ 5 ]'. '[ 500 ] -> [ 5 ]'. '[ 502 ] -> [ 300 ]'. '[ 503 ] -> [ 6 ]'. '[ 505 ] -> [ 5 ]'. '[ 506 ] -> [ 300 ]'. '[ 507 ] -> [ 6 ]'. '[ 508 ] -> [ 6 ]'. '[ 507 ] -> [ 7 ]'. '[ 503 ] -> [ 7 ]' ); print $graph->as_ascii();
now i just need to do it automaticly because a few things needs to be clear when you have more then one connection it depends on the order of notes if its going trough or not
for exp if you switch the last 2 lines in the code it will generate an compiler error, so i need to figure out how to do it manually , but im in bed now in 4 h i need to get to work
thx again for the hintUPDATE 2so here is some more optimised version im atm writing som script that check all possible transitions and will link those who are same if the second pair is reversed as a double connection <-> and not as -> this save alot of lines in the tree, i find some eq testing for my second problem and will look this up but im not sure if i get it ;D
#!/usr/bin/perl use Graph::Easy::Parser; my $parser = Graph::Easy::Parser->new(); my $graph = $parser->from_text( "[ 0 ] -> [ 1 ]". "[ 1 ] -> [ 202 ]". "[ 1 ] -> [ 300 ]". "[ 1 ] -> [ 344 ]". "[ 300 ] <-> [ 344 ]". "[ 300 ] <-> [ 502 ]". "[ 300 ] <-> [ 506 ]". "[ 300 ] -> [ 2 ]". "[ 2 ] -> [ 3 ]". "[ 3 ] -> [ 4 ]". "[ 4 ] -> [ 5 ]". "[ 5 ] <-> [ 440 ]". "[ 5 ] <-> [ 500 ]". "[ 5 ] <-> [ 505 ]". "[ 5 ] -> [ 6 ]". "[ 5 ] -> [ 508 ]". "[ 508 ] -> [ 6 ]". "[ 6 ] <-> [ 503 ]". "[ 6 ] <-> [ 507 ]". "[ 6 ] -> [ 7 ]". "[ 7 ] <-> [ 503 ]". "[ 7 ] <-> [ 507 ]". "[ 7 ] -> [ 200 ]". "[ 200 ] -> [ 202 ]". "[ 202 ] -> [ 201 ]". "[ 6 ] -> [ 201 ]" ); print $graph->as_ascii();
|
|---|