#!/usr/bin/perl # A little script to run Robert Bosch's program to convert pbn puzzles into # LP's, then run the GNU glpk "glpsol" program on it, and pretty print the # result. http://www.oberlin.edu/math/faculty/bosch/pbn-page.html $input= $ARGV[0]; system("mv $input pbn.dat"); $start= (times)[2]; system("./pbn"); system("glpsol --cpxlp pbn.lp -o pbn.sol"); $end= (times)[2]; open SOL, "pbn.sol" or die("Could not open solution file"); while ($line= ) { if ($line =~ /^Status:\s*(\S.*)$/) { $status= $1; last; } } print "Status: $status\n"; while ($line= ) { if ($line =~ /\sZ(\d+),(\d+)\s+\*\s+(\d+)\s/) { $i= $1; $j= $2; $v= $3; $map[$i-1][$j-1]= ($v ? 'X' : '.'); } } for $row (@map) { print @$row,"\n"; } printf "CPU Time: %.2f seconds\n",$end-$start;