Skip to content

Commit

Permalink
finally?
Browse files Browse the repository at this point in the history
  • Loading branch information
TreshMom committed Mar 4, 2024
1 parent bf87ad0 commit 882d824
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 109 deletions.
6 changes: 3 additions & 3 deletions project/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .task_2 import regex_to_min_dfa, create_nfa
from .task2 import regex_to_dfa, graph_to_nfa
from .task_1 import graph_info, create_labeled_two_cycle_graph

__all__ = [
"graph_info",
"create_labeled_two_cycle_graph",
"regex_to_min_dfa",
"create_nfa",
"regex_to_dfa",
"graph_to_nfa",
]
28 changes: 28 additions & 0 deletions project/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pyformlang.regular_expression import *
from pyformlang.finite_automaton import *
from networkx import MultiDiGraph
from typing import Set


def regex_to_dfa(regex: str) -> DeterministicFiniteAutomaton:
return Regex(regex).to_epsilon_nfa().minimize()


def graph_to_nfa(
graph: MultiDiGraph, start_states: Set[int], final_states: Set[int]
) -> NondeterministicFiniteAutomaton:
nfa = NondeterministicFiniteAutomaton()

if not start_states:
start_states = set(graph.nodes())
if not final_states:
final_states = set(graph.nodes())

for state in start_states:
nfa.add_start_state(State(state))
for state in final_states:
nfa.add_final_state(State(state))
for s, e, label in graph.edges(data="label"):
nfa.add_transition(s, label, e)

return nfa
33 changes: 0 additions & 33 deletions project/task_2.py

This file was deleted.

73 changes: 0 additions & 73 deletions tests/test_task_2.py

This file was deleted.

0 comments on commit 882d824

Please sign in to comment.