chiark / gitweb /
Do not include self-edges in routes
[ypp-sc-tools.db-live.git] / yarrg / yppedia-chart-parser
index c7db12ecdc6cb5c35914a02736b85921c73c96df..54a0e4577604592c6e365a1de0be7159c8446e08 100755 (executable)
@@ -423,7 +423,8 @@ sub shortest_path_reduction ($$) {
 
     1. F is an undirected weighted graph with positive edge weights.
 
-    2. All graphs we will consider have the same vertices as F.
+    2. All graphs we will consider have the same vertices as F
+       and none have self-edges.
 
     3. G = Closure(F) is the graph of cliques whose edge weights
        are the shortest paths in F, one clique for each connected
@@ -480,6 +481,7 @@ END
 
     my $result= Graph::Undirected->new();
     foreach my $edge_ac ($g->edges()) {
+        next if $edge_ac->[0] eq $edge_ac->[1];
        my $edgename_ac= join ' .. ', @$edge_ac;
        printf DEBUG "spr %s edge %s\n", $what, $edgename_ac;
        my $w_ac= $g->get_edge_weight(@$edge_ac);
@@ -649,8 +651,11 @@ END
 END
     ;
     foreach my $ia (sort keys %wiisland2node) {
+       my $na= $wiisland2node{$ia};
        foreach my $ib (sort keys %wiisland2node) {
-           my $apdist= widist($ia,$ib);
+           my $nb= $wiisland2node{$ib};
+           my $apdist= $ia eq $ib ? 0 : widist($na,$nb);
+           die "$ia $ib" unless defined $apdist;
            my $sprdist= $wispr->get_edge_weight($ia,$ib);
            die "$ia $ib $apdist $sprdist" if
                defined($sprdist) && $sprdist != $apdist;
@@ -660,10 +665,38 @@ END
        }
     }
 
-    # select ia.islandname, ib.islandname,dists.dist from dists, islands as ia on dists.aiid = ia.islandid, islands as ib on dists.biid = ib.islandid order by ia.islandname, ib.islandname;
+    # select ia.islandname, ib.islandname, d.dist from dists as d, islands as ia on d.aiid = ia.islandid, islands as ib on d.biid = ib.islandid order by ia.islandname, ib.islandname;
     
 }
 
+#========== update _ocean-*.txt ==========
+
+our $localtopo_path;
+
+sub localtopo_rewrite () {
+    $localtopo_path= '_ocean-'.(lc $ocean).'.txt';
+    my $fh= new IO::File "$localtopo_path.tmp", 'w';
+    print $fh "# autogenerated - do not edit\n" or die $!;
+    print $fh "ocean $ocean\n" or die $!;
+    my %arches;
+    foreach my $isle (sort keys %wtisland2arch) {
+       my $arch= $wtisland2arch{$isle};
+       push @{ $arches{$arch} }, $isle;
+    }
+    foreach my $arch (sort keys %arches) {
+       print $fh " $arch\n" or die $!;
+       foreach my $isle (@{ $arches{$arch} }) {
+           print $fh "  $isle\n" or die $!;
+       }
+    }
+    print $fh "\n" or die $!;
+    close $fh or die $!;
+}
+
+sub localtopo_commit () {
+    rename "$localtopo_path.tmp", $localtopo_path or die $!;
+}
+
 #========== main program ==========
 
 parse_info_serverside();