in reply to using Graph::Undirected
If I understand what you said you wanted to do, it would not make sense to have more than two items in each "add_path" call. That is, if you had [ qw(a A B C)] instead, there would be edges from a to A to B to C, which is wrong. You want a bipartite graph, correct?use strict; use Graph::Undirected; use Data::Dumper; # Suppose list1 consists of the # edges to add. Lowercase is first # list, uppercase is second list. # a to A, B, C # b to C, D my @list1 = ( [ qw(a A) ], [ qw(a B) ], [ qw(a C) ], [ qw(b C) ], [ qw(b D) ]); my $g = new Graph::Undirected; foreach my $ids (@list1){ $g->add_path(@$ids); } $Data::Dumper::Indent = 1; print Data::Dumper->Dump([\$g], [qw(*g)]);
Or perhaps you want something different. If you have an edge between every list2 vertex that shares an id, you would need not only A to B to C, but also C to A, a cycle. Please clarify your question with a more complete example.
|
|---|