-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
33 lines (27 loc) · 875 Bytes
/
start.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
from algorithm.main import Algorithm
from algorithm import init
from data import dbManager
from rule import Rule
import sys
if len(sys.argv) != 4:
print("ERROR: start.py usage: \n\npython start.py [initial_rule] [result_name] [iterations]")
exit(-1)
iter = int(sys.argv[3])
initialRuleName = sys.argv[1]
splitRule = initialRuleName.split("/")
Eb = int(splitRule[0][0])
Eh = int(splitRule[0][1])
Fb = int(splitRule[1][0])
Fh = int(splitRule[1][1])
initialRule = (Eb, Eh, Fb, Fh)
# Algorithm
rule, fitness = Algorithm(initialRule).run(iter)
dbManager.insertRule(sys.argv[2], rule.getRuleList())
print("\nRule saved on the database with name: " + sys.argv[2])
# Mutations
rule2 = dbManager.getRuleByName(initialRuleName)
cont = 0
for bit1, bit2 in zip(rule.getRuleList(), rule2):
if bit1 != bit2:
print("Mutated bit in position: ", cont)
cont += 1