-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_genetic_algorithm.py
More file actions
69 lines (51 loc) · 2.53 KB
/
test_genetic_algorithm.py
File metadata and controls
69 lines (51 loc) · 2.53 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from hklearn_genetic.genetic_algorithm import GeneticAlgorithm
class TestRouletteGeneticAlgorithm(GeneticAlgorithm):
def __init__(self, r_probs, pc = 0.6, pm = 0.1, max_iter = 5000, elitism = None, selection = "proportional"):
super().__init__(pc = pc, pm = pm, max_iter = max_iter, elitism = elitism, selection = selection)
self.roulette_probs = r_probs
# self.crossover_points = c_points
# self.crossover_probs = c_probs
# self.mutation_probs = m_probs
def set_roulette_probs(self, r_probs):
self.roulette_probs = r_probs
#return np.array([[0.25410149, 0.71410111, 0.31915886, 0.45725239]])
# def set_mutation(self, m_probs):
# self.mutation_probs = m_probs
# def set_crossover_probs(self, c_probs):
# self.crossover_probs = c_probs
# def set_crossover_points(self, c_points):
# self.crossover_points = c_points
def get_roulette_probs(self, n_individuals):
return self.roulette_probs
#return np.array([[0.25410149, 0.71410111, 0.31915886, 0.45725239]])
# def get_mutation(self, shape):
# return self.mutation_probs
# def get_crossover_probs(self, n_cross):
# return self.crossover_probs
# def get_crossover_points(self, length):
# return self.crossover_points
class TestSinglePointCrossover(GeneticAlgorithm):
def __init__(self, c_points, c_probs, pc = 0.6, pm = 0.1, max_iter = 5000, elitism = None, selection = "proportional"):
super().__init__(pc = pc, pm = pm, max_iter = max_iter, elitism = elitism, selection = selection)
# self.roulette_probs = r_probs
self.crossover_points = c_points
self.crossover_probs = c_probs
# self.mutation_probs = m_probs
#return np.array([[0.25410149, 0.71410111, 0.31915886, 0.45725239]])
# def set_roulette_probs(self, r_probs):
# self.roulette_probs = r_probs
# def set_mutation(self, m_probs):
# self.mutation_probs = m_probs
def set_crossover_probs(self, c_probs):
self.crossover_probs = c_probs
def set_crossover_points(self, c_points):
self.crossover_points = c_points
# def get_roulette_probs(self, n_individuals):
# return self.roulette_probs
# #return np.array([[0.25410149, 0.71410111, 0.31915886, 0.45725239]])
# def get_mutation(self, shape):
# return self.mutation_probs
def get_crossover_probs(self, n_cross):
return self.crossover_probs
def get_crossover_points(self, length):
return self.crossover_points