Codebase list libgraph-perl / 225f8aa
fix APSP_Floyd_Warshall logic error when subpaths totalled 0 - fix #3 Ed J 3 years ago
3 changed file(s) with 31 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
66 - switch to GitHub issues rather than RT
77 - fix all_successors with non-truthy names - fix #5
88 - add Graph::Matrix->stringify to help debug
9 - fix APSP_Floyd_Warshall logic error when subpaths totalled 0 - fix #3
910
1011 0.9704 2015-10-07 Jarkko Hietaniemi <jhi@iki.fi>
1112 - rt.cpan.org 107567: edges() missing on undirected multiedged graph:
139139 # $d1a = $dm->get($v, $u) || 1;
140140 # $d1b = $dm->get($u, $w) || 1;
141141 $d0 = $didiv->[$diw];
142 $d1a = $didiv->[$diu] || 1;
143 $d1b = $didiu->[$diw] || 1;
142 # no override sum-zero paths which can happen with negative weights
143 $d1a = $didiv->[$diu];
144 $d1a = 1 unless defined $d1a;
145 $d1b = $didiu->[$diw];
146 $d1b = 1 unless defined $d1b;
144147 } else {
145148 $d1a = 1;
146149 $d1b = 1;
0 use Test::More tests => 227;
0 use Test::More tests => 231;
11
22 use Graph::Directed;
33 use Graph::Undirected;
314314
315315 is($t0, $t0tcfw);
316316
317 my $t3apspfw = Graph::APSP_Floyd_Warshall($g3);
317 my $t3apspfw = $g3->APSP_Floyd_Warshall;
318318
319319 is($t3, $t3apspfw);
320320
398398 is ("@{[sort $tc2->path_vertices(0,1)]}", "0 1");
399399 is ("@{[sort $tc2->path_vertices(0,2)]}", "0 1 2");
400400 is ("@{[sort $tc2->path_vertices(1,2)]}", "1 2");
401
402 }
401 }
402
403 {
404 # From Jon Freeman.
405 my @example = ( [ 1, 3, -2 ],
406 [ 3, 4, 2 ],
407 [ 4, 2, -1 ],
408 [ 2, 1, 4 ],
409 [ 2, 3, 3 ] );
410 my $g = Graph::Directed->new;
411 $g->add_weighted_edge(@$_) for @example;
412 my $apsp = $g->APSP_Floyd_Warshall();
413 # The output from APSP_Floyd_Warshall was non-deterministically
414 # incorrect for two of the possible vertex pairs due to an "|| 1"
415 # instead of defined-or across the 1-3-4 path which had "distance" 2+-2=0
416 my @bad_edges = ( [1, 2, -1, [1,3,4,2]], [2, 4, 4, [2,1,3,4]] );
417 foreach my $e (@bad_edges) {
418 my ($u, $v, $length, $path) = @$e;
419 my @spvs = $apsp->path_vertices($u, $v);
420 is_deeply \@spvs, $path, "APSP $u $v" or diag explain \@spvs;
421 is $apsp->path_length($u, $v), $length, "length $u $v";
422 }
423 }