Subject: | bridges() sometimes returns empty list when isolated vertices present |
#!/usr/bin/perl
# The bridges call should return 1 bridge for this graph, but
# if there are isolated vertices, then sometimes it returns empty.
# The frequency of this happening goes up with the number of isolated
# vertices.
#
# Multiple calls within the same script always give the same result,
# but multiple runs of the script will produce different results.
# Problem maybe dependent on returned hash key order somewhere?
#
#
#run multiple times like:
=pod
run this script multiple times like:
$ for i in $(seq 1 10); do ./bridge_test.pl; done
0000000000
0000000000
1111111111
1111111111
0000000000
1111111111
0000000000
1111111111
1111111111
0000000000
=cut
# b1-a1 - a2 - b2
# \ / \ /
# c1 c2
use Graph;
$g = new Graph::Undirected;
$g->add_edges(qw(a1 b1 b1 c1 c1 a1 a2 b2 b2 c2 c2 a2 a1 a2));
$g->add_vertices(1..5);
foreach (1..10) {
print scalar($g->bridges);
}
print "\n";