| Total Complexity | 3 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | import random |
||
| 6 | import numpy as np |
||
| 7 | |||
| 8 | from .base_population_optimizer import BasePopulationOptimizer |
||
| 9 | |||
| 10 | |||
| 11 | class EvolutionaryAlgorithmOptimizer(BasePopulationOptimizer): |
||
| 12 | def __init__(self, *args, **kwargs) -> None: |
||
| 13 | super().__init__(*args, **kwargs) |
||
| 14 | |||
| 15 | def discrete_recombination(self, parent_pos_l, crossover_rates=None): |
||
| 16 | n_parents = len(parent_pos_l) |
||
| 17 | size = parent_pos_l[0].size |
||
| 18 | |||
| 19 | choice = [] |
||
| 20 | for _ in range(size): |
||
| 21 | choices = list(range(n_parents)) |
||
| 22 | choice.append(np.random.choice(choices, p=crossover_rates)) |
||
| 23 | |||
| 24 | return np.choose(choice, parent_pos_l) |
||
| 25 |