in reply to Re: Building Networks of Matches
in thread Building Networks of Matches
Slight variation that I was working on before having to attend a meeting. Use add_path rather than add_edges
use strict; use Graph; use Graph::Undirected; my $ud = Graph::Undirected->new(); while(<DATA>) { my @items = split(' '); if(@items <= 1) { $ud->add_vertex(@items); } else { $ud->add_path(@items); } } foreach my $connectedSet ($ud->strongly_connected_components) { print "Connected Nodes: " . join(',', @$connectedSet) . "\n"; } __DATA__ a b c d e f b g h i j k l m f z
Update: Modified code based on feedback. Have to handle the case where there is only one letter on a line. UNFORTUNATELY this cause it to lock on strongly_connected_components call.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Building Networks of Matches
by bowsie (Initiate) on Jan 11, 2005 at 20:20 UTC |