in reply to Re^2: Array of hashes of Arrays
in thread Array of hashes of Arrays

but ultimately I need this to be fast so routing through an external nodule isn't ideal (not that my code is the pinnacle of fast execution).

Get it working, then get it fast. You have no idea how fast Graph is or isn't until you have tried it and benchmarked it. In fact, it may be so fast that you have no idea how you lived without it.

Further more, "routing through an external module" is no slower than using a module you wrote yourself. And, it may be faster for several reasons:

Try Graph. If it's not fast enough, I have a faster version that assumes one edge between each connected vertex. At least study the Graph code - at least it works.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^4: Array of hashes of Arrays
by thekestrel (Friar) on Feb 21, 2005 at 21:10 UTC
    Dragonchild

    I've rewritten it with Graph =), it now has more functionality with less code and is cleaner.. thanks again.


    Regards Paul
    use strict; use Graph; my $graph = Graph->new(); sub AddInput { my $name = $_[0]; $graph->set_vertex_attributes($name, { allow_inputs => "No", a +llow_outputs => "Yes" }); } sub AddOutput { my $name = $_[0]; $graph->set_vertex_attributes($name, { allow_inputs => "Yes", +allow_outputs => "No" }); } sub AddNeuron { my $name = $_[0]; $graph->set_vertex_attributes($name, { allow_inputs => "Yes", +allow_outputs => "Yes" }); } sub AddConnection { my ($from, $to, $weight) = @_; my $f = $graph->get_vertex_attribute($from, "allow_outputs"); my $t = $graph->get_vertex_attribute($to, "allow_inputs"); if ( $f eq "Yes" && $t eq "Yes" ) { $graph->add_weighted_edge($from,$to, $weight); } } AddInput("I1"); AddInput("I2"); AddNeuron("N1"); AddNeuron("N2"); AddNeuron("N3"); AddOutput("O1"); AddConnection("I1", "N1", int(rand(10)) ); AddConnection("I1", "N2", int(rand(10)) ); AddConnection("I1", "N3", int(rand(10)) ); AddConnection("I2", "N1", int(rand(10)) ); AddConnection("I2", "N2", int(rand(10)) ); AddConnection("I2", "N3", int(rand(10)) ); AddConnection("N1", "O1", int(rand(10)) ); AddConnection("N2", "O1", int(rand(10)) ); AddConnection("N3", "O1", int(rand(10)) ); print "$graph\n"; my @source = $graph->source_vertices(); foreach $a ( @source ) { print "source : $a\n"; }
Re^4: Array of hashes of Arrays
by thekestrel (Friar) on Feb 21, 2005 at 17:11 UTC
    Dragonchild,
    You are of course correct...=)... Thanks for the link to the Graph module I'll look into it =)
    Regards Paul.