#!/usr/bin/perl

# From an adjacency matrix, produce a graphviz .dot file

$in = $ARGV[0];
die "USAGE: $0 <input>\n" unless $in;

open(IN, "<$in") or die "Could not open file: $in";
print "strict graph g {\n";
print "\tgraph [size=\"4,4\"]\n";
print "\tnode [shape=circle, style=filled]\n";

$r = 0;
while (<IN>) {
	chomp;
	@v = split / /, $_; 
	printf "\t%d -- {", $r;
	$cols = scalar(@v);
	for ($c=0; $c<$cols; $c++) {
		if ($c != $r) {
			if ($v[$c] == 1) {
				printf "%d ", $c;
			}
		}
	}
	print "}\n";

	if ($r < 14) {
		printf "\t%d [color=\"red\"]\n", $r;
	} else {
		printf "\t%d [color=\"green\"]\n", $r;
	}
	$r++;
}
close(IN);
print "}\n";

