-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
83 lines (72 loc) · 2.15 KB
/
config.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Configuration:
can be reloaded at runtime.
"""
import math
IMG="./Eternity/"
population_file_saved="try01.dill"
# population_file_base="test_4pieces.txt"
# population_file_base="test_9pieces.txt"
population_file_base="e2pieces.txt"
# NGEN % gen_modulo_elitism : 2000 / 100 = 20
# 20 * elitism_percentage_up : 20 * 4 = 80
# 80 + elitism_percentage_start : 80 + 10 = 90
# elitism_percentage_end = 90
NGEN = 2000
mutate_inpd=0.01
selection_ind_value_step=1
elitism_percentage_start=10
elitism_percentage_up=4
gen_modulo_elitism=100
# diff = connection_completions - score
select_light = 25.0
select_medium = 70.0
# select_heavy for other
# values dynamically computed with init()
initialized = False
size_line = 0
total = 0
corner_pos = []
border_bot_pos = []
border_top_pos = []
border_left_pos = []
border_right_pos = []
border_pos = []
inside_pos = []
score_group_max = 0
def count_nb_pieces():
"""
Doc
"""
nb_pieces = 0
with open(population_file_base) as f:
for i, line in enumerate(f):
if line != "\n": nb_pieces += 1
return nb_pieces
def deduce_line_size():
"""
Doc
"""
return int(round(math.sqrt(count_nb_pieces())))
def init():
"""
Doc
"""
globals()["size_line"] = deduce_line_size()
globals()["total"] = size_line * size_line
globals()["corner_pos"] = [0, size_line - 1, total - size_line, total - 1]
globals()["border_bot_pos"] = range(corner_pos[2] + 1, corner_pos[3])
globals()["border_top_pos"] = range(corner_pos[0] + 1, corner_pos[1])
globals()["border_left_pos"] = range(corner_pos[1] + size_line, corner_pos[3], size_line)
globals()["border_right_pos"] = range(corner_pos[0] + size_line, corner_pos[2], size_line)
globals()["border_pos"] = border_top_pos + border_bot_pos + border_left_pos + border_right_pos
globals()["inside_pos"] = [x for x in range(0, total) if x not in corner_pos and x not in border_pos]
globals()["score_group_max"] = 4 * total
if not initialized:
init()
globals()["initialized"] = True
__all__ = [ "init"
]
__md__ = [
"init"
]