| 1 | package Algorithm::Networksort::Chooser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.110'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use common::sense; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Math::Combinatorics; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub silence_carps { | ||||||||||||||||||||||||||
|
Subroutine
silence_carps: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | local *Algorithm::Networksort::carp = sub {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | shift->(); | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub build_selection_network { | ||||||||||||||||||||||||||
|
Subroutine
build_selection_network: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | my ($network, $selection) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $pinned = {}; | |||||||||||||||||||||||||||
| 23 | 0 | $pinned->{$_} = 1 foreach (@$selection); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my @reversed_network = reverse @$network; | |||||||||||||||||||||||||||
| 26 | 0 | my @reversed_output; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | foreach my $comparator (@reversed_network) { | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ($pinned->{$comparator->[0]} || $pinned->{$comparator->[1]}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$$pinned{$comparator->[0]} or $$pinned{$comparator->[1]}
MC/DC0%0/2
$$pinned{$comparator->[0]} or $$pinned{$comparator->[1]}
$$pinned{$comparator->[0]}
$$pinned{$comparator->[1]}
Truth table0%0/3
A or B
A= $$pinned{$comparator->[0]}B= $$pinned{$comparator->[1]}
| |||||||||||||||||||||||||||||
| 30 | 0 | $pinned->{$comparator->[0]} = $pinned->{$comparator->[1]} = 1; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | push @reversed_output, $comparator; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | return [ reverse @reversed_output ]; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub average_swaps_zero_one { | ||||||||||||||||||||||||||
|
Subroutine
average_swaps_zero_one: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($n, $network) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | my $sum = 0; | |||||||||||||||||||||||||||
| 45 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | for my $i (0 .. (2**$n - 1)) { | |||||||||||||||||||||||||||
| 48 | 0 | my $p = [ split //, sprintf("%0${n}b", $i) ]; | |||||||||||||||||||||||||||
| 49 | 0 | $count++; | |||||||||||||||||||||||||||
| 50 | 0 | Algorithm::Networksort::nw_sort($network, $p); | |||||||||||||||||||||||||||
| 51 | 0 | my %stats = Algorithm::Networksort::nw_sort_stats(); | |||||||||||||||||||||||||||
| 52 | 0 | $sum += $stats{swaps}; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return $sum / $count; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub average_swaps_permutation { | ||||||||||||||||||||||||||
|
Subroutine
average_swaps_permutation: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($n, $network) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | my $sum = 0; | |||||||||||||||||||||||||||
| 63 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | for my $p (Math::Combinatorics::permute(0 .. ($n-1))) { | |||||||||||||||||||||||||||
| 66 | 0 | $count++; | |||||||||||||||||||||||||||
| 67 | 0 | Algorithm::Networksort::nw_sort($network, $p); | |||||||||||||||||||||||||||
| 68 | 0 | my %stats = Algorithm::Networksort::nw_sort_stats(); | |||||||||||||||||||||||||||
| 69 | 0 | $sum += $stats{swaps}; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | return $sum / $count; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Algorithm::Networksort::Chooser - Helper utility for Algorithm::Networksort | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | This module contains library routines used by the L<algorithm-networksort-chooser> command-line script. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | L<Algorithm-Networksort-Chooser github repo|https://github.com/hoytech/Algorithm-Networksort-Chooser> | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Doug Hoyte, C<< <doug@hcsw.org> >> | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Copyright 2013-2016 Doug Hoyte. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | This module is licensed under the same terms as perl itself. | ||||||||||||||||||||||||||||