forked from CodeReclaimers/neat-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_simple_run.py
61 lines (43 loc) · 1.7 KB
/
test_simple_run.py
1
2
3
4
5
6
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
56
57
58
59
60
61
import os
import neat
def eval_dummy_genome(genome, config):
return 1.0
def eval_dummy_genomes(genomes, config):
for genome_id, genome in genomes:
genome.fitness = eval_dummy_genome(genome, config)
def test_serial():
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter())
stats = neat.StatisticsReporter()
p.add_reporter(stats)
# Run for up to 300 generations.
p.run(eval_dummy_genomes, 300)
stats.save()
def test_parallel():
# Load configuration.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'test_configuration')
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_path)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter())
stats = neat.StatisticsReporter()
p.add_reporter(stats)
# Run for up to 300 generations.
pe = neat.ParallelEvaluator(4, eval_dummy_genome)
p.run(pe.evaluate, 300)
stats.save()
if __name__ == '__main__':
test_serial()
test_parallel()