File Coverage

blib/lib/Algorithm/Networksort/Best.pm
Criterion Covered Total %
statement 29 47 61.7
branch 3 12 25.0
condition 0 3 0.0
subroutine 9 11 81.8
pod 3 3 100.0
total 44 76 57.8


line stmt bran cond sub pod time code
1             =pod
2              
3             =encoding UTF-8
4              
5             =head1 NAME
6              
7             Algorithm::Networksort::Best - Optimized Sorting Networks.
8              
9             =cut
10              
11             package Algorithm::Networksort::Best;
12              
13 2     2   3162 use 5.010001;
  2         6  
14              
15 2     2   9 use Algorithm::Networksort;
  2         2  
  2         12  
16 2     2   921 use Carp;
  2         3  
  2         128  
17 2     2   8 use Exporter;
  2         4  
  2         70  
18 2     2   7 use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
  2         1  
  2         113  
19 2     2   7 use strict;
  2         3  
  2         32  
20 2     2   6 use warnings;
  2         4  
  2         4948  
21              
22             @ISA = qw(Exporter);
23              
24             %EXPORT_TAGS = (
25             'all' => [ qw(
26             nwsrt_best
27             nw_best_names
28             nw_best_title
29             ) ],
30             );
31              
32             @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
33              
34             our $VERSION = '1.30';
35              
36             #
37             # The hashes represent each network, with a short, hopefully descriptive, key.
38             #
39             my %nw_best_by_name = (
40             floyd09 => {
41             inputs => 9,
42             depth => 9,
43             title => '9-input Network by Robert W. Floyd',
44             comparators =>
45             [[0,1], [3,4], [6,7], [1,2], [4,5], [7,8], [0,1], [3,4],
46             [6,7], [0,3], [3,6], [0,3], [1,4], [4,7], [1,4], [2,5],
47             [5,8], [2,5], [1,3], [5,7], [2,6], [4,6], [2,4], [2,3],
48             [5,6]]},
49             senso09 => {
50             inputs => 9,
51             depth => 8,
52             title => '9-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
53             comparators =>
54             [[2,6], [0,5], [1,4], [7,8], [0,7], [1,2], [3,5], [4,6],
55             [5,8], [1,3], [6,8], [0,1], [4,5], [2,7], [3,7], [3,4],
56             [5,6], [1,2], [1,3], [6,7], [4,5], [2,4], [5,6], [2,3],
57             [4,5]]},
58             waksman10 => {
59             inputs => 10,
60             depth => 9,
61             title => '10-Input Network by A. Waksman',
62             comparators =>
63             [[4,9], [3,8], [2,7], [1,6], [0,5], [1,4], [6,9], [0,3],
64             [5,8], [0,2], [3,6], [7,9], [0,1], [2,4], [5,7], [8,9],
65             [1,2], [4,6], [7,8], [3,5], [2,5], [6,8], [1,3], [4,7],
66             [2,3], [6,7], [3,4], [5,6], [4,5]]},
67             senso10 => {
68             inputs => 10,
69             depth => 8,
70             title => '10-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
71             comparators =>
72             [[1,4], [7,8], [2,3], [5,6], [0,9], [2,5], [0,7], [8,9],
73             [3,6], [4,9], [0,1], [0,2], [6,9], [3,5], [4,7], [1,8],
74             [3,4], [5,8], [6,7], [1,2], [7,8], [1,3], [2,5], [4,6],
75             [2,3], [6,7], [4,5], [3,4], [5,6]]},
76             shapirogreen11 => {
77             inputs => 11,
78             depth => 9,
79             title => '11-Input by G. Shapiro and M. W. Green',
80             comparators =>
81             [[0,1], [2,3], [4,5], [6,7], [8,9], [1,3], [5,7], [0,2],
82             [4,6], [8,10], [1,2], [5,6], [9,10], [1,5], [6,10], [5,9],
83             [2,6], [1,5], [6,10], [0,4], [3,7], [4,8], [0,4], [1,4],
84             [7,10], [3,8], [2,3], [8,9], [2,4], [7,9], [3,5], [6,8],
85             [3,4], [5,6], [7,8]]},
86             senso11 => {
87             inputs => 11,
88             depth => 10,
89             title => '11-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
90             comparators =>
91             [[0,9], [2,8], [3,7], [4,6], [1,5], [1,3], [2,4], [6,10],
92             [7,8], [5,9], [0,6], [1,2], [8,10], [9,10], [0,1], [5,7],
93             [3,4], [6,8], [2,6], [1,5], [7,8], [4,9], [2,3], [8,9],
94             [1,2], [4,6], [3,5], [6,7], [7,8], [2,3], [4,6], [5,6],
95             [3,4], [6,7], [4,5]]},
96             shapirogreen12 => {
97             inputs => 12,
98             depth => 9,
99             title => '12-Input by G. Shapiro and M. W. Green',
100             comparators =>
101             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [1,3], [5,7],
102             [9,11], [0,2], [4,6], [8,10], [1,2], [5,6], [9,10], [1,5],
103             [6,10], [5,9], [2,6], [1,5], [6,10], [0,4], [7,11], [3,7],
104             [4,8], [0,4], [7,11], [1,4], [7,10], [3,8], [2,3], [8,9],
105             [2,4], [7,9], [3,5], [6,8], [3,4], [5,6], [7,8]]},
106             senso12 => {
107             inputs => 12,
108             depth => 9,
109             title => '12-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
110             comparators =>
111             [[0,5], [2,7], [4,10], [3,6], [8,11], [1,9], [5,6], [1,8],
112             [0,3], [2,4], [9,11], [7,10], [7,9], [10,11], [1,2], [6,11],
113             [0,1], [4,8], [5,8], [1,4], [3,7], [2,5], [7,10], [6,9],
114             [2,3], [4,6], [8,10], [1,2], [9,10], [6,8], [3,4], [8,9],
115             [2,3], [5,7], [4,5], [6,7], [7,8], [5,6], [3,4]]},
116             end13 => {
117             inputs => 13,
118             depth => 10,
119             title => '13-Input Network Generated by the END algorithm, by Hugues Juillé',
120             comparators =>
121             [[1,7], [9,11], [3,4], [5,8], [0,12], [2,6], [0,1], [2,3],
122             [4,6], [8,11], [7,12], [5,9], [0,2], [3,7], [10,11], [1,4],
123             [6,12], [7,8], [11,12], [4,9], [6,10], [3,4], [5,6], [8,9],
124             [10,11], [1,7], [2,6], [9,11], [1,3], [4,7], [8,10], [0,5],
125             [2,5], [6,8], [9,10], [1,2], [3,5], [7,8], [4,6], [2,3],
126             [4,5], [6,7], [8,9], [3,4], [5,6]]},
127             senso13 => {
128             inputs => 13,
129             depth => 12,
130             title => '13-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
131             comparators =>
132             [[4,8], [0,9], [3,7], [2,5], [6,11], [1,12], [0,6], [2,4],
133             [5,8], [7,12], [1,3], [10,11], [9,11], [0,1], [8,12], [8,10],
134             [2,8], [11,12], [0,2], [7,9], [5,9], [3,6], [3,5], [1,8],
135             [4,6], [4,7], [10,11], [6,9], [3,4], [1,2], [9,11], [1,3],
136             [6,10], [2,4], [2,3], [9,10], [6,8], [5,7], [5,6], [7,8],
137             [3,5], [8,9], [4,5], [6,7], [5,6]]},
138             green14 => {
139             inputs => 14,
140             depth => 10,
141             title => '14-Input Network by M. W. Green',
142             comparators =>
143             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [12,13], [0,2],
144             [4,6], [8,10], [1,3], [5,7], [9,11], [0,4], [8,12], [1,5],
145             [9,13], [2,6], [3,7], [0,8], [1,9], [2,10], [3,11], [4,12],
146             [5,13], [5,10], [6,9], [3,12], [7,11], [1,2], [4,8], [1,4],
147             [7,13], [2,8], [2,4], [5,6], [9,10], [11,13], [3,8], [7,12],
148             [6,8], [10,12], [3,5], [7,9], [3,4], [5,6], [7,8], [9,10],
149             [11,12], [6,7], [8,9]]},
150             senso14 => {
151             inputs => 14,
152             depth => 11,
153             title => '14-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
154             comparators =>
155             [[0,6], [2,3], [8,12], [4,5], [1,10], [7,13], [9,11], [3,6],
156             [4,7], [5,13], [1,8], [10,12], [0,2], [11,12], [0,9], [1,4],
157             [6,13], [12,13], [0,1], [2,7], [3,5], [9,10], [3,8], [7,10],
158             [5,8], [2,9], [6,11], [4,6], [8,12], [1,3], [10,11], [2,4],
159             [11,12], [1,2], [8,10], [3,9], [3,4], [2,3], [10,11], [5,7],
160             [7,8], [6,9], [5,6], [4,5], [8,9], [6,7], [9,10], [3,4],
161             [5,6], [7,8], [6,7]]},
162             green15 => {
163             inputs => 15,
164             depth => 10,
165             title => '15-Input Network by M. W. Green',
166             comparators =>
167             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [12,13], [0,2],
168             [4,6], [8,10], [12,14], [1,3], [5,7], [9,11], [0,4], [8,12],
169             [1,5], [9,13], [2,6], [10,14], [3,7], [0,8], [1,9], [2,10],
170             [3,11], [4,12], [5,13], [6,14], [5,10], [6,9], [3,12], [13,14],
171             [7,11], [1,2], [4,8], [1,4], [7,13], [2,8], [11,14], [2,4],
172             [5,6], [9,10], [11,13], [3,8], [7,12], [6,8], [10,12], [3,5],
173             [7,9], [3,4], [5,6], [7,8], [9,10], [11,12], [6,7], [8,9]]},
174             senso15 => {
175             inputs => 15,
176             depth => 10,
177             title => '15-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
178             comparators =>
179             [[12,13], [5,7], [3,11], [2,10], [4,9], [6,8], [1,14], [11,14],
180             [1,3], [7,10], [0,12], [4,6], [2,5], [8,9], [0,2], [9,14],
181             [1,4], [0,1], [5,6], [7,8], [11,13], [3,12], [5,11], [9,10],
182             [8,12], [2,4], [6,13], [3,7], [2,3], [12,14], [10,13], [1,5],
183             [13,14], [1,2], [3,5], [10,12], [12,13], [2,3], [8,11], [4,9],
184             [10,11], [6,7], [5,6], [4,8], [7,9], [4,5], [9,11], [11,12],
185             [3,4], [6,8], [7,10], [9,10], [5,6], [7,8], [8,9], [6,7]]},
186             green16 => {
187             inputs => 16,
188             depth => 10,
189             title => '16-Input Network by M. W. Green',
190             comparators =>
191             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [12,13], [14,15],
192             [0,2], [4,6], [8,10], [12,14], [1,3], [5,7], [9,11], [13,15],
193             [0,4], [8,12], [1,5], [9,13], [2,6], [10,14], [3,7], [11,15],
194             [0,8], [1,9], [2,10], [3,11], [4,12], [5,13], [6,14], [7,15],
195             [5,10], [6,9], [3,12], [13,14], [7,11], [1,2], [4,8], [1,4],
196             [7,13], [2,8], [11,14], [2,4], [5,6], [9,10], [11,13], [3,8],
197             [7,12], [6,8], [10,12], [3,5], [7,9], [3,4], [5,6], [7,8],
198             [9,10], [11,12], [6,7], [8,9]]},
199             senso16 => {
200             inputs => 16,
201             depth => 10,
202             title => '16-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
203             comparators =>
204             [[12,13], [5,7], [3,11], [2,10], [0,15], [4,9], [6,8], [1,14],
205             [11,14], [1,3], [7,10], [0,12], [4,6], [2,5], [8,9], [13,15],
206             [10,15], [0,2], [9,14], [1,4], [0,1], [14,15], [5,6], [7,8],
207             [11,13], [3,12], [5,11], [9,10], [8,12], [2,4], [6,13], [3,7],
208             [2,3], [12,14], [10,13], [1,5], [13,14], [1,2], [3,5], [10,12],
209             [12,13], [2,3], [8,11], [4,9], [10,11], [6,7], [5,6], [4,8],
210             [7,9], [4,5], [9,11], [11,12], [3,4], [6,8], [7,10], [9,10],
211             [5,6], [7,8], [8,9], [6,7]]},
212             senso17 => {
213             inputs => 17,
214             depth => 17,
215             title => '17-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
216             comparators =>
217             [[5,11], [4,9], [7,12], [0,14], [2,16], [1,15], [3,8], [6,13],
218             [3,10], [8,13], [4,7], [9,12], [0,2], [14,16], [1,6], [10,15],
219             [3,5], [11,13], [0,4], [12,16], [1,3], [13,15], [0,1], [15,16],
220             [2,9], [7,14], [5,10], [6,11], [5,7], [6,8], [8,10], [2,3],
221             [8,14], [9,11], [12,13], [4,6], [10,14], [4,5], [7,9], [11,13],
222             [1,2], [14,15], [1,8], [13,15], [1,4], [2,5], [11,14], [13,14],
223             [2,4], [6,12], [9,12], [3,10], [3,8], [6,7], [10,12], [3,6],
224             [3,4], [12,13], [10,11], [5,6], [11,12], [4,5], [7,8], [8,9],
225             [6,8], [9,11], [5,7], [6,7], [9,10], [8,9], [7,8]]},
226             sat17 => {
227             inputs => 17,
228             depth => 10,
229             title => '17-Input Network by M. Codish, L. Cruz-Filipe, T. Ehlers, M. Müller, P. Schneider-Kamp',
230             comparators =>
231             [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [15,16],
232             [2,4], [6,8], [10,12], [14,16], [1,3], [5,7], [9,11], [13,15],
233             [4,8], [12,16], [3,7], [11,15], [2,6], [10,14], [1,5], [9,13],
234             [0,3], [4,7], [8,16], [1,13], [14,15], [6,12], [5,11], [2,10],
235             [1,16], [3,6], [7,15], [4,14], [0,13], [2,5], [8,9], [10,11],
236             [0,1], [2,8], [9,15], [3,4], [7,11], [12,14], [6,13], [5,10],
237             [2,15], [4,10], [11,13], [3,8], [9,12], [1,5], [6,7], [1,3],
238             [4,6], [7,9], [10,11], [13,15], [0,2], [5,8], [12,14], [0,1],
239             [2,3], [4,5], [6,8], [9,11], [12,13], [14,15], [7,10], [1,2],
240             [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [15,16]]},
241             alhajbaddar18 => {
242             inputs => 18,
243             depth => 11,
244             title => '18-Input Network by Sherenaz Waleed Al-Haj Baddar',
245             comparators =>
246             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [12,13], [14,15],
247             [16,17], [0,2], [1,3], [4,6], [5,7], [8,10], [9,11], [12,17],
248             [13,14], [15,16], [0,4], [1,5], [2,6], [3,7], [9,10], [8,12],
249             [11,16], [13,15], [14,17], [7,16], [6,17], [3,5], [10,14], [11,12],
250             [9,15], [2,4], [1,13], [0,8], [16,17], [7,14], [5,12], [3,15],
251             [6,13], [4,10], [2,11], [8,9], [0,1], [1,8], [14,16], [6,9],
252             [7,13], [5,11], [3,10], [4,15], [4,8], [14,15], [5,9], [7,11],
253             [1,2], [12,16], [3,6], [10,13], [5,8], [11,14], [2,3], [12,13],
254             [6,7], [9,10], [7,9], [3,5], [12,14], [2,4], [13,15], [6,8],
255             [10,11], [13,14], [11,12], [9,10], [7,8], [5,6], [3,4], [12,13],
256             [10,11], [8,9], [6,7], [4,5]]},
257             senso18 => {
258             inputs => 18,
259             depth => 15,
260             title => '18-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
261             comparators =>
262             [[4,12], [5,13], [0,7], [10,17], [2,3], [14,15], [6,8], [9,11],
263             [1,16], [2,6], [11,15], [1,9], [8,16], [4,10], [7,13], [3,12],
264             [5,14], [0,2], [15,17], [1,4], [13,16], [0,5], [12,17], [0,1],
265             [16,17], [3,7], [10,14], [6,9], [8,11], [2,15], [3,8], [9,14],
266             [4,5], [12,13], [6,10], [2,6], [7,11], [1,4], [13,16], [14,15],
267             [2,3], [11,15], [15,16], [1,2], [11,14], [3,6], [13,14], [3,4],
268             [14,15], [2,3], [5,6], [11,12], [7,9], [8,10], [9,10], [7,8],
269             [5,11], [6,12], [10,12], [5,7], [12,14], [3,5], [10,13], [4,7],
270             [12,13], [4,5], [8,9], [6,9], [8,11], [9,12], [5,8], [6,7],
271             [10,11], [6,8], [9,11], [7,10], [9,10], [7,8]]},
272             senso19 => {
273             inputs => 19,
274             depth => 15,
275             title => '19-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
276             comparators =>
277             [[4,10], [3,12], [0,16], [7,14], [8,11], [6,13], [15,17], [1,5],
278             [9,18], [2,5], [11,16], [7,9], [1,2], [6,15], [10,12], [3,4],
279             [13,17], [0,8], [14,18], [5,16], [3,7], [17,18], [1,6], [4,15],
280             [0,1], [12,16], [0,3], [16,18], [2,11], [9,10], [13,14], [6,8],
281             [7,13], [2,9], [11,15], [1,7], [5,10], [12,17], [8,14], [4,6],
282             [10,14], [3,4], [15,16], [1,2], [14,17], [1,3], [16,17], [5,7],
283             [6,13], [5,6], [10,15], [2,4], [14,15], [2,5], [11,12], [15,16],
284             [2,3], [8,9], [7,13], [9,12], [8,11], [9,10], [13,14], [5,8],
285             [12,14], [14,15], [3,5], [4,6], [10,13], [4,8], [4,5], [13,14],
286             [7,11], [6,11], [6,9], [7,8], [11,12], [6,7], [12,13], [5,6],
287             [9,10], [10,11], [11,12], [8,9], [7,8], [9,10]]},
288             senso20 => {
289             inputs => 20,
290             depth => 14,
291             title => '20-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
292             comparators =>
293             [[2,11], [8,17], [0,10], [9,19], [4,5], [14,15], [3,6], [13,16],
294             [1,12], [7,18], [3,14], [5,16], [0,1], [18,19], [4,13], [6,15],
295             [7,9], [10,12], [2,8], [11,17], [4,7], [12,15], [0,3], [16,19],
296             [0,2], [17,19], [0,4], [15,19], [1,14], [5,18], [8,10], [9,11],
297             [6,13], [5,9], [10,14], [1,3], [16,18], [6,8], [11,13], [2,7],
298             [12,17], [1,5], [1,2], [14,18], [4,6], [13,15], [17,18], [15,18],
299             [1,4], [3,9], [10,16], [2,3], [16,17], [13,17], [2,6], [15,17],
300             [2,4], [7,8], [11,12], [5,10], [9,14], [8,12], [7,11], [3,7],
301             [12,16], [3,5], [14,16], [15,16], [3,4], [5,6], [13,14], [14,15],
302             [4,5], [10,11], [8,9], [11,12], [7,8], [7,10], [9,12], [5,7],
303             [12,14], [9,13], [6,10], [6,7], [10,11], [12,13], [8,9], [9,11],
304             [11,12], [8,10], [7,8], [9,10]]},
305             sat20 => {
306             inputs => 20,
307             depth => 11,
308             title => '20-Input Network by M. Codish, L. Cruz-Filipe, T. Ehlers, M. Müller, P. Schneider-Kamp',
309             comparators =>
310             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [12,13], [14,15],
311             [16,17], [18,19], [1,3], [5,7], [9,11], [13,15], [17,19], [0,2],
312             [4,6], [8,10], [12,14], [16,18], [3,7], [9,10], [15,19], [2,6],
313             [14,18], [1,5], [13,17], [0,4], [12,16], [7,19], [6,18], [5,17],
314             [4,16], [3,15], [2,14], [1,13], [0,12], [2,19], [3,8], [11,16],
315             [17,18], [1,4], [5,15], [9,14], [10,13], [6,12], [0,19], [1,18],
316             [2,6], [7,15], [16,17], [3,4], [8,14], [5,9], [10,11], [12,13],
317             [1,3], [4,5], [9,12], [13,16], [17,18], [0,15], [7,14], [8,11],
318             [6,10], [0,1], [3,6], [7,13], [14,17], [18,19], [2,4], [5,10],
319             [11,12], [15,16], [8,9], [2,3], [4,8], [9,11], [12,15], [16,18],
320             [1,17], [5,6], [7,10], [13,14], [1,3], [4,5], [7,9], [10,11],
321             [12,13], [14,15], [16,17], [18,19], [0,2], [6,8], [1,2], [3,4],
322             [5,6], [7,8], [9,10], [11,12], [13,14], [15,16]]},
323             senso21 => {
324             inputs => 21,
325             depth => 20,
326             title => '21-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
327             comparators =>
328             [[5,9], [11,15], [1,19], [2,14], [6,18], [0,17], [3,20], [4,8],
329             [12,16], [7,13], [1,7], [13,19], [2,11], [9,18], [4,12], [8,16],
330             [3,5], [15,17], [0,10], [10,20], [0,6], [14,20], [2,3], [17,18],
331             [1,4], [16,19], [0,1], [19,20], [0,2], [18,20], [7,8], [12,13],
332             [9,10], [4,11], [5,6], [14,15], [10,11], [5,12], [8,15], [6,13],
333             [7,14], [16,17], [1,3], [4,9], [5,7], [13,15], [11,18], [17,19],
334             [1,2], [18,19], [4,5], [1,4], [15,19], [13,17], [2,7], [11,17],
335             [9,14], [4,5], [15,18], [17,18], [2,4], [6,10], [8,16], [3,12],
336             [10,14], [12,16], [3,8], [6,9], [14,16], [8,12], [3,6], [4,5],
337             [15,16], [16,17], [3,4], [11,13], [5,7], [13,15], [6,7], [15,16],
338             [4,5], [10,11], [9,11], [8,9], [11,12], [12,14], [8,10], [6,8],
339             [14,15], [5,6], [12,13], [13,14], [6,8], [7,9], [10,11], [7,10],
340             [7,8], [9,13], [11,12], [9,12], [9,11], [9,10]]},
341             alhajbaddar22 => {
342             inputs => 22,
343             depth => 12,
344             title => '22-Input Network by Sherenaz Waleed Al-Haj Baddar',
345             comparators =>
346             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [12,13], [14,15],
347             [16,17], [18,19], [20,21], [2,4], [1,3], [0,5], [6,8], [7,9],
348             [10,12], [11,13], [14,16], [15,17], [18,20], [19,21], [6,10], [7,11],
349             [8,12], [9,13], [14,18], [15,19], [16,20], [17,21], [3,5], [1,4],
350             [0,2], [9,17], [7,15], [11,19], [8,16], [3,12], [0,10], [1,18],
351             [5,20], [13,21], [6,14], [2,4], [0,7], [17,20], [3,15], [9,18],
352             [2,11], [4,16], [5,10], [1,8], [12,19], [13,14], [20,21], [0,6],
353             [3,8], [12,18], [2,13], [14,16], [5,9], [10,15], [4,7], [11,17],
354             [16,20], [18,19], [15,17], [12,14], [10,11], [7,9], [8,13], [4,5],
355             [1,3], [2,6], [19,20], [16,17], [15,18], [11,14], [9,13], [10,12],
356             [7,8], [3,5], [4,6], [1,2], [18,19], [14,16], [13,15], [11,12],
357             [8,9], [5,10], [6,7], [2,3], [17,19], [16,18], [14,15], [12,13],
358             [9,11], [8,10], [5,7], [3,6], [2,4], [17,18], [15,16], [13,14],
359             [11,12], [9,10], [7,8], [5,6], [3,4], [16,17], [14,15], [12,13],
360             [10,11], [8,9], [6,7], [4,5]]},
361             senso22 => {
362             inputs => 22,
363             depth => 15,
364             title => '22-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
365             comparators =>
366             [[10,11], [2,8], [13,19], [3,15], [6,18], [1,16], [5,20], [0,17],
367             [4,21], [7,9], [12,14], [0,4], [17,21], [3,12], [9,18], [1,2],
368             [19,20], [7,13], [8,14], [5,6], [15,16], [5,7], [14,16], [1,10],
369             [11,20], [0,3], [18,21], [0,5], [16,21], [0,1], [20,21], [6,8],
370             [13,15], [2,4], [17,19], [9,11], [10,12], [2,7], [14,19], [3,9],
371             [12,18], [6,13], [8,15], [4,11], [10,17], [5,10], [11,16], [3,6],
372             [15,18], [1,2], [19,20], [1,3], [18,20], [1,5], [16,20], [2,6],
373             [15,19], [11,18], [2,5], [16,19], [3,10], [2,3], [18,19], [9,12],
374             [4,14], [7,17], [8,13], [12,17], [4,9], [13,14], [7,8], [4,7],
375             [14,17], [4,5], [16,17], [17,18], [3,4], [6,10], [11,15], [5,6],
376             [15,16], [4,5], [16,17], [9,12], [8,13], [10,13], [8,11], [7,9],
377             [12,14], [7,8], [13,14], [14,16], [5,7], [9,10], [11,12], [6,9],
378             [12,15], [14,15], [6,7], [8,11], [10,13], [8,9], [12,13], [7,8],
379             [13,14], [10,11], [11,12], [9,10]]},
380             morwenn23 => {
381             inputs => 23,
382             depth => 18,
383             title => '23-Input Network by Morwenn',
384             comparators =>
385             [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15],
386             [16, 17], [18, 19], [20, 21], [1, 3], [5, 7], [9, 11], [0, 2], [4, 6],
387             [8, 10], [13, 15], [17, 19], [12, 14], [16, 18], [20, 22], [1, 2], [5, 6],
388             [9, 10], [13, 14], [17, 18], [21, 22], [1, 5], [6, 10], [13, 17], [18, 22],
389             [5, 9], [2, 6], [17, 21], [14, 18], [1, 5], [6, 10], [0, 4], [7, 11],
390             [13, 17], [18, 22], [12, 16], [3, 7], [4, 8], [15, 19], [16, 20], [0, 4],
391             [7, 11], [12, 16], [1, 4], [7, 10], [3, 8], [13, 16], [19, 22], [15, 20],
392             [2, 3], [8, 9], [14, 15], [20, 21], [2, 4], [7, 9], [3, 5], [6, 8],
393             [14, 16], [19, 21], [15, 17], [18, 20], [3, 4], [5, 6], [7, 8], [15, 16],
394             [17, 18], [19, 20], [0, 12], [1, 13], [2, 14], [3, 15], [4, 16], [5, 17],
395             [6, 18], [7, 19], [8, 20], [9, 21], [10, 22], [2, 12], [3, 13], [10, 20],
396             [11, 21], [4, 12], [5, 13], [6, 14], [7, 15], [8, 16], [9, 17], [10, 18],
397             [11, 19], [8, 12], [9, 13], [10, 14], [11, 15], [6, 8], [10, 12], [14, 16],
398             [7, 9], [11, 13], [15, 17], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10],
399             [11, 12], [13, 14], [15, 16], [17, 18], [19, 20], [21, 22]]},
400             senso23 => {
401             inputs => 23,
402             depth => 22,
403             title => '23-Input Network via SENSO by V. K. Valsalam and R. Miikkulainen',
404             comparators =>
405             [[1,20], [2,21], [5,13], [9,17], [0,7], [15,22], [4,11], [6,12],
406             [10,16], [8,18], [14,19], [3,8], [4,14], [11,18], [2,6], [16,20],
407             [0,9], [13,22], [5,15], [7,17], [1,10], [12,21], [8,19], [17,22],
408             [0,5], [20,21], [1,2], [18,19], [3,4], [21,22], [0,1], [19,22],
409             [0,3], [12,13], [9,10], [6,15], [7,16], [8,11], [11,14], [4,11],
410             [6,8], [14,16], [17,20], [2,5], [9,12], [10,13], [15,18], [10,11],
411             [4,7], [20,21], [1,2], [7,15], [3,9], [13,19], [16,18], [8,14],
412             [4,6], [18,21], [1,4], [19,21], [1,3], [9,10], [11,13], [2,6],
413             [16,20], [4,9], [13,18], [19,20], [2,3], [18,20], [2,4], [5,17],
414             [12,14], [8,12], [5,7], [15,17], [5,8], [14,17], [3,5], [17,19],
415             [3,4], [18,19], [6,10], [11,16], [13,16], [6,9], [16,17], [5,6],
416             [4,5], [7,9], [17,18], [12,15], [14,15], [8,12], [7,8], [13,15],
417             [15,17], [5,7], [9,10], [10,14], [6,11], [14,16], [15,16], [6,7],
418             [10,11], [9,12], [11,13], [13,14], [8,9], [7,8], [14,15], [9,10],
419             [8,9], [12,14], [11,12], [12,13], [10,11], [11,12]]},
420             morwenn24 => {
421             inputs => 24,
422             depth => 18,
423             title => '24-Input Network by Morwenn',
424             comparators =>
425             [[0,1], [2,3], [4,5], [6,7], [8,9], [10,11], [12,13], [14,15],
426             [16,17], [18,19], [20,21], [22,23], [1,3], [5,7], [9,11], [0,2],
427             [4,6], [8,10], [13,15], [17,19], [21,23], [12,14], [16,18], [20,22],
428             [1,2], [5,6], [9,10], [13,14], [17,18], [21,22], [1,5], [6,10],
429             [13,17], [18,22], [5,9], [2,6], [17,21], [14,18], [1,5], [6,10],
430             [0,4], [7,11], [13,17], [18,22], [12,16], [19,23], [3,7], [4,8],
431             [15,19], [16,20], [0,4], [7,11], [12,16], [19,23], [1,4], [7,10],
432             [3,8], [13,16], [19,22], [15,20], [2,3], [8,9], [14,15], [20,21],
433             [2,4], [7,9], [3,5], [6,8], [14,16], [19,21], [15,17], [18,20],
434             [3,4], [5,6], [7,8], [15,16], [17,18], [19,20], [0,12], [1,13],
435             [2,14], [3,15], [4,16], [5,17], [6,18], [7,19], [8,20], [9,21],
436             [10,22], [11,23], [2,12], [3,13], [10,20], [11,21], [4,12], [5,13],
437             [6,14], [7,15], [8,16], [9,17], [10,18], [11,19], [8,12], [9,13],
438             [10,14], [11,15], [6,8], [10,12], [14,16], [7,9], [11,13], [15,17],
439             [1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [15,16],
440             [17,18], [19,20], [21,22]]},
441             );
442              
443             #
444             # The hash that will return the keys by input number.
445             #
446             my %nw_best_by_input;
447              
448             #
449             # Set up %nw_best_by_input.
450             #
451             INIT
452             {
453 2     2   128967 for my $k (keys %nw_best_by_name)
454             {
455 58         40 my $inputs = ${$nw_best_by_name{$k}}{inputs};
  58         77  
456              
457 58 100       114 if (exists $nw_best_by_input{$inputs})
458             {
459 26         16 push @{$nw_best_by_input{$inputs}}, $k;
  26         40  
460             }
461             else
462             {
463 32         64 $nw_best_by_input{$inputs} = [$k];
464             }
465             #print STDERR "$inputs: " . join(", ", @{$nw_best_by_input{$inputs}}) . "\n";
466             }
467             }
468              
469             =head1 SYNOPSIS
470              
471             use Algorithm::Networksort;
472             use Algorithm::Networksort::Best qw(:all);
473              
474             my $inputs = 9;
475              
476             #
477             # First find if any networks exist for the size you want.
478             #
479             my @nwkeys = nw_best_names($inputs);
480              
481             #
482             # For each sorting network, show the comparators.
483             #
484             for my $name (@nwkeys)
485             {
486             my $nw = nwsrt_best(name => $name);
487              
488             #
489             # Print the list, and print the graph of the list.
490             #
491             print $nw->title(), "\n", $nw->formatted(), "\n\n";
492             print $nw->graph_text(), "\n\n";
493             }
494              
495             =head1 DESCRIPTION
496              
497             For some inputs, sorting networks have been discovered that are more efficient
498             than those generated by rote algorithms. The "Best" module allows you to use
499             those networks instead.
500              
501             There is no guarantee that it will return the best network for
502             all cases. Usually "best" means that the module will return a lower number of
503             comparators for the number of inputs than the algorithms in Algorithm::Networksort
504             will return. Some will simply have a lower number of comparators, others may have
505             a smaller depth but an equal or greater number of comparators.
506              
507             The current networks are:
508              
509             =head2 9-Input Networks
510              
511             =over 4
512              
513             =item floyd09
514              
515             A 9-input network of depth 9 discovered by R. W. Floyd.
516              
517             =item senso09
518              
519             A 9-input network of depth 8 found using the SENSO program by
520             V. K. Valsalam and R. Miikkulaainen.
521              
522             =back
523              
524             =head2 10-Input Networks
525              
526             =over 4
527              
528             =item waksman10
529              
530             a 10-input network of depth 9 found by A. Waksman.
531              
532             =item senso10
533              
534             A 10-input network of depth 8 found using the SENSO program by
535             V. K. Valsalam and R. Miikkulaainen.
536              
537             =back
538              
539             =head2 11-Input Networks
540              
541             =over 4
542              
543             =item shapirogreen11
544              
545             An 11-input network of depth 9 found by G. Shapiro and M. W. Green.
546              
547             =item senso11
548              
549             A 11-input network of depth 10 found using the SENSO program by
550             V. K. Valsalam and R. Miikkulaainen.
551              
552             =back
553              
554             =head2 12-Input Networks
555              
556             =over 4
557              
558             =item shapirogreen12
559              
560             A 12-input network of depth 9 found by G. Shapiro and M. W. Green.
561              
562             =item senso12
563              
564             A 12-input network of depth 9 found using the SENSO program by
565             V. K. Valsalam and R. Miikkulaainen.
566              
567             =back
568              
569             =head2 13-Input Networks
570              
571             =over 4
572              
573             =item end13
574              
575             A 13-input network of depth 10 generated by the END algorithm, by Hugues Juillé.
576              
577             =item senso13
578              
579             A 13-input network of depth 12 found using the SENSO program by
580             V. K. Valsalam and R. Miikkulaainen.
581              
582             =back
583              
584             =head2 14-Input Networks
585              
586             =over 4
587              
588             =item green14
589              
590             A 14-input network of depth 10 created by taking the 16-input network of
591             M. W. Green and removing inputs 15 and 16.
592              
593             =item senso14
594              
595             A 14-input network of depth 11 found using the SENSO program by
596             V. K. Valsalam and R. Miikkulaainen.
597              
598             =back
599              
600             =head2 15-Input Networks
601              
602             =over 4
603              
604             =item green15
605              
606             A 15-input network of depth 10 created by taking the 16-input network of
607             M. W. Green and removing the 16th input.
608              
609             =item senso15
610              
611             A 15-input network of depth 10 found using the SENSO program by
612             V. K. Valsalam and R. Miikkulaainen.
613              
614             =back
615              
616             =head2 16-Input Networks
617              
618             =over 4
619              
620             =item green16
621              
622             A 16-input network of depth 10 found by M. W. Green.
623              
624             =item senso16
625              
626             A 16-input network of depth 10 found using the SENSO program by
627             V. K. Valsalam and R. Miikkulaainen.
628              
629             =back
630              
631             =head2 17-Input Networks
632              
633             =over 4
634              
635             =item senso17
636              
637             A 17-input network of depth 17 found using the SENSO program by
638             V. K. Valsalam and R. Miikkulaainen.
639              
640             =item sat17
641              
642             17-input network of depth 10 found by M. Codish, L. Cruz-Filipe, T. Ehlers,
643             M. Müller, P. Schneider-Kamp.
644              
645             =back
646              
647             =head2 18-Input Networks
648              
649             =over 4
650              
651             =item alhajbaddar18
652              
653             18-input network of depth 11 found by Sherenaz Waleed Al-Haj Baddar.
654              
655             =item senso18
656              
657             A 18-input network of depth 15 found using the SENSO program by
658             V. K. Valsalam and R. Miikkulaainen.
659              
660             =back
661              
662             =head2 19-Input Networks
663              
664             =over 4
665              
666             =item senso19
667              
668             A 19-input network of depth 15 found using the SENSO program by
669             V. K. Valsalam and R. Miikkulaainen.
670              
671             =back
672              
673             =head2 20-Input Networks
674              
675             =over 4
676              
677             =item sat20
678              
679             20-input network of depth 11 found by M. Codish, L. Cruz-Filipe, T. Ehlers, M. Müller, P. Schneider-Kamp.
680              
681             =item senso20
682              
683             A 20-input network of depth 14 found using the SENSO program by
684             V. K. Valsalam and R. Miikkulaainen.
685              
686             =back
687              
688             =head2 21-Input Networks
689              
690             =over 4
691              
692             =item senso21
693              
694             A 21-input network of depth 20 found using the SENSO program by
695             V. K. Valsalam and R. Miikkulaainen.
696              
697             =back
698              
699             =head2 22-Input Networks
700              
701             =over 4
702              
703             =item alhajbaddar22
704              
705             22-input network of depth 12 found by Sherenaz Waleed Al-Haj Baddar.
706              
707             =item senso22
708              
709             A 22-input network of depth 15 found using the SENSO program by
710             V. K. Valsalam and R. Miikkulaainen.
711              
712             =back
713              
714             =head2 23-Input Networks
715              
716             =over 4
717              
718             =item morwenn23
719              
720             A 23-input network of depth 18 found by Morwenn, by taking the 24-input
721             network and removing the final input.
722              
723             =item senso23
724              
725             A 23-input network of depth 22 found using the SENSO program by
726             V. K. Valsalam and R. Miikkulaainen.
727              
728             =back
729              
730             =head2 24-Input Networks
731              
732             =over 4
733              
734             =item morwenn24
735              
736             A 24-input network of depth 18 found by Morwenn
737             L<https://github.com/Morwenn/cpp-sort/wiki/Original-research#sorting-networks-23-and-24>.
738              
739             =back
740              
741             =head2 Export
742              
743             None by default. There is only one available export tag, ':all', which
744             exports the functions to create and use sorting networks. The functions are
745             nwsrt_best(), nw_best_names(), and nw_best_title().
746              
747             =head2 Functions
748              
749             =head3 nwsrt_best
750              
751             Return the Algorithm::Networksort object, given a key name. Also takes an optional
752             title to override the default.
753              
754             $nw = nwsrt_best(name => 'floyd09', title => "Compare depth to Bose-Nelson");
755              
756             =cut
757              
758             sub nwsrt_best
759             {
760 0     0 1 0 my(%opts) = @_;
761              
762 0 0       0 croak "No network chosen" unless (exists $opts{name});
763 0         0 my $name = $opts{name};
764              
765 0 0       0 croak "Unknown network name '$name'" unless (exists $nw_best_by_name{$name});
766 0         0 my %nw_struct = %{ $nw_best_by_name{$name} };
  0         0  
767 0   0     0 my $title = $opts{title} // $nw_struct{title};
768              
769             return Algorithm::Networksort->new(
770             algorithm => 'none',
771             inputs => $nw_struct{inputs},
772             comparators => $nw_struct{comparators},
773             depth => $nw_struct{depth},
774 0         0 title => $title,
775             nwid => $name,
776             );
777             }
778              
779             =head3 nw_best_names
780              
781             Return the list of keys for sorting networks of a giving input size.
782              
783             @names = nw_best_names(13);
784              
785             =cut
786              
787             sub nw_best_names
788             {
789 1     1 1 1063 my($inputs) = @_;
790              
791 1 50       19 return keys %nw_best_by_name unless (defined $inputs);
792              
793 0 0         unless (exists $nw_best_by_input{$inputs})
794             {
795 0           carp "No 'best' sorting networks exist for size $inputs";
796 0           return ();
797             }
798              
799 0           return @{$nw_best_by_input{$inputs}};
  0            
800             }
801              
802             =head3 nw_best_title
803              
804             Return a descriptive title for the network, given a key.
805              
806             $title = nw_best_title($key);
807              
808             =cut
809              
810             sub nw_best_title
811             {
812 0     0 1   my $key = shift;
813            
814 0 0         unless (exists $nw_best_by_name{$key})
815             {
816 0           carp "Unknown 'best' name '$key'.";
817 0           return "";
818             }
819              
820 0           return $nw_best_by_name{$key}{title};
821             }
822              
823             1;
824             __END__
825              
826             =head1 ACKNOWLEDGMENTS
827              
828             L<Doug Hoyte|https://github.com/hoytech> pointed out Sherenaz Waleed
829             Al-Haj Baddar's paper.
830              
831             L<Morwenn|https://github.com/Morwenn> found for me the SAT and SENSO
832             papers, contributed 23-input and 24-input sorting networks, and caught
833             documentation errors.
834              
835             =head1 SEE ALSO
836              
837             =head2 Non-algorithmic discoveries
838              
839             =over 3
840              
841             =item
842              
843             The networks by Floyd, Green, Shapiro, and Waksman are in
844             Donald E. Knuth's B<The Art of Computer Programming, Vol. 3:
845             Sorting and Searching> (2nd ed.), Addison Wesley Longman Publishing Co., Inc.,
846             Redwood City, CA, 1998.
847              
848             =item
849              
850             The Evolving Non-Determinism (END) algorithm by Hugues Juillé has found
851             more efficient sorting networks:
852             L<http://www.cs.brandeis.edu/~hugues/sorting_networks.html>.
853              
854             =item
855              
856             The 18 and 22 input networks found by Sherenaz Waleed Al-Haj Baddar
857             are described in her dissertation "Finding Better Sorting Networks" at
858             L<http://etd.ohiolink.edu/view.cgi?acc_num=kent1239814529>.
859              
860             =item
861              
862             The Symmetry and Evolution based Network Sort Optimization (SENSO) found more
863             networks for inputs of 9 through 23.
864              
865             =item
866              
867             Morwenn's 23 and 24-input networks are described at
868             L<https://github.com/Morwenn/cpp-sort/wiki/Original-research#sorting-networks-23-and-24>.
869              
870             =item
871              
872             Ian Parberry, "A computer assisted optimal depth lower bound for sorting
873             networks with nine inputs", L<http://www.eng.unt.edu/ian/pubs/snverify.pdf>.
874              
875             =back
876              
877             =head1 AUTHOR
878              
879             John M. Gamble may be found at B<jgamble@cpan.org>
880              
881             =cut
882