I guess it's just me, but last time I needed to do something like this (verify that there were no cycles in macro definitions), Graph let concentrate on what I wanted to do and let me forget about the nit-picky graph management.

Then again, I have written an AVL tree implementation in FORTRAN, so I shouldn't talk too much about doing things the hard way.

I'd implement something like this:

Create root-node hash Current level is zero Establish limits: max & min nodes per level, number of levels root{A0} = add_levels($current_level, $level_limit, $min_nodes, $max_n +odes); sub add_levels { return if current level is > the limit, bump it if not calculate a random number between high and low limit new_level = {}; for $n (0..$local_limit) { generate $name from level and $n new_level{$name} = add_levels($current_level, $limit, $min, $max +) } return $new_level; }
The printing code will be similar, but you'll instead pass a string down the recursive call tree, adding level names until you run out of levels, then printing it. The recursion plus the loop will automatically follow all paths for you.

I have written a program to do this but I'm not posting it; you'll learn a lot more if you follow this outline and write it yourself; as you don't want to handwave the details via Graph, I assume there's a reason for writing it yourself -- and me writing it for you won't teach you anywhere near as much.

I recommend running under the debugger, as you'll be able to x the growing data structure as you go along and see if it's working.


In reply to Re: GRAPH is too complicated for my needs. by pemungkah
in thread Print all possible paths in a graph and some graph creation too! by tsk1979

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.