source: framspy/evolalg/frams_base/experiment_frams_islands.py @ 1235

Last change on this file since 1235 was 1190, checked in by Maciej Komosinski, 2 years ago

Added the "evolalg" module for evolutionary optimization

File size: 1.8 KB
Line 
1
2from ..base.experiment_islands_model_abc import ExperimentIslands
3from ..frams_base.experiment_frams import ExperimentFrams
4from ..structures.individual import Individual
5from ..structures.population import PopulationStructures
6from ..utils import merge_two_parsers
7
8
9class 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)
Note: See TracBrowser for help on using the repository browser.