This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetrules.py
140 lines (116 loc) · 6.33 KB
/
setrules.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# 1.
rule1 = [
[['a', 'b'], "sk", "k", "m", "g"],
['sk', 'z', 'z', 'z', 'z'],
['k', 'z', 'z', 'z', 'z'],
['m', 'k', 'k', 'z', 'z'],
['g', 'm', 'm', 'k', 'k']
]
rule2 = [
[['a', 'd'], "sk", "k", "m", "g"],
['sk', 'z', 'z', 'z', 'z'],
['k', 'z', 'z', 'z', 'z'],
['m', 'k', 'k', 'z', 'z'],
['g', 'm', 'm', 'k', 'k']
]
rule3 = [
[['c', 'b', 'i'], "sk", "k", "m", "g"],
[['sw', 'sk'], 'z', 'z', 'z', 'z'],
[['sw', 'k'], 'z', 'z', 'z', 'z'],
[['sw', 'm'], 'k', 'k', 'z', 'z'],
[['sw', 'g'], 'm', 'm', 'k', 'k'],
[['w', 'sk'], 'z', 'z', 'z', 'z'],
[['w', 'k'], 'z', 'z', 'z', 'z'],
[['w', 'm'], 'k', 'k', 'z', 'z'],
[['w', 'g'], 'm', 'm', 'k', 'k'],
[['m', 'sk'], 'z', 'z', 'z', 'z'],
[['m', 'k'], 'z', 'z', 'z', 'z'],
[['m', 'm'], 'm', 'm', 'z', 'z'],
[['m', 'g'], 'g', 'g', 'm', 'z'],
[['n', 'sk'], 'z', 'z', 'z', 'z'],
[['n', 'k'], 'k', 'k', 'z', 'z'],
[['n', 'm'], 'm', 'm', 'k', 'z'],
[['n', 'g'], 'g', 'g', 'm', 'k']
]
rule4 = [
[['c', 'd', 'i'], "sk", "k", "m", "g"],
[['sw', 'sk'], 'z', 'z', 'z', 'z'],
[['sw', 'k'], 'z', 'z', 'z', 'z'],
[['sw', 'm'], 'k', 'k', 'z', 'z'],
[['sw', 'g'], 'm', 'm', 'k', 'k'],
[['w', 'sk'], 'z', 'z', 'z', 'z'],
[['w', 'k'], 'z', 'z', 'z', 'z'],
[['w', 'm'], 'k', 'k', 'z', 'z'],
[['w', 'g'], 'm', 'm', 'k', 'k'],
[['m', 'sk'], 'z', 'z', 'z', 'z'],
[['m', 'k'], 'z', 'z', 'z', 'z'],
[['m', 'm'], 'm', 'm', 'z', 'z'],
[['m', 'g'], 'g', 'g', 'm', 'z'],
[['n', 'sk'], 'z', 'z', 'z', 'z'],
[['n', 'k'], 'k', 'k', 'z', 'z'],
[['n', 'm'], 'm', 'm', 'k', 'z'],
[['n', 'g'], 'g', 'g', 'm', 'k']
]
rule5 = [
[['b', 'a'], "sk", "k", "m", "g"],
['sk', 'z', 'z', 'z', 'z'],
['k', 'z', 'z', 'z', 'z'],
['m', 'k', 'z', 'z', 'z'],
['g', 'm', 'm', 'k', 'z']
]
rule6 = [
[['d', 'a'], "sk", "k", "m", "g"],
['sk', 'z', 'z', 'z', 'z'],
['k', 'z', 'z', 'z', 'z'],
['m', 'k', 'z', 'z', 'z'],
['g', 'm', 'm', 'k', 'z']
]
rule7 = [
[['b', 'c', 'i'], ['sw', 'sk'], ['sw', 'k'], ['sw', 'm'], ['sw', 'g'], ['w', 'sk'], ['w', 'k'], ['w', 'm'], ['w', 'g'], ['m', 'sk'], ['m', 'k'], ['m', 'm'], ['m', 'g'], ['n', 'sk'], ['n', 'k'], ['n', 'm'], ['n', 'g']],
['sk', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', ],
['k', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', ],
['m', 'k', 'z', 'z', 'z', 'k', 'z', 'z', 'z', 'k', 'z', 'z', 'z', 'z', 'z', 'z', 'z', ],
['g', 'm', 'm', 'k', 'z', 'm', 'm', 'k', 'z', 'm', 'k', 'k', 'z', 'm', 'k', 'z', 'z', ]
]
rule8 = [
[['d', 'c', 'i'], ['sw', 'sk'], ['sw', 'k'], ['sw', 'm'], ['sw', 'g'], ['w', 'sk'], ['w', 'k'], ['w', 'm'], ['w', 'g'], ['m', 'sk'], ['m', 'k'], ['m', 'm'], ['m', 'g'], ['n', 'sk'], ['n', 'k'], ['n', 'm'], ['n', 'g']],
['sk', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', ],
['k', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', ],
['m', 'k', 'z', 'z', 'z', 'k', 'z', 'z', 'z', 'k', 'z', 'z', 'z', 'z', 'z', 'z', 'z', ],
['g', 'm', 'm', 'k', 'z', 'm', 'm', 'k', 'z', 'm', 'k', 'k', 'z', 'm', 'k', 'z', 'z', ]
]
# regeln in strings umwandeln
rule1_list = []
for row in rule1[1:]:
for ic, column in enumerate(rule1[0][1:]):
rule1_list.append(f"IF {rule1[0][0][0]} IS {row[0]} AND {rule1[0][0][1]} IS {column} THEN xt IS {row[ic+1]}")
for row in rule2[1:]:
for ic, column in enumerate(rule2[0][1:]):
rule1_list.append(f"IF {rule2[0][0][0]} IS {row[0]} AND {rule2[0][0][1]} IS {column} THEN xt IS {row[ic+1]}")
for row in rule3[1:]:
for ic, column in enumerate(rule3[0][1:]):
rule1_list.append(f"IF {rule3[0][0][2]} IS {row[0][0]} AND {rule3[0][0][0]} IS {row[0][1]} AND {rule3[0][0][1]} IS {column} THEN xt IS {row[ic+1]}")
for row in rule4[1:]:
for ic, column in enumerate(rule4[0][1:]):
rule1_list.append(f"IF {rule4[0][0][2]} IS {row[0][0]} AND {rule3[0][0][0]} IS {row[0][1]} AND {rule4[0][0][1]} IS {column} THEN xt IS {row[ic+1]}")
print(*rule1_list, sep='\n')
print("\n_------------_\n")
rule2_list = []
for row in rule5[1:]:
for ic, column in enumerate(rule5[0][1:]):
rule2_list.append(f"IF {rule5[0][0][0]} IS {row[0]} AND {rule5[0][0][1]} IS {column} THEN xt IS {row[ic+1]}")
for row in rule6[1:]:
for ic, column in enumerate(rule6[0][1:]):
rule2_list.append(f"IF {rule6[0][0][0]} IS {row[0]} AND {rule6[0][0][1]} IS {column} THEN xt IS {row[ic+1]}")
for row in rule7[1:]:
for ic, column in enumerate(rule7[0][1:]):
rule2_list.append(f"IF {rule7[0][0][0]} IS {row[0]} AND {rule7[0][0][1]} IS {column[1]} AND {rule7[0][0][2]} IS {column[0]} THEN xt IS {row[ic+1]}")
for row in rule8[1:]:
for ic, column in enumerate(rule8[0][1:]):
rule2_list.append(f"IF {rule8[0][0][0]} IS {row[0]} AND {rule8[0][0][1]} IS {column[1]} AND {rule8[0][0][2]} IS {column[0]} THEN xt IS {row[ic+1]}")
print(*rule2_list, sep='\n')
# regeln in dateien speicher
with open("phase1rules.csv", 'w') as file:
file.write("\n".join(rule1_list))
with open("phase2rules.csv", 'w') as file:
file.write("\n".join(rule2_list))