From 7328dbd4d2c03d533a20a9bad54bcf89b969ca0f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 27 Aug 2009 17:39:39 +0100 Subject: [PATCH] Further work on chart parser --- yarrg/yppedia-chart-parser | 45 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/yarrg/yppedia-chart-parser b/yarrg/yppedia-chart-parser index 7cc0baf..e315061 100755 --- a/yarrg/yppedia-chart-parser +++ b/yarrg/yppedia-chart-parser @@ -17,15 +17,23 @@ my %wiisland2node; my %winode2island; my %winode2lines; my %wiccix2arch; +my $wialldists; my $dbdists= Graph::Undirected->new(); my %dbisland2arch; -my %msgcount; -sub perr ($$) { print STDERR "$_[0]: $_[1]\n"; $msgcount{$_[0]}++; } -sub warning ($) { perr("warning",$_[0]); } -sub error ($) { perr("error", $_[0]); } -sub change ($) { perr("change", $_[0]); } +my %msgs; +sub pmsg ($$) { push @{ $msgs{$_[0]} }, "$_[0]: $_[1]\n"; } +sub warning ($) { pmsg("warning",$_[0]); } +sub error ($) { pmsg("error", $_[0]); } +sub change ($) { pmsg("change", $_[0]); } +sub print_messages () { + foreach my $k (qw(change warning error)) { + my $m= $msgs{$k}; + next unless $m; + print sort @$m or die $!; + } +} if (@ARGV && $ARGV[0] eq '--debug') { shift @ARGV; @@ -173,7 +181,7 @@ sub process_yppedia_graphs () { # Compute all-pairs-shortest-paths on dist, which is the # actual distances between all LPs. # - my $wialldists= $widists->APSP_Floyd_Warshall(); + $wialldists= $widists->APSP_Floyd_Warshall(); # Assign archipelago labels to groups of islands # @@ -329,10 +337,35 @@ sub compare_island_lists () { } } +sub compare_distances () { + foreach my $ia (sort keys %dbisland2arch) { + my $na= $wiisland2node{$ia}; + next unless defined $na; + foreach my $ib (sort keys %dbisland2arch) { + next unless $ia le $ib; # do every pair only once + my $nb= $wiisland2node{$ib}; + next unless defined $nb; + my $dbdist= $dbdists->get_edge_weight($ia,$ib); + my $widist= $wialldists->path_length($na,$nb); + if (!defined $dbdist) { + change(sprintf "define distance %2d for %s..%s", + $widist, $ia,$ib); + } elsif ($dbdist != $widist) { + change(sprintf "change distance %2d to %2d for %s..%s", + $dbdist, $widist, $ia,$ib); + } + } + } +} + parse_info_serverside(); db_setocean($ocean); db_connect(); parse_yppedia_map(); parse_database_map(); process_yppedia_graphs(); + compare_island_lists(); +compare_distances(); + +print_messages(); -- 2.30.2