+sub parse_database_map () {
+ my ($row,$sth);
+ $sth= $dbh->prepare('SELECT islandname, archipelago FROM islands');
+ $sth->execute();
+ foreach $row ($sth->fetchrow_hashref) {
+ $dbisland2arch{$row->{'islandname'}}= $row->{'archipelago'};
+ }
+ $sth= $dbh->prepare('SELECT dist, a.islandname a, b.islandname b
+ FROM dists
+ JOIN islands AS a ON dists.aiid==a.islandid
+ JOIN islands AS b ON dists.biid==b.islandid');
+ $sth->execute();
+ foreach $row ($sth->fetchrow_hashref) {
+ $dbdists->add_weighted_edge($row->{'a'}, $row->{'b'}, $row->{'dist'});
+ }
+}
+
+sub process_yppedia_graphs () {
+ # Prune the LP database by eliminating boring intermediate vertices
+ foreach my $delete ($widists->vertices()) {
+ next if exists $winode2island{$delete};
+ my @neigh= $widists->neighbours($delete);
+ next unless @neigh==2;
+# my @aneigh= $wiarchs->has_vertex($delete)
+# ? $wiarchs->neighbours($delete) : ();
+# next unless @aneigh==0 || @aneigh==2;
+ my $weight= 0;
+ map { $weight += $widists->get_edge_weight($delete, $_) } @neigh;
+ $widists->add_weighted_edge(@neigh, $weight);
+ $widists->delete_vertex($delete);
+# print PO "$delete elide $weight\n";
+ }
+
+ # Check that it's connected.
+ foreach my $cc ($widists->connected_components()) {
+ next if 2*@$cc > $widists->vertices();
+ my $m= "disconnected league point(s):";
+ foreach my $n (@$cc) {
+ $m .= "\n LP $n, def. yppedia line(s): ".
+ join(',', sort keys %{ $winode2lines{$n} });
+ }
+ warning($m);
+ }
+
+ # Compute all-pairs-shortest-paths on dist, which is the
+ # actual distances between all LPs.
+ my $wialldists= $widists->APSP_Floyd_Warshall();
+
+ # Compute arch's
+ foreach my $label (@wiarchlabels) {
+ my ($ax,$ay,$arch) = @$label;
+ my $d2best= 9999999;
+ my $best;
+ foreach my $vertex ($wiarchs->vertices()) {
+ next unless exists $winode2island{$vertex};
+ my ($vx,$vy) = split /,/, $vertex;
+ my $d2= ($vx-$ax)*($vx-$ax) + ($vy-$ay)*($vy-$ay);
+ next unless $d2 < $d2best;
+ $best= $vertex;
+ $d2best= $d2;
+ }
+ die 'no island vertices?!' unless defined $best;
+ printf PO "%d,%d arch-select-island %s %s\n",
+ $ax,$ay, $arch, $winode2island{$best};
+ my $ccix= $wiarchs->connected_component_by_vertex($best);
+ my $desc= join "\n", map {
+ my $in= $winode2island{$_};
+ " LP $_". (defined $in ? ", $in" : "");
+ } sort $wiarchs->connected_component_by_index($ccix);
+
+ if (exists $wiccix2arch{$ccix}) {
+ error("architecture determination failed:\n".
+ " archipelago $arch\n".
+ " archipelago $wiccix2arch{$ccix}\n".
+ $desc);
+ next;
+ }
+ $wiccix2arch{$ccix}= $arch;
+ print "$ccix $arch ::\n$desc\n";
+ }
+}
+
+sub compare_island_lists () {
+# foreach my $island (keys %dbisland2arch) {
+# next if exists $winode2island
+# error("
+}
+
+db_setocean('Midnight');
+db_connect();