From: Ian Jackson Date: Sun, 2 Feb 2014 20:27:08 +0000 (+0000) Subject: wip X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=0627d3e30d981724e0f97939b551d59a8e167d79 wip --- diff --git a/parse b/parse index 16f0926..c04d33b 100755 --- 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;