Skip to content

Commit

Permalink
Fix elisitm operator with incorrent sorting direction
Browse files Browse the repository at this point in the history
  • Loading branch information
gkirgizov committed Sep 12, 2022
1 parent 45664fa commit 8b33ed4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fedot/core/optimisers/gp_comp/operators/elitism.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ def _keep_n_best_elitism(self, best_individuals: PopulationT, new_population: Po

def _replace_worst_elitism(self, best_individuals: PopulationT, new_population: PopulationT) -> PopulationT:
population = best_individuals + new_population
sorted_ascending_population = sorted(population, key=lambda individual: individual.fitness)
return sorted_ascending_population[:len(new_population)]
sorted_from_best_to_worst = sorted(population, key=lambda individual: individual.fitness, reverse=True)
return sorted_from_best_to_worst[:len(new_population)]
4 changes: 1 addition & 3 deletions test/unit/optimizer/test_elitism_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from test.unit.optimizer.test_evaluation import prepared_objective
from test.unit.pipelines.test_node_cache import pipeline_first, pipeline_second, pipeline_third, pipeline_fourth, \
pipeline_fifth

if TYPE_CHECKING:
from fedot.core.optimisers.gp_comp.gp_params import GPGraphOptimizerParameters
from fedot.core.optimisers.gp_comp.gp_params import GPGraphOptimizerParameters


@pytest.fixture()
Expand Down

0 comments on commit 8b33ed4

Please sign in to comment.