source: framspy/evolalg/frams_base/experiment_frams_niching.py @ 1194

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

Added the "evolalg" module for evolutionary optimization

File size: 2.5 KB
RevLine 
[1190]1from ..base.experiment_niching_abc import ExperimentNiching
2from ..structures.individual import Individual
3from ..structures.population import PopulationStructures
4from ..utils import merge_two_parsers
5from .experiment_frams import ExperimentFrams
6
7
8class ExperimentFramsNiching(ExperimentFrams, ExperimentNiching):
9    def __init__(self, frams_lib, optimization_criteria, hof_size, popsize, constraints, normalize, dissim, fit, genformat, archive_size, save_only_best) -> None:
10        ExperimentFrams.__init__(self, hof_size=hof_size,
11                                 popsize=popsize,
12                                 frams_lib=frams_lib,
13                                 constraints=constraints,
14                                 optimization_criteria=optimization_criteria,
15                                 genformat=genformat,
16                                 save_only_best=save_only_best
17                                 )
18        ExperimentNiching.__init__(self, hof_size=hof_size,
19                                   popsize=popsize,
20                                   fit=fit,
21                                   normalize=normalize,
22                                   save_only_best=save_only_best,
23                                   archive_size=archive_size
24                                   )
25        self.dissim = dissim
26       
27
28    def initialize_evolution(self, genformat, initialgenotype):
29        self.current_generation = 0
30        self.time_elapsed = 0
31        self.stats = []  # stores the best individuals, one from each generation
32        initial_individual = Individual()
33        initial_individual.set_and_evaluate(self.frams_getsimplest(
34            '1' if genformat is None else genformat, initialgenotype), self.evaluate)
35        self.hof.add(initial_individual)
36        self.stats.append(
37            initial_individual.rawfitness if self.save_only_best else initial_individual)
38        self.population_structures = PopulationStructures(
39            initial_individual=initial_individual, archive_size=self.archive_size, popsize=self.popsize)
40        if self.fit == "nsga2":
41            self.do_nsga2_dissim(self.population_structures.population)
42        if self.fit == "nslc":
43            self.do_nslc_dissim(self.population_structures.population)
44
45    def dissimilarity(self, population):
46        return self.frams_lib.dissimilarity([i.genotype for i in population], self.dissim)
47
48
49    @staticmethod
50    def get_args_for_parser():
51        p1 = ExperimentFrams.get_args_for_parser()
52        p2 = ExperimentNiching.get_args_for_parser()
53        return merge_two_parsers(p1, p2)
54
Note: See TracBrowser for help on using the repository browser.