view trunk/test.py @ 0:4b2e8e8a633e

Repository setup.
author revcompgeek
date Mon, 03 Mar 2008 19:28:10 -0700
parents
children
line wrap: on
line source

#!/usr/bin/python

from subprocess import *

def frange(*args):
	l = len(args)
	if l == 1: # only to
		f = 0
		t = args[0]
		step = 1
	elif l == 2: # from, to
		start, stop = args
		step = 1
	elif l == 3:
		start, stop, step = args
	k = (stop-start)/step+1
	return map(lambda x, f=start, s=step: f+s*x, range(max(0, int(k))))

prefix = "/Users/matthew/Desktop/D/ai/"
output_prefix = "/Users/matthew/Desktop/D/ai/tests/"

print "Running..."


repetitions=100

tests = [
	["ga_code","mutation-rate", "-m",frange(0.0,0.05,0.01) + frange(0.1,1,0.05),[]],
	["ga_code","population",    "-p",frange(500,5000,500),[]],
	["ga_code","survival-rate", "-d",frange(0.2,0.8,0.05),[]],
	["ga_code","crossover-type","-c",frange(1,3,1),[]],
	["ga_code","code-length",   "-l",frange(10,30,1),[]],
	
	["ga_maze","mutation-rate","-m",frange(0.0,0.05,0.01) + frange(0.1,1,0.05),[]],
	["ga_maze","population",   "-p",frange(500,5000,500),["-s","9","9"]],
	["ga_maze","survival-rate", "-d",frange(0.2,0.8,0.05),[]],
	["ga_maze","crossover-type","-c",frange(1,3,1),[]],
	["ga_maze","code-length",   "-l",frange(10,30,1),[]]
]

def runTest(exe,name,switch,vrange,addparams):
	f  = open(output_prefix + ("%s_%s_generations.csv" % (exe,name)),"w")
	f2 = open(output_prefix + ("%s_%s_times.csv" % (exe,name)),"w")
	
	for i in vrange:
		print i
		p = Popen([prefix + exe,switch,str(i),"-r",str(repetitions),"-b","100"]+addparams,stdout=PIPE,bufsize=-1)
		p.wait()
		r = "".join(p.stdout.readlines())
		r = r.split(",");
		f.write("%s,%s,%s\n" % (str(i),r[0],r[1]))
		f2.write("%s,%s,%s" % (str(i),r[2],r[3]))
	f.close()
	f2.close()
#try:
for test in tests:
	print "%s: %s" % (test[0],test[1])
	runTest(test[0],test[1],test[2],test[3],test[4])
#except:
#	print "Stopped"