I was experimenting with creating graphs in perl. No drawing involved, but simple graphs.
For example, imagine the start node A
Level 1 nodes are B1,B2
Level 3 nodes are C1,C2
Level 4 node is D
No all possible paths are
A-B1-C1-D
A-B1-C2-D
A-B2-C1-D
A-B2-C2-D
Now lets say I wanted a program to randomly create graphs.
So I would choose 4 levels or 5 levels etc.
The starting level would have just 1 node.
The subsequent levels can have 2-5 nodes(random, using rand() function.
Now lets say I wanted to print all possible paths in the format I listed above
I am wondering how to use perl for traversing all possible paths of the graph, and which is the fastest way to create a random graph.
I am leaning towards using hashes
My nodes can be identified by levels A,B,C,D... and so on
Then the hash can be node.B.1, node.B.2., node.B.3
The upper limit is controlled by rand() function.
I guess this is the right way.
After creating the hashes for all the nodes, I have to create paths, infact all possible paths, and print them as
A-B1-C2-D and so on etc.,
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.