|
1 | 1 | import pandas as pd
|
2 | 2 | from graphviz import Digraph
|
3 | 3 | from itertools import product
|
4 |
| -from typing import Dict, Tuple, List |
| 4 | +from typing import Callable, Dict, Tuple, List |
5 | 5 | from tabulate import tabulate
|
6 | 6 |
|
7 | 7 | State = str
|
8 | 8 | Letter = str
|
| 9 | +SemigroupElement = str |
9 | 10 | StateMachine = Dict[Tuple[State, Letter], State]
|
10 | 11 |
|
11 | 12 | EqvTable = pd.DataFrame
|
12 | 13 | Semigroup = pd.DataFrame
|
| 14 | +Action = Callable[[State, SemigroupElement], State] |
| 15 | +TransformationSemigroup = (List[State], Semigroup, Action) |
13 | 16 |
|
14 | 17 |
|
15 | 18 | def get_states(transitions):
|
@@ -154,9 +157,51 @@ def format_semitable(s: Semigroup):
|
154 | 157 | s.columns = [f"[{col}]" for col in s.columns]
|
155 | 158 | return tabulate(s, headers="keys", tablefmt="grid")
|
156 | 159 |
|
157 |
| -#res2 = create_table(l1, ['a','b','c'], N = 5) |
158 |
| -#u, class_, _ = add_representatives(l1, res2) |
159 |
| -# |
160 |
| -##print(u) |
161 |
| -## |
162 |
| -#r = eqv_class_to_semigroup(l1,['a','b','c'], u) |
| 160 | + |
| 161 | + |
| 162 | +def compatability(states: List[State], sg: Semigroup, a: Action, filter_sames = True): |
| 163 | + pass |
| 164 | + |
| 165 | +def faithfullness(states: List[State], sg: Semigroup, a: Action, filter_sames = True): |
| 166 | + # TODO Think about this some more |
| 167 | + action_results = [] |
| 168 | + for s in states: |
| 169 | + for g1 in sg.index: |
| 170 | + for g2 in sg.index: |
| 171 | + if g1 != g2: |
| 172 | + #q*g1 |
| 173 | + res1 = a(s, g1) |
| 174 | + #q*g2 |
| 175 | + res2 = a(s, g2) |
| 176 | + action_results.append([s, g1, res1 == res2, s, g2]) |
| 177 | + |
| 178 | + action_results = pd.DataFrame(action_results) |
| 179 | + action_results.columns = ['q', 'g1', 'is_same', 'q', 'q2'] |
| 180 | + return action_results[action_results['is_same'] == True] |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +def execute_semigroup(states: List[State], sg: Semigroup, a: Action, filter_sames = True): |
| 186 | + # TODO Think about this some more |
| 187 | + action_results = [] |
| 188 | + for s in states: |
| 189 | + for g1 in sg.index: |
| 190 | + res = a(s, g1) |
| 191 | + action_results.append([s, g1, res]) |
| 192 | + |
| 193 | + action_results = pd.DataFrame(action_results) |
| 194 | + action_results.columns = ['q', 'g1', 'action_result'] |
| 195 | + return action_results |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | +def semigroup_to_machine(tsg: TransformationSemigroup): |
| 200 | + action_table = execute_semigroup(tsg[0], tsg[1], tsg[2]) |
| 201 | + transformations = {} |
| 202 | + |
| 203 | + for _, q1, l, q2 in action_table.itertuples(): |
| 204 | + transformations[(q1, str(l))] = q2 |
| 205 | + |
| 206 | + return transformations |
| 207 | + |
0 commit comments