+my $defeats = Graph::Directed->new; # A.6(4)
+
+foreach my $ia (0..$#ch) {
+ foreach my $ib (0..$#ch) {
+ my $vab = $vab[$ia][$ib];
+ my $vba = $vab[$ib][$ia];
+ next unless $vab > $vba;
+ print "defeat: $choices[$ia] beats $choices[$ib] ($vab > $vba)\n"
+ or die $!;
+ $defeats->add_vertex($ia,$ib);
+ }
+}
+
+print "# transitive closure A.6(5)\n" or die $!;
+
+my $tdefeats = $defeats->transitive_closure();
+
+print "# schwartz set A.6(6)\n" or die $!;
+
+my $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"
+ or die $!;
+ $schwartz->delete_vertex($ia);
+ last;
+ }
+}
+
+print "# dropping weakest defeats A.6(7)\n" or die $!;
+
+my @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
+ }
+ push @weakest, $edge;
+}