chiark / gitweb /
graphviz: label the winning node(s)
[appendix-a6.git] / compute
diff --git a/compute b/compute
index 4021eb7db6c56537ca59f7b69449a643bc4cc83f..58b3587d69cc216827e8e7a1f23987f0aae51c60 100755 (executable)
--- a/compute
+++ b/compute
@@ -294,9 +294,9 @@ sub chremain () {
     return grep { !$ch[$_]{Dropped} } (0..$#ch);
 }
 
-foreach my $ia (chremain()) {
+foreach my $ia (0..$#ch) {
     $defeats->add_vertex($choices[$ia]);
-    foreach my $ib (chremain()) {
+    foreach my $ib (0..$#ch) {
        my $vab = scalar @{ $vab[$ia][$ib] };
        my $vba = scalar @{ $vab[$ib][$ia] };
        next unless $vab > $vba;
@@ -304,6 +304,11 @@ foreach my $ia (chremain()) {
        print "defeat: $choices[$ia] beats $choices[$ib]",
            " ($vab > $vba = +$diff)\n";
        $defeats->add_edge($choices[$ia],$choices[$ib]);
+       my $label = "$diff($vab:$vba)";
+       $label .= "\n". join ' ', @{ $vab[$ia][$ib] };
+       $label .= "\n/". join ' ', @{ $vab[$ib][$ia] };
+       $defeats->set_edge_attribute($choices[$ia],$choices[$ib],
+                                    label => $label);
     }
 }
 
@@ -326,6 +331,12 @@ sub weaker ($$) {
 
 our $showg = $defeats->deep_copy();
 
+foreach my $ix (0..$#ch) {
+    my $cho = $ch[$ix];
+    next unless $cho->{Dropped};
+    $defeats->delete_vertex($choices[$ix]);
+}
+
 our $schwartz;
 
 for (;;) {
@@ -397,10 +408,13 @@ for (;;) {
 print "no defeats within the Schwartz set\n";
 print "final schwartz set:\n\n";
 
+my $winxlabel;
 if ($schwartz->vertices() == 1) {
     print "WINNER IS:\n";
+    $winxlabel = "winner";
 } else {
     print "WINNER IS ONE OF (CASTING VOTE DECIDES):\n";
+    $winxlabel = "potential winner";
 }
 
 printf "    %-5s %s\n", $_, $choices{$_}{Desc}
@@ -413,6 +427,9 @@ if (defined $gfile) {
        if ($cho->{Dropped}) {
            $label .= "\nDropped: $cho->{Dropped}";
        }
+       if ($schwartz->has_vertex($chn)) {
+           $label .= "\n$winxlabel";
+       }
        $showg->set_vertex_attribute($chn, 'label', $label);
     }