Module: GABenchmark
Defined Under Namespace
Classes: StrategiesDSL
Instance Method Summary collapse
-
#benchmark(genotype_class, html_outfile = 'report.html', csv_outfile = nil, &b) ⇒ Object
This method generates reports comparing several selection/crossover/mutation methods.
Instance Method Details
#benchmark(genotype_class, html_outfile = 'report.html', csv_outfile = nil, &b) ⇒ Object
This method generates reports comparing several selection/crossover/mutation methods. Check the examples directory for several examples. See the BENCHMARK documentation file for more information.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/charlie/gabenchmark.rb', line 7 def benchmark(genotype_class, html_outfile='report.html', csv_outfile=nil, &b) start = Time.now dsl_obj = StrategiesDSL.new; dsl_obj.instance_eval(&b) all_tests = dsl_obj.get_tests generations = dsl_obj.generations population_size = dsl_obj.population_size repeat_tests = dsl_obj.repeat setup_proc = dsl_obj.setup teardown_proc = dsl_obj.teardown track_stat = dsl_obj.track_stat n_tests = all_tests.size tests_done = 0 puts "#{n_tests} Total tests:" overall_best = [nil, -1.0 / 0.0] data = all_tests.map{|selection_module,crossover_module,mutator_module| tests_done += 1 print "\nRunning test #{tests_done}/#{n_tests} : #{selection_module} / #{crossover_module} / #{mutator_module}\t" gclass = Class.new(genotype_class) { use selection_module,crossover_module,mutator_module } start_test = Time.now test_stats = (0...repeat_tests).map{ print '.'; $stdout.flush population = Population.new(gclass,population_size) setup_proc.call(population) best = population.evolve_silent(generations).last stat = track_stat.call(best) teardown_proc.call(population) overall_best = [best, stat] if overall_best[0].nil? || (overall_best[1] <=> stat) < 0 # use <=> to allow arrays stat } [selection_module, crossover_module,mutator_module, (Time.now-start_test) / repeat_tests, test_stats] } html_output(html_outfile, data, genotype_class, Time.now-start, overall_best, dsl_obj) csv_output(csv_outfile , data) puts '',table_details(data).to_s return data end |