#! /usr/bin/perl -w

use strict;

# Extract approximate held karp bounds from output of lk --held-karp.
# Output format is as instance lines for expt.pl

my $iters = "N/10";
my $seed =0;
my $n=0;
my $d=-1;
my $last_bound = -1;
my $bound = -1;
my $last_file="none";
my $verbose=10;
foreach (@ARGV) {
	my $file = $_;
	print "# $file\n" if $verbose >= 50;
	if ( $file =~ m/^ben.(\d+).(\d+).(\d+)/ ) {
		if ( !($1 == $d && $2 == $seed & $3 == $n) ) {
			print "instance ben.$d.$seed.$n:$n:-l hka $last_bound : $iters\n";
			$last_bound = -1;
			$last_file = $file;
		}
		($d,$seed,$n) = ($1,$2,$3);
		open IN, "grep 'Held-Karp lower bound' $file|";
		while (<IN>) {
			if ( m/^Held-Karp lower bound: (\d+\.\d+)/ ) {
				print "#$_" if $verbose >= 75;
				$bound = $1+0;
				$last_bound >= $bound || ($last_bound = $bound);
			}
		}
		close IN;
	}
}
