def GraphDFA(self): states = set(self.trans_func.keys()) alphabet = set(self.symbols) dfa = SimpleDFA(states, alphabet, self.initial_state, self.accepting_states, self.trans_func) graph = dfa.trim().to_graphviz() graph.attr(rankdir='LR') source = graph.source WriteToFile('./output/DirectDFA.gv', source) graph.render('./output/DirectDFA.gv', format='pdf', view=True)
def test_trim_simple_case(self): dfa = SimpleDFA( {"q0", "q1", "q2", "sink"}, MapAlphabet({"a", "b"}), "q0", {"q1"}, { "q0": {"a": "q0", "b": "q1"}, "q1": {"a": "sink", "b": "sink"}, "sink": {"a": "sink", "b": "sink"}, }, ) actual_trimmed_dfa = dfa.trim() expected_trimmed_dfa = SimpleDFA( {"q0", "q1"}, MapAlphabet({"a", "b"}), "q0", {"q1"}, {"q0": {"a": "q0", "b": "q1"}}, ) assert actual_trimmed_dfa == expected_trimmed_dfa