chiark / gitweb /
remove Data::Printer debugging option
[appendix-a6.git] / compute
diff --git a/compute b/compute
index c544437bdb05468ed7f94076829c884d609a54f4..4021eb7db6c56537ca59f7b69449a643bc4cc83f 100755 (executable)
--- a/compute
+++ b/compute
@@ -53,8 +53,8 @@ use strict;
 use utf8;
 use autodie;
 
-use Data::Printer;
 use Graph::Directed;
+use Graph::Writer::GraphViz;
 
 binmode STDIN, 'encoding(UTF-8)';
 binmode STDOUT, 'encoding(UTF-8)';
@@ -67,6 +67,19 @@ our @invotes_cc;
 our $defcho;
 our $quorum = 0;
 
+our $gfile;
+
+while (@ARGV && $ARGV[0] =~ /^-/) {
+    local $_ = shift @ARGV;
+    if (m/^--?$/) {
+       last;
+    } elsif (s/^-g//) {
+       $gfile = $_;
+    } else {
+       die "bad usage\n";
+    }
+}
+
 sub addchoice {
     my $choname = shift @_;
     my $cho = $choices{$choname} = {
@@ -311,6 +324,8 @@ sub weaker ($$) {
     return 0;
 }
 
+our $showg = $defeats->deep_copy();
+
 our $schwartz;
 
 for (;;) {
@@ -391,6 +406,20 @@ if ($schwartz->vertices() == 1) {
 printf "    %-5s %s\n", $_, $choices{$_}{Desc}
     foreach ($schwartz->vertices());
 
+if (defined $gfile) {
+    foreach my $cho (values %choices) {
+       my $chn = $choices[$cho->{Index}];
+       my $label = "\\N\n$cho->{Desc}";
+       if ($cho->{Dropped}) {
+           $label .= "\nDropped: $cho->{Dropped}";
+       }
+       $showg->set_vertex_attribute($chn, 'label', $label);
+    }
+
+    my $gwriter = new Graph::Writer::GraphViz -format => 'ps';
+    $gwriter->write_graph($showg, $gfile);
+}
+
 print ".\n";
 
 #p %choices;