I've rewritten it with Graph =), it now has more functionality with less code and is cleaner.. thanks again.
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"; }
In reply to Re^4: Array of hashes of Arrays
by thekestrel
in thread Array of hashes of Arrays
by thekestrel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |