#!/usr/bin/perl

for ($i = 0; $i < 20; $i++){
	for ($n = 1; $n <= 1; $n++) {
		for ($s = 1; $s < 15; $s += 3) {
			$dir = "results.$n.$s.$i";
			$ENV{'NUM_AGENTS'} = 5;
			runantfarm(20*$n, 80*$n, $s, $n, $dir);
		}
	}
}

sub runantfarm {
	($TARGETS, $SENSORS, $SPEED, $NUM, $DIR) = @_;
	return if (-e $DIR);

	$CMD = "./runantfarm -targets $TARGETS -sensors $SENSORS -placement ordered -speed $SPEED -width 100 -height 100";

	print "Starting $CMD\n";
	`/usr/bin/time $CMD > $TARGETS.$SENSORS.$NUM.log 2>&1`;
	#`/usr/bin/time $CMD`;
	print "...completed $CMD\n";

	`mkdir -p $DIR`;

	chomp($stat = "TotalUtility\t" . `grep TotalUtility utility.log | cut -d'	' -f3 | average`);
	system("echo $stat > stats.txt");
	chomp($stat = "PossibleUtility\t" . `grep PossibleUtility utility.log | cut -d'	' -f3 | average`);
	system("echo $stat >> stats.txt");
	chomp($stat = "RealRandomUtility\t" . `grep RealRandomUtility utility.log | cut -d'	' -f3 | average`);
	system("echo $stat >> stats.txt");

	`mv *.log *.txt $DIR`;
	`cp ../generic/*.log $DIR`;
	`cp ../simulator/*.log $DIR`;
	`cp ../simulator/simulator.sav $DIR/simulator.$TARGETS.$NUM.$SENSORS.sav`;
}
