chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Feb 2014 20:27:08 +0000 (20:27 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Feb 2014 20:27:08 +0000 (20:27 +0000)
parse

diff --git a/parse b/parse
index 16f09266a2471eff0551b4f25f31e5ba1a6951c8..c04d33b0083cea24f5495e5b35d9e2318083fe1e 100755 (executable)
--- a/parse
+++ b/parse
@@ -157,42 +157,79 @@ foreach my $ia (0..$#ch) {
     }
 }
 
-print "# transitive closure A.6(5)\n";
+sub weaker ($$) {
+    # A.6(7)(1)
+    my ($def1,$def2) = @_;
+    my ($ia,$ix) = @$def1;
+    my ($ib,$iy) = @$def1;
+    return 1 if $vab[$ia][$ix] < $vab[$ib][$iy];
+    return 1 if $vab[$ia][$ix] == $vab[$ib][$iy]
+       && $vab[$ix][$ia] > $vab[$iy][$ib];
+    return 0;
+}
 
-my $tdefeats = $defeats->transitive_closure();
+our $schwartz;
 
-print "# schwartz set A.6(6)\n";
+for (;;) {
+    # loop from A6(5)
 
-my $schwartz = $defeats->copy();
+    print "# transitive closure A.6(5)\n";
 
-foreach my $ia (0..$#ch) {
-    foreach my $ib (0..$#ch) {
-       next if $tdefeats->has_edge($ia,$b);
-       next if !$tdefeats->has_edge($b,$ia);
-       print "not in Schwartz set: $choices[$ia] because $choices[$ib]\n";
-       $schwartz->delete_vertex($ia);
-       last;
+    my $tdefeats = $defeats->transitive_closure();
+
+    print "# schwartz set A.6(6)\n";
+    
+    $schwartz = $defeats->copy();
+
+    foreach my $ia (0..$#ch) {
+       foreach my $ib (0..$#ch) {
+           next if $tdefeats->has_edge($ia,$b);
+           next if !$tdefeats->has_edge($b,$ia);
+           print "not in Schwartz set: $choices[$ia] because $choices[$ib]\n";
+           $schwartz->delete_vertex($ia);
+           last;
+       }
     }
-}
 
-print "# dropping weakest defeats A.6(7)\n";
+    print "# dropping weakest defeats A.6(7)\n";
 
-my @weakest = ();
+    our @weakest = ();
 
-foreach my $edge (@{ $schwartz->edges() }) {
-    if (!@weakest) {
-       # no weakest edges yet
-    } elsif (weaker($edge, $weakest[0])) {
-       # this edge is weaker than previous weakest, start new set
-       @weakest = ();
-    } elsif (weaker($weakest[0], $edge)) {
-       # weakest edge is weaker than this one, ignore this one
-       next;
-    } else {
-       # weakest edge is exactly as weak as this one, add this one
+    foreach my $edge (@{ $schwartz->edges() }) {
+       if (!@weakest) {
+           # no weakest edges yet
+       } elsif (weaker($edge, $weakest[0])) {
+           # this edge is weaker than previous weakest, start new set
+           @weakest = ();
+       } elsif (weaker($weakest[0], $edge)) {
+           # weakest edge is weaker than this one, ignore this one
+           next;
+       } else {
+           # weakest edge is exactly as weak as this one, add this one
+       }
+       push @weakest, $edge;
+    }
+
+    last unless @weakest;
+    
+    printf "weakest defeats %d > %d", 
+       (scalar @{ $vab[$_->[0]][$_->[1]]) },
+       (scalar @{ $vab[$_->[1]][$_->[0]]) };
+    foreach my $weakest (@weakest) {
+       my ($ia,$ib) = @$weakest;
+       print "weakest defeat $choices[$ia] > $choices[$ib]\n";
+       $defeats->delete_edge($ia,$ib);
     }
-    push @weakest, $edge;
+
+    print "# defeats within the Schwartz set, round again\n";
 }
 
-b#p %choices;
+print "# no defeats within the Schwartz set\n";
+print "FINAL SCHWARTZ SET:\n";
+
+print $choices[$_] foreach (@{ $schwartz->nodes() });
+
+print ".\n";
+
+#p %choices;
 #p @vab;