chiark / gitweb /
wip cc
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 14 Jan 2019 13:13:42 +0000 (13:13 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 14 Jan 2019 13:13:42 +0000 (13:13 +0000)
parse-input-graph

index f9708086ae30282c3ef9c43265dbcbb96ac3fb3e..3ea008f8abf638d69b3b45cd7272a2d7c1a97b77 100755 (executable)
@@ -3,6 +3,7 @@
 use strict;
 use Carp;
 use Data::Dumper;
+use Graph;
 
 our %region;
 # $region{NAME}{Colour}
@@ -13,6 +14,8 @@ our %region;
 # $region{NAME}{Adj}[]{Regexp}
 # $region{NAME}{Adj}[]{Dikes}
 # $region{NAME}{Adj}[]{L}
+# computed by dual():
+# %region{NAME}{Adj}[]{Vertices}[0..1]
 
 our %adj;
 # $adj{EARLIER}{LATER}{Dikes}
@@ -139,7 +142,46 @@ sub dual () {
   # We want to turn the graph from a graph on the regions, to
   # one where the nodes are the vertices of region boundaries.
   #
-  # Each adjacency in 
+  # Each adjacency in %adj has two ends, each of which is at
+  # such a vertex.  We need to identify which of these vertices
+  # are the same.  We do this by assigning an id to each vertex.
+  #
+  # This is actually a DJF, where the to-be-vertices are the connected
+  # components, and the edges indicate that two vertices are the same.
+
+  my $g = Graph::Undirected->new(unionfind => 1);
+
+  # vertex "<Region Name> # <i>" is the vertex at the
+  # anticlockwise end of the i'th listed edge of Region Name.
+
+  foreach my $ra (sort keys %region) {
+    my $adjsa = $region{$ra}{Adj};
+    foreach my $adjia (0..$#$adjsa) {
+      my $adja = $adjsa->[$adjia];
+      my $va = "$ra # $adjia";
+      # $va is the vertex at the anticlockwise end
+      # of edge no.$adjia of region $ra
+      my $rb = $adja->{Name};
+      # $rb is the region on the other side of that edge
+      my $adjsb = $region{$rb}{Adj};
+      foreach my $adjib (0..$#$adjsb) {
+       my $adjb = $adjsb->[$adjib];
+       next unless $adjb->{Name} eq $ra;
+       # $adjb is the same edge seen from the other side
+       my $adjibc = ($adjib + 1) % @$adjsb;
+       my $vb = "$rb # $adjibc";
+       # $vb is the vertex at the *clockwise* end
+       # of that same edge, which is edge no $adjib of region $rb
+       print STDERR "vertex $va = $vb\n";
+       $g->add_edge($va,$vb);
+       last;
+      }
+    }
+  }
+  foreach my $cc ($g->connected_components) {
+    print STDERR "CC:\n";
+    print STDERR "    $_\n" foreach @$cc;
+  }
 }
 
 sub o { print @_ or die $!; }