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"; }

In reply to Re^4: Array of hashes of Arrays by thekestrel
in thread Array of hashes of Arrays by thekestrel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.