Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

creating multiple graphs programmatically

by Anonymous Monk
on Nov 10, 2004 at 15:17 UTC ( #406684=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Graph::Base, Graph::Undirected, and Graph::Writer::Dot explore and visualize a large electrical network. I need to be able to create multiple graphs based on information in the (flat) source files. I need to do something like this:
foreach $area (@areas) { $graph{$area} = Graph->new(); }
I've tried all the tricks I can think of with no joy. I get warnings when I try to add a vertex or an edge, not when I create the graphs. I'm stumped. Any suggestions welcome.

Comment on creating multiple graphs programmatically
Download Code
Re: creating multiple graphs programmatically
by Fletch (Chancellor) on Nov 10, 2004 at 15:39 UTC

    Your vreemflitzer's obviously clogged near the 3rd fetzer valve. Try Penzoil . . . no, make that Quaker State.

    (Maybe if you posted some actual code and the actual error messages you're getting someone could come up with something resembling a useful reply.)

Re: creating multiple graphs programmatically
by Util (Priest) on Nov 15, 2004 at 18:00 UTC

    Fletch is correct; by your own description, the only code that you posted is not the even the code that produces the warning. Please post more details. Often, when reducing large code to a concise example of a problem, you will find the solution yourself.

    That said, I can see a few possible problems.

    1. You mention Graph::Undirected, which implies that your graphs should be undirected, but your example code uses Graph->new(), which creates *directed* graphs.
    2. Graph::Writer::Dot does not correctly handle undirected graphs; it treats them as if they were directed. This will not produce any warning; it will just cause GraphViz to render the graph's edges with arrows. My casual testing indicates that this simple patch will correct the problem:
    3. You may be using the wrong syntax to invoke methods on the objects stored in the %graph hash. Here is a working example program, to demonstrate the syntax:

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://406684]
Approved by Courage
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (17)
As of 2014-07-22 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (116 votes), past polls