Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Don't ask to ask, just ask
 
PerlMonks  

Graphs and Shortest Distance Between Nodes

by arunhorne (Pilgrim)
on Jul 18, 2002 at 18:33 UTC ( [id://183065]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

arunhorne has asked for the wisdom of the Perl Monks concerning the following question:

Monks...

I find myself needing to create a graph, as in a collection of nodes connected to one another by directed arcs. Despite the availability of suitable libraries in Java, I have no wish to turn away from Perl for this task. I have search CPAN and Google for a library to aid me with the following requirements but find the results to vague. Does anyone know/have any code snippets/modules that would allow me to:

  • Easily create a graph data structure in memory - i.e. some form of API to add nodes and connect them using directed edges.
  • Calculate the shortest (arcs are unweighted - i.e. constanst cost to traverse) distance between two arbitrary nodes.

Any suggestions are welcomed - the more ideas the better :)

Best wishes,

____________
Arun
  • Comment on Graphs and Shortest Distance Between Nodes

Replies are listed 'Best First'.
Re: Graphs and Shortest Distance Between Nodes
by thelenm (Vicar) on Jul 18, 2002 at 18:39 UTC
    There are some code snippets in the O'Reilly book Mastering Algorithms with Perl. All the example programs are available online here. Download "examples.tar.gz" or "examples.zip", and the examples you'll probably want will be in the "ch08" subdirectory. I don't know for sure that you'll find exactly what you need, but hopefully it will put you on the right track. Good luck!

    -- Mike

    --
    just,my${.02}

Re: Graphs and Shortest Distance Between Nodes
by kvale (Monsignor) on Jul 18, 2002 at 18:46 UTC
    The Graph::Directed module allows one to easily set up directed graphs and contains Dijkstra's algorithm for shortest paths.

    To understand what is going on under the hood, look at the chapter on graphs in the book "Mastering Algorithms in Perl" published by O'Reilly.

    -Mark

Re: Graphs and Shortest Distance Between Nodes
by FoxtrotUniform (Prior) on Jul 18, 2002 at 18:55 UTC
Re: Graphs and Shortest Distance Between Nodes
by larsen (Parson) on Jul 18, 2002 at 18:59 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://183065]
Approved by vagnerr
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.