-
Notifications
You must be signed in to change notification settings - Fork 0
/
crossovers_examples.py
60 lines (37 loc) · 1.01 KB
/
crossovers_examples.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 25 12:40:24 2021
@author: qtckp
"""
import sys
sys.path.append('..')
import numpy as np
from geneticalgorithm2 import Crossover
crossovers = [
Crossover.one_point(),
Crossover.two_point(),
Crossover.uniform(),
Crossover.uniform_window(window = 3),
Crossover.shuffle(),
Crossover.segment(),
Crossover.arithmetic(),
Crossover.mixed(alpha = 0.4)
]
x = np.ones(15)
y = x*0
lines = []
for cr in crossovers:
new_x, new_y = cr(x, y)
print(cr.__qualname__.split('.')[1])
print(new_x)
print(new_y)
print()
lines += [
f"* **{cr.__qualname__.split('.')[1]}**:\n",
'|' + ' | '.join(np.round(new_x, 2).astype(str))+'|',
'|' + ' | '.join( [':---:']*x.size )+'|',
'|' + ' | '.join(np.round(new_y, 2).astype(str))+'|',
''
]
with open('./output/crossovers_example.txt', 'w') as file:
file.writelines([line.replace('.0','') + '\n' for line in lines])