1 | |
---|
2 | from ..base.experiment_islands_model_abc import ExperimentIslands |
---|
3 | from ..frams_base.experiment_frams import ExperimentFrams |
---|
4 | from ..structures.individual import Individual |
---|
5 | from ..structures.population import PopulationStructures |
---|
6 | from ..utils import merge_two_parsers |
---|
7 | |
---|
8 | |
---|
9 | class ExperimentFramsIslands(ExperimentIslands, ExperimentFrams): |
---|
10 | def __init__(self, frams_lib, optimization_criteria, hof_size, |
---|
11 | popsize, constraints, genformat, |
---|
12 | number_of_populations, migration_interval, save_only_best) -> None: |
---|
13 | ExperimentFrams.__init__(self, frams_lib=frams_lib, optimization_criteria=optimization_criteria, |
---|
14 | hof_size=hof_size, popsize=popsize, |
---|
15 | genformat=genformat, save_only_best=save_only_best, constraints=constraints) |
---|
16 | |
---|
17 | self.number_of_populations = number_of_populations |
---|
18 | self.migration_interval = migration_interval |
---|
19 | |
---|
20 | def initialize_evolution(self, initialgenotype): |
---|
21 | self.current_generation = 0 |
---|
22 | self.time_elapsed = 0 |
---|
23 | # stores the best individuals, one from each generation across all populations |
---|
24 | self.stats = [] |
---|
25 | initial_individual = Individual() |
---|
26 | initial_individual.set_and_evaluate(self.frams_getsimplest( |
---|
27 | '1' if self.genformat is None else self.genformat, initialgenotype), self.evaluate) |
---|
28 | self.stats.append(initial_individual.rawfitness) |
---|
29 | self.populations= [PopulationStructures(initial_individual=initial_individual, |
---|
30 | popsize=self.popsize) |
---|
31 | for _ in range(self.number_of_populations)] |
---|
32 | @staticmethod |
---|
33 | def get_args_for_parser(): |
---|
34 | parser1 = ExperimentFrams.get_args_for_parser() |
---|
35 | parser2 = ExperimentIslands.get_args_for_parser() |
---|
36 | return merge_two_parsers(parser1, parser2) |
---|