Subject: | SPT_Dijkstra sometimes returns a wrong answer |
SPT_Dijkstra sometimes returns wrong answers. The simplest example I was able to find is attached.
Subject: | graph-bug.pl |
#!/usr/bin/perl
use warnings;
use strict;
use Graph::Directed;
my %results;
for (1 .. 100) {
my $g = 'Graph::Directed'->new;
$g->add_vertex for 1 .. 5;
$g->add_weighted_edge(@$_) for [1, 2, 1],
[2, 3, 1],
[4, 3, 1],
[5, 4, 2];
my $d = $g->SPT_Dijkstra(1);
$results{$d->get_vertex_attribute(4, 'weight') || 'undef'}++;
}
for my $r (keys %results) {
print "$r: $results{$r}x\n";
}
# 1 -> 2 -> 3 <- 4 <- 5
# 1 1 1 2