-
Notifications
You must be signed in to change notification settings - Fork 31
/
main_entry.py
36 lines (31 loc) · 1.22 KB
/
main_entry.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
"""
Entrance of the program.
"""
from game import *
from postprocessing import *
import random
def main():
random.seed(RANDOM_SEED)
game = Game()
while game.running and game.current_generation < N_GEN:
game.reset()
game.run()
if PP_FORMULA or PP_GRAPH_VISUALIZATION:
gs = [extract_computational_subgraph(ind) for ind in game.pop]
# note that only the MU parents have been evaluated and have fitness values
if PP_FORMULA:
print("Writing formula to ./pp/formula.txt ...")
with open("./pp/formula.txt", 'w') as f:
for i, g in enumerate(gs):
formula = simplify(g, ['v', 'h', 'g'])
formula = round_expr(formula, PP_FORMULA_NUM_DIGITS)
print(
f"{i}\n score: {game.pop[i].fitness}\n formula: {formula}")
f.write(
f"{i}\n score: {game.pop[i].fitness}\n formula: {formula}\n")
if PP_GRAPH_VISUALIZATION:
print("Drawing graphs to files in folder ./pp ...")
for i, g in enumerate(gs):
visualize(g, f"./pp/g{i}.pdf", input_names=['v', 'h', 'g'])
if __name__ == '__main__':
main()