comparison trunk/test.py @ 0:4b2e8e8a633e

Repository setup.
author revcompgeek
date Mon, 03 Mar 2008 19:28:10 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4b2e8e8a633e
1 #!/usr/bin/python
2
3 from subprocess import *
4
5 def frange(*args):
6 l = len(args)
7 if l == 1: # only to
8 f = 0
9 t = args[0]
10 step = 1
11 elif l == 2: # from, to
12 start, stop = args
13 step = 1
14 elif l == 3:
15 start, stop, step = args
16 k = (stop-start)/step+1
17 return map(lambda x, f=start, s=step: f+s*x, range(max(0, int(k))))
18
19 prefix = "/Users/matthew/Desktop/D/ai/"
20 output_prefix = "/Users/matthew/Desktop/D/ai/tests/"
21
22 print "Running..."
23
24
25 repetitions=100
26
27 tests = [
28 ["ga_code","mutation-rate", "-m",frange(0.0,0.05,0.01) + frange(0.1,1,0.05),[]],
29 ["ga_code","population", "-p",frange(500,5000,500),[]],
30 ["ga_code","survival-rate", "-d",frange(0.2,0.8,0.05),[]],
31 ["ga_code","crossover-type","-c",frange(1,3,1),[]],
32 ["ga_code","code-length", "-l",frange(10,30,1),[]],
33
34 ["ga_maze","mutation-rate","-m",frange(0.0,0.05,0.01) + frange(0.1,1,0.05),[]],
35 ["ga_maze","population", "-p",frange(500,5000,500),["-s","9","9"]],
36 ["ga_maze","survival-rate", "-d",frange(0.2,0.8,0.05),[]],
37 ["ga_maze","crossover-type","-c",frange(1,3,1),[]],
38 ["ga_maze","code-length", "-l",frange(10,30,1),[]]
39 ]
40
41 def runTest(exe,name,switch,vrange,addparams):
42 f = open(output_prefix + ("%s_%s_generations.csv" % (exe,name)),"w")
43 f2 = open(output_prefix + ("%s_%s_times.csv" % (exe,name)),"w")
44
45 for i in vrange:
46 print i
47 p = Popen([prefix + exe,switch,str(i),"-r",str(repetitions),"-b","100"]+addparams,stdout=PIPE,bufsize=-1)
48 p.wait()
49 r = "".join(p.stdout.readlines())
50 r = r.split(",");
51 f.write("%s,%s,%s\n" % (str(i),r[0],r[1]))
52 f2.write("%s,%s,%s" % (str(i),r[2],r[3]))
53 f.close()
54 f2.close()
55 #try:
56 for test in tests:
57 print "%s: %s" % (test[0],test[1])
58 runTest(test[0],test[1],test[2],test[3],test[4])
59 #except:
60 # print "Stopped"