-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparent_selection.py
38 lines (29 loc) · 1.31 KB
/
parent_selection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from random import *
def roulette_wheel_selection(population: list[int], fitness_values: list[int], population_size: int) -> list[int]:
"""
Roulette Wheel is a Parent Selection technique. The chromosome is selected according to its fitness probability.
The wheel position is generated as a random number between 0 and 1, because we are dealing with probabilities.
"""
fitness_sum = sum(fitness_values)
fitness_probs = [(fitness / fitness_sum) for fitness in fitness_values]
wheel_position = uniform(0, 1)
comulative_prob = 0
for i in range(population_size):
comulative_prob += fitness_probs[i]
if comulative_prob >= wheel_position:
return population[i]
# -----------------------------------------------------------------------------------
def tournament_selection():
pass
# -----------------------------------------------------------------------------------
def rank_selection():
pass
# -----------------------------------------------------------------------------------
def boltzmann_selection():
pass
# -----------------------------------------------------------------------------------
def random_selection():
pass
# -----------------------------------------------------------------------------------
def stochastic_universal_sampling():
pass