Mentions légales du service

Skip to content
Snippets Groups Projects
Commit e36a9d82 authored by Djildé-Mbénard Dabo's avatar Djildé-Mbénard Dabo
Browse files

Optimization in final states computations

parent 9bcbcf31
No related branches found
No related tags found
No related merge requests found
......@@ -791,7 +791,7 @@ class DFA(NFA):
def minimize(self) -> "DFA":
def components_of_minimized_automata(
minimized_states: Iterable[Hashable],
) -> tuple[Iterable[tuple[Hashable, Hashable, Hashable]], Hashable]:
) -> tuple[Iterable[tuple[Hashable, Hashable, Hashable]], Hashable, Iterable[Hashable]]:
"""
Intermediary function that, from a list containing tuples compounded by sets of equivalent states as well
as their key, returns another tuple containing the transitions that correspond to the ones in between the
......@@ -802,10 +802,13 @@ class DFA(NFA):
init_state = 0
transitions = set()
final_states = set()
for state in minimized_states:
if self.initial_state in state:
# Assignment of new initial state
init_state = state
if self.final_states.intersection(state):
final_states.add(state)
# In order to compute the new transitions, we take a random state from each set of equivalent states,
# we then look for its successor (another state) though each letter of the alphabet (as each state needs
......@@ -818,7 +821,7 @@ class DFA(NFA):
if successor.issubset(successor_state):
transitions.add((state, letter, successor_state))
continue
return transitions, init_state
return transitions, init_state, final_states
def split(classes_eq: Iterable[C]) -> Iterable[C]:
"""
......@@ -870,14 +873,10 @@ class DFA(NFA):
# With subsets considered the equivalent states (states of minimized automata), it is now possible to compute
# the transitions of these new states, as well as initial state.
tr, init = components_of_minimized_automata(states_classes)
tr, init, final_states = components_of_minimized_automata(states_classes)
# Final states are computable as well
final_states = set()
for f in states_classes:
if self.final_states.intersection(f):
final_states.add(f)
return DFA(tr, init, final_states)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment