[1190] | 1 | from ..base.experiment_niching_abc import ExperimentNiching |
---|
| 2 | from ..structures.individual import Individual |
---|
| 3 | from ..structures.population import PopulationStructures |
---|
| 4 | from ..utils import merge_two_parsers |
---|
| 5 | from .experiment_frams import ExperimentFrams |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | class ExperimentFramsNiching(ExperimentFrams, ExperimentNiching): |
---|
[1270] | 9 | def __init__(self, frams_lib, optimization_criteria, hof_size, popsize, constraints, normalize, dissim, fit, genformat, archive_size, save_only_best, knn_niching, knn_nslc) -> None: |
---|
[1190] | 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, |
---|
[1270] | 23 | archive_size=archive_size, |
---|
| 24 | knn_niching=knn_niching, |
---|
| 25 | knn_nslc=knn_nslc |
---|
[1190] | 26 | ) |
---|
| 27 | self.dissim = dissim |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | def initialize_evolution(self, genformat, initialgenotype): |
---|
| 31 | self.current_generation = 0 |
---|
| 32 | self.time_elapsed = 0 |
---|
| 33 | self.stats = [] # stores the best individuals, one from each generation |
---|
| 34 | initial_individual = Individual() |
---|
| 35 | initial_individual.set_and_evaluate(self.frams_getsimplest( |
---|
| 36 | '1' if genformat is None else genformat, initialgenotype), self.evaluate) |
---|
| 37 | self.hof.add(initial_individual) |
---|
| 38 | self.stats.append( |
---|
| 39 | initial_individual.rawfitness if self.save_only_best else initial_individual) |
---|
| 40 | self.population_structures = PopulationStructures( |
---|
| 41 | initial_individual=initial_individual, archive_size=self.archive_size, popsize=self.popsize) |
---|
| 42 | if self.fit == "nsga2": |
---|
| 43 | self.do_nsga2_dissim(self.population_structures.population) |
---|
| 44 | if self.fit == "nslc": |
---|
| 45 | self.do_nslc_dissim(self.population_structures.population) |
---|
| 46 | |
---|
| 47 | def dissimilarity(self, population): |
---|
| 48 | return self.frams_lib.dissimilarity([i.genotype for i in population], self.dissim) |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | @staticmethod |
---|
| 52 | def get_args_for_parser(): |
---|
| 53 | p1 = ExperimentFrams.get_args_for_parser() |
---|
| 54 | p2 = ExperimentNiching.get_args_for_parser() |
---|
| 55 | return merge_two_parsers(p1, p2) |
---|
| 56 | |
---|