blib/lib/SNA/Network/Algorithm/Connectivity.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 43 / 43 CC 5 SCAR 8.5
CC
5
Cov
100%
identify_weak_components
3.0
_weakly_expand_node
3.0
BEGIN
1.0
CRAP 2.3
« blib/lib/SNA/Network/Generator/MCMC.pm ↑ Summary blib/lib/SNA/Network/Community.pm »
1 package SNA::Network::Algorithm::Connectivity;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 require Exporter;
7 15 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 our @EXPORT = qw(identify_weak_components);
9  
10  
11 =head1 NAME
12  
13 SNA::Network::Algorithm::Connectivity - identify network components
14  
15  
16 =head1 SYNOPSIS
17  
18 use SNA::Network;
19  
20 my $net = SNA::Network->new();
21 $net->load_from_pajek_net($filename);
22 ...
23 my $number_of_weak_components = $net->identify_weak_components();
24  
25  
26 =head1 METHODS
27  
28 The following methods are added to L<SNA::Network>.
29  
30  
31 =head2 identify_weak_components
32  
33 Identifies the weak components in the graph.
34 All componets get an id, starting from 0 on.
35 Stores the component id under the hash entry B<weak_component_id> for each node object.
36 Returns the number of weak components found in the network.
37  
38 =cut
39  
40 sub identify_weak_components {
41 1 ▶ my ($self) = @_;
Subroutine identify_weak_components: called CC=3 SCAR=11.0
Pod documented
42
43 1 foreach ($self->nodes) {
44 7 undef $_->{weak_component_id};
45 }
46
47 1 my $weak_component_id = 0;
48 1 my @remainder = $self->nodes();
49 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
@remainder > 0 and do { do { _weakly_expand_node($remainder[0], $weak_component_id); $weak_component_id += 1; @remainder = grep({not defined $_->{"weak_component_id"};} @remainder) } } 2 1 3
50 3 _weakly_expand_node($remainder[0], $weak_component_id);
51 3 $weak_component_id += 1;
52 3 @remainder = grep { !defined $_->{weak_component_id} } @remainder;
53 } while (@remainder > 0);
54
55 1 return $weak_component_id;
56 }
57  
58  
59 sub _weakly_expand_node {
60 3 ▶ my ($node, $weak_component_id) = @_;
Subroutine _weakly_expand_node: called CC=3 SCAR=11.0
61
62 3 $node->{weak_component_id} = $weak_component_id;
63 3 my @to_expand = ($node);
64  
65 3 ▶ while (@to_expand) {
Branch: 1 branch
BranchTrueFalseTotal
if (@to_expand) 7 3 10
66 7 my $next_node = shift @to_expand;
67 7 my @unassigned_related_nodes = grep { !defined $_->{weak_component_id} } $next_node->related_nodes();
68 7 foreach (@unassigned_related_nodes) {
69 4 $_->{weak_component_id} = $weak_component_id;
70 }
71 7 push @to_expand, @unassigned_related_nodes;
72 }
73 }
74  
75  
76 =head1 AUTHOR
77  
78 Darko Obradovic, C<< <dobradovic at gmx.de> >>
79  
80 =head1 BUGS
81  
82 Please report any bugs or feature requests to C<bug-sna-network-node at rt.cpan.org>, or through
83 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SNA-Network>. I will be notified, and then you'll
84 automatically be notified of progress on your bug as I make changes.
85  
86  
87  
88  
89 =head1 SUPPORT
90  
91 You can find documentation for this module with the perldoc command.
92  
93 perldoc SNA::Network
94  
95  
96 You can also look for information at:
97  
98 =over 4
99  
100 =item * RT: CPAN's request tracker
101  
102 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SNA-Network>
103  
104 =item * AnnoCPAN: Annotated CPAN documentation
105  
106 L<http://annocpan.org/dist/SNA-Network>
107  
108 =item * CPAN Ratings
109  
110 L<http://cpanratings.perl.org/d/SNA-Network>
111  
112 =item * Search CPAN
113  
114 L<http://search.cpan.org/dist/SNA-Network>
115  
116 =back
117  
118  
119 =head1 ACKNOWLEDGEMENTS
120  
121  
122 =head1 COPYRIGHT & LICENSE
123  
124 Copyright 2009 Darko Obradovic, all rights reserved.
125  
126 This program is free software; you can redistribute it and/or modify it
127 under the same terms as Perl itself.
128  
129  
130 =cut
131  
132 15 1; # End of SNA::Network::Algorithm::Connectivity
133  
« blib/lib/SNA/Network/Generator/MCMC.pm ↑ Summary blib/lib/SNA/Network/Community.pm »