| 1 | package SNA::Network::Node; | ||||||||||
| 2 | |||||||||||
| 3 | 15 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 15 | ▶ | use List::Util qw(sum first); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 15 | ▶ | use Object::Tiny::XS qw(index community); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | 15 | ▶ | use Module::List::Pluggable qw(import_modules); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 15 | import_modules('SNA::Network::Node::Plugin'); | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | =head1 NAME | ||||||||||
| 15 | |||||||||||
| 16 | SNA::Network::Node - Node class for SNA::Network | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||
| 20 | |||||||||||
| 21 | my $node = $net->node_at_index(0); | ||||||||||
| 22 | my @neighbours = $node->related_nodes; | ||||||||||
| 23 | ... | ||||||||||
| 24 | ... | ||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | =head1 METHODS | ||||||||||
| 28 | |||||||||||
| 29 | =head2 new | ||||||||||
| 30 | |||||||||||
| 31 | Creates a new node with the given named parameters. | ||||||||||
| 32 | Not intended for external use. | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | sub new { | ||||||||||
| 37 | 660 | ▶ | my ($package, %params) = @_; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | 660 | return bless { %params, outgoing_edges => [], incoming_edges => [] }, $package; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | =head2 index | ||||||||||
| 43 | |||||||||||
| 44 | Returns the index of the node | ||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | =head2 edges | ||||||||||
| 48 | |||||||||||
| 49 | Returns the list of L<SNA::Network::Edge> objects associated with this node. | ||||||||||
| 50 | |||||||||||
| 51 | =cut | ||||||||||
| 52 | |||||||||||
| 53 | sub edges { | ||||||||||
| 54 | 1491 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
edges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 55 | #FIXME why does that not work??? | ||||||||||
| 56 | 1491 | return map { $_ } $self->outgoing_edges, $self->incoming_edges; | |||||||||
| 57 | # return($self->outgoing_edges, $self->incoming_edges); | ||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | =head2 related_nodes | ||||||||||
| 62 | |||||||||||
| 63 | Returns the list of L<SNA::Network::Node> objects that are linked to this node in any direction via an edge. | ||||||||||
| 64 | |||||||||||
| 65 | =cut | ||||||||||
| 66 | |||||||||||
| 67 | sub related_nodes { | ||||||||||
| 68 | 1103 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
related_nodes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 69 | 1103 | return (map { $_->source } $self->incoming_edges), map { $_->target } $self->outgoing_edges; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | =head2 incoming_edges | ||||||||||
| 74 | |||||||||||
| 75 | Returns the list of L<SNA::Network::Edge> objects that point to this node. | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | sub incoming_edges { | ||||||||||
| 80 | 3807 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
incoming_edges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 81 | 3807 | return @{ $self->{incoming_edges} }; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | =head2 incoming_nodes | ||||||||||
| 86 | |||||||||||
| 87 | Returns the list of L<SNA::Network::Node> objects that point to this node via an edge. | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||
| 90 | |||||||||||
| 91 | sub incoming_nodes { | ||||||||||
| 92 | 90 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
incoming_nodes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 93 | 90 | return map { $_->source } $self->incoming_edges; | |||||||||
| 94 | |||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | |||||||||||
| 98 | =head2 outgoing_edges | ||||||||||
| 99 | |||||||||||
| 100 | Returns the list of L<SNA::Network::Edge> objects pointing from this node to other nodes. | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | sub outgoing_edges { | ||||||||||
| 105 | 22508 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
outgoing_edges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 106 | 22508 | return @{ $self->{outgoing_edges} }; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | |||||||||||
| 110 | =head2 outgoing_nodes | ||||||||||
| 111 | |||||||||||
| 112 | Returns the list of L<SNA::Network::Node> objects that this node points to via an edge. | ||||||||||
| 113 | |||||||||||
| 114 | =cut | ||||||||||
| 115 | |||||||||||
| 116 | sub outgoing_nodes { | ||||||||||
| 117 | 18669 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
outgoing_nodes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 118 | 18669 | return map { $_->target } $self->outgoing_edges; | |||||||||
| 119 | |||||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | =head2 in_degree | ||||||||||
| 124 | |||||||||||
| 125 | Returns the in-degree of this node, i.e. the number of incoming edges. | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||
| 128 | |||||||||||
| 129 | sub in_degree { | ||||||||||
| 130 | 9 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
in_degree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 131 | 9 | return int $self->incoming_edges; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | |||||||||||
| 135 | =head2 out_degree | ||||||||||
| 136 | |||||||||||
| 137 | Returns the out-degree of this node, i.e. the number of outgoing edges. | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | sub out_degree { | ||||||||||
| 142 | 77 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
out_degree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 143 | 77 | return int $self->outgoing_edges; | |||||||||
| 144 | } | ||||||||||
| 145 | |||||||||||
| 146 | |||||||||||
| 147 | =head2 summed_degree | ||||||||||
| 148 | |||||||||||
| 149 | Returns the summed degree of this node, i.e. the number of associated edges. | ||||||||||
| 150 | |||||||||||
| 151 | =cut | ||||||||||
| 152 | |||||||||||
| 153 | sub summed_degree { | ||||||||||
| 154 | 2 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
summed_degree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 155 | 2 | return int $self->edges; | |||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | |||||||||||
| 159 | =head2 weighted_in_degree | ||||||||||
| 160 | |||||||||||
| 161 | Returns the weighted in-degree of this node, i.e. the sum of all incoming edge weights. | ||||||||||
| 162 | |||||||||||
| 163 | =cut | ||||||||||
| 164 | |||||||||||
| 165 | sub weighted_in_degree { | ||||||||||
| 166 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
weighted_in_degree: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 167 | 0 | ▶ | return 0 unless $self->incoming_edges; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 168 | 0 | return sum map { $_->weight } $self->incoming_edges; | |||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | |||||||||||
| 172 | =head2 weighted_out_degree | ||||||||||
| 173 | |||||||||||
| 174 | Returns the weighted out-degree of this node, i.e. the sum of all outgoing edge weights. | ||||||||||
| 175 | |||||||||||
| 176 | =cut | ||||||||||
| 177 | |||||||||||
| 178 | sub weighted_out_degree { | ||||||||||
| 179 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
weighted_out_degree: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 180 | 0 | ▶ | return 0 unless $self->outgoing_edges; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 181 | 0 | return sum map { $_->weight } $self->outgoing_edges; | |||||||||
| 182 | } | ||||||||||
| 183 | |||||||||||
| 184 | |||||||||||
| 185 | =head2 weighted_summed_degree | ||||||||||
| 186 | |||||||||||
| 187 | Returns the summed weighted degree of this node, | ||||||||||
| 188 | i.e. the sum of all incoming and all outgoing edgeweights. | ||||||||||
| 189 | |||||||||||
| 190 | =cut | ||||||||||
| 191 | |||||||||||
| 192 | sub weighted_summed_degree { | ||||||||||
| 193 | 190 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
weighted_summed_degree: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 194 | 190 | ▶ | return 0 unless $self->edges; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 195 | 190 | return sum map { $_->weight() } $self->edges; | |||||||||
| 196 | } | ||||||||||
| 197 | |||||||||||
| 198 | |||||||||||
| 199 | =head2 loop | ||||||||||
| 200 | |||||||||||
| 201 | Returns the L<SNA::Network::Edge> object that connects this node with itself, a so-called loop, it such one exitst. Otherwise returns C<undef>. | ||||||||||
| 202 | |||||||||||
| 203 | =cut | ||||||||||
| 204 | |||||||||||
| 205 | sub loop { | ||||||||||
| 206 | 54 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
loop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 207 | 54 | ▶ | return first { $_->target == $self } $self->outgoing_edges; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 208 | } | ||||||||||
| 209 | |||||||||||
| 210 | |||||||||||
| 211 | =head2 community | ||||||||||
| 212 | |||||||||||
| 213 | Returns the index of the community the node belongs to after community identification by L<SNA::Network::Algorithm::Louvain> | ||||||||||
| 214 | |||||||||||
| 215 | |||||||||||
| 216 | |||||||||||
| 217 | =head1 AUTHOR | ||||||||||
| 218 | |||||||||||
| 219 | Darko Obradovic, C<< <dobradovic at gmx.de> >> | ||||||||||
| 220 | |||||||||||
| 221 | =head1 BUGS | ||||||||||
| 222 | |||||||||||
| 223 | Please report any bugs or feature requests to C<bug-sna-network-node at rt.cpan.org>, or through | ||||||||||
| 224 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SNA-Network>. I will be notified, and then you'll | ||||||||||
| 225 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 226 | |||||||||||
| 227 | |||||||||||
| 228 | |||||||||||
| 229 | |||||||||||
| 230 | =head1 SUPPORT | ||||||||||
| 231 | |||||||||||
| 232 | You can find documentation for this module with the perldoc command. | ||||||||||
| 233 | |||||||||||
| 234 | perldoc SNA::Network | ||||||||||
| 235 | |||||||||||
| 236 | |||||||||||
| 237 | You can also look for information at: | ||||||||||
| 238 | |||||||||||
| 239 | =over 4 | ||||||||||
| 240 | |||||||||||
| 241 | =item * RT: CPAN's request tracker | ||||||||||
| 242 | |||||||||||
| 243 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SNA-Network> | ||||||||||
| 244 | |||||||||||
| 245 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 246 | |||||||||||
| 247 | L<http://annocpan.org/dist/SNA-Network> | ||||||||||
| 248 | |||||||||||
| 249 | =item * CPAN Ratings | ||||||||||
| 250 | |||||||||||
| 251 | L<http://cpanratings.perl.org/d/SNA-Network> | ||||||||||
| 252 | |||||||||||
| 253 | =item * Search CPAN | ||||||||||
| 254 | |||||||||||
| 255 | L<http://search.cpan.org/dist/SNA-Network> | ||||||||||
| 256 | |||||||||||
| 257 | =back | ||||||||||
| 258 | |||||||||||
| 259 | |||||||||||
| 260 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 261 | |||||||||||
| 262 | |||||||||||
| 263 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 264 | |||||||||||
| 265 | Copyright 2009 Darko Obradovic, all rights reserved. | ||||||||||
| 266 | |||||||||||
| 267 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 268 | under the same terms as Perl itself. | ||||||||||
| 269 | |||||||||||
| 270 | |||||||||||
| 271 | =cut | ||||||||||
| 272 | |||||||||||
| 273 | 15 | 1; # End of SNA::Network::Node | |||||||||