X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=compute;h=4021eb7db6c56537ca59f7b69449a643bc4cc83f;hb=fbc40601bc45c332b834d0c2d95f9cc57936eeb4;hp=c544437bdb05468ed7f94076829c884d609a54f4;hpb=ec0d2dafa7c72f2f7d77e77c7859ca9aad7635d9;p=appendix-a6.git diff --git a/compute b/compute index c544437..4021eb7 100755 --- 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;