rhc = RandomizedHillClimbing(hcp) sa = SimulatedAnnealing(100, .95, hcp) ga = StandardGeneticAlgorithm(20, 20, 0, gap) mimic = MIMIC(50, 10, pop) rhc_f = open('out/op/countones/rhc.csv', 'w') sa_f = open('out/op/countones/sa.csv', 'w') ga_f = open('out/op/countones/ga.csv', 'w') mimic_f = open('out/op/countones/mimic.csv', 'w') for i in range(ITERATIONS): rhc.train() rhc_fitness = ef.value(rhc.getOptimal()) rhc_f.write('{},{}\n'.format(i, rhc_fitness)) sa.train() sa_fitness = ef.value(sa.getOptimal()) sa_f.write('{},{}\n'.format(i, sa_fitness)) ga.train() ga_fitness = ef.value(ga.getOptimal()) ga_f.write('{},{}\n'.format(i, ga_fitness)) mimic.train() mimic_fitness = ef.value(mimic.getOptimal()) mimic_f.write('{},{}\n'.format(i, mimic_fitness)) rhc_f.close() sa_f.close() ga_f.close() mimic_f.close()
while iters < 80000: score = rhc.train() f.write(str(iters) + "," + str(score) +"\n") iters += 1 print "RHC: " + str(ef.value(rhc.getOptimal())), "time taken", time() - t0, "Iterations:", iters f.write("starting SA\n") sa = SimulatedAnnealing(1E13, .95, hill_climbing_problem) t0 = time() iters = 0 score = 0 while iters < 80000: score = sa.train() f.write(str(iters) + "," + str(score) + "\n") iters += 1 print "SA: " + str(ef.value(sa.getOptimal())), "time taken", time() - t0, "Iterations", iters ga = StandardGeneticAlgorithm(200, 100, 10, genetic_problem) t0 = time() iters = 0 score = 0 f.write("starting GA\n") while iters < 5000: ga.train() score = ef.value(ga.getOptimal()) f.write(str(iters) + "," + str(score) +"\n")
rhc = RandomizedHillClimbing(hcp) max = 0 i = 0 while (max < goal and i < timeout): rhc.train() i += 1 max = ef.value(rhc.getOptimal()) #print "rhc,", i,",", max, ',', goal print "rhc,", i,",", max, ',', goal # run SA sa = SimulatedAnnealing(1E11, .95, hcp) max = 0 i = 0 while (max < goal and i < timeout): sa.train() i += 1 max = ef.value(sa.getOptimal()) #print "sa,", i,",", max, ',', goal print "sa,", i,",", max, ',', goal # run GA ga = StandardGeneticAlgorithm(200, 100, 25, gap) max = 0 i = 0 while (max < goal and i < timeout): ga.train() i += 200 max = ef.value(ga.getOptimal()) #print "ga,", i,",", max, ',', goal print "ga,", i,",", max, ',', goal