Graph module and multiedge graphs

J

Jim Mozley

I am trying to use the graph module (Graph-0.20105) to implement a
multigraph representing a computer network. Where I am after some help
is in implementing a multiedge.

I can add an edge using:

$G = $G->add_edge($u, $v)

But when I have multiple redundent edges between the same $u and $v
there seems to be no way to manipulate the edges as discrete objects.

The add_edge method returns a graph object, if it returned an edge
object I could add an attribute to it.

After looking at the module source I have tried following the example of:

$G->add_weighted_edge($u, $w, $v, $a)

( although $a doesn't seemed to be used in the source ?)

So I've used:

$G->add_edge($u, $v);
$G->set_attribute('id', $u, $v, $w);

However, there is no way to specify a particular edge if there is more
than one between two vertices.

For instance if I use this:

#!/usr/local/bin/perl

use strict;
use warnings;

use Graph::Undirected;

my $G = Graph::Undirected->new;

my $u = 'west';
my $v = 'east';

# create two vertices with four edges between
for ( 1..4 ) {
$G = $G->add_edge( $u, $v );
$G->set_attribute( 'id', $u, $v, $_);
}

my @edges = $G->edges;
while ( my( $u, $v ) = splice( @edges, 0 ,2) ) {
print "ID: ", $G->get_attribute('id', $u, $v), "\n";
}

__END__

to add four interfaces with a unique ID I get the output:

ID: 4
ID: 4
ID: 4
ID: 4

Any suggestions as to how I can use the module to treat edges as unique?

Jim Mozley
 
A

Anno Siegel

Jim Mozley said:
I am trying to use the graph module (Graph-0.20105) to implement a
multigraph representing a computer network. Where I am after some help
is in implementing a multiedge.

I can add an edge using:

$G = $G->add_edge($u, $v)

But when I have multiple redundent edges between the same $u and $v
there seems to be no way to manipulate the edges as discrete objects.

If the module doesn't support multiple edges between nodes, the
only way I see is to duplicate (parts of) the node structure. Instead
of establishing two edges between "east" and "west", you'd have
otherwise indistinguishable pairs "east1", "east2" and "west1" "west2"
with single edges between each pair. Think of the complete (multi-)graph
as a multi-layered structure where each layer is a graph with at most
one edge between node pairs.

Whether that is an adequate solution, I don't know. A better one
would certainly be to find or write a multigraph module.

Anno
 
J

Jim Mozley

Anno said:
Whether that is an adequate solution, I don't know.

Not sure, but I'll think on it, thanks.
A better one
would certainly be to find or write a multigraph module.

I have just found a much earlier version of the Graph module that may do
what I need; it seems to have named edges. It is from 1998 though! I can
only assume this functionality was dropped at some point. Looks like I
need to find out more information about this change.

Thanks,

Jim Mozley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top