arunhorne has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I'm having a few teething problems with the Graph::Directed module and was hoping someone could put me straight.
First up I want to label the edges in my directed graph, but not with a weight but just a textual label (i.e. E1--A-->E1 such that vertices E1 and E2 are connected by the edge A). Thus when I come to do a search through the graph for the shortest path between 2 nodes I can see which edges were travelled along. (Will this even be possible with Graph::Directed?)
My second problem is finding out how many vertices/edges are in my graph for verification purposes. The documentation notes I can use $G->has_vertices(@v) in scalar context, this is fine but what is the @V for??
I've posted my code below... it works fine but I need to add the features I described above. Vertices are created implicitly by the add_edge method. Don't worry about the duplicate self-referencing edges (what a mouthful!) - once each has been given an individual label, for example, E3 will be self referenced by three distinct edges (rather than the three anonymous and thus identical edges created by my code) - this is a feature of the problem domain I am handling and not something I have control over. Code below:
use Graph::Directed; use warnings; use strict; # Instantiate my $G = new Graph::Directed; my @V = (); # Create graph $G = $G->add_edge("E1", "E2"); $G = $G->add_edge("E3", "E3"); $G = $G->add_edge("E3", "E2"); $G = $G->add_edge("E3", "E1"); $G = $G->add_edge("E2", "E2"); $G = $G->add_edge("E2", "E2"); $G = $G->add_edge("E2", "E2"); $G = $G->add_edge("E3", "E3"); $G = $G->add_edge("E3", "E3"); # Print some info about graph print $G, "\n";
Looking forward to your words of wisdom, best wishes,
____________
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: New User to Graph::Directed Seeks Help!!
by amphiplex (Monk) on Jul 19, 2002 at 09:05 UTC |