def test_to_graphviz(self): dfa = SimpleDFA( {"q0", "q1", "q2", "q3", "q4", "q5"}, MapAlphabet({"a", "b"}), "q0", {"q0"}, {}, ) dfa.to_graphviz() dfa = SimpleDFA( {"q0", "q1", "q2", "q3", "q4", "q5"}, MapAlphabet({"a", "b"}), "q0", {"q3"}, { "q0": {"a": "q0", "b": "q1"}, "q1": {"a": "q0", "b": "q2"}, "q2": {"a": "q3", "b": "q4"}, "q3": {"a": "q3", "b": "q4"}, "q4": {"a": "q3", "b": "q5"}, }, ) dfa.to_graphviz()
def graph_automata(states, alphabet, initial_state, accepting_states, transition_function, name, minimize = False): dfa = SimpleDFA(states, alphabet, initial_state, accepting_states, transition_function) if minimize: graph = dfa.minimize().trim().to_graphviz() else: graph = dfa.to_graphviz() graph.render(name)
def serverGateway(alphabet, states, initialState, acceptingState, transitionList): transitionFunction = _getTransitionFunction(states, transitionList) alphabet = set(alphabet) states = set(states) acceptingState = set(acceptingState) dfa = SimpleDFA(states, alphabet, initialState, acceptingState, transitionFunction) initialDFAGraph = dfa.to_graphviz() initialDFAGraph.render("initial", view=False, format='png') minimizedDFA = dfa.minimize() graph = minimizedDFA.trim().to_graphviz() graph.render("graph", view=False, format='png') with open("initial.png", "rb") as image_file: initialGraphEncoded = base64.b64encode(image_file.read()) with open("graph.png", "rb") as image_file: finalGraphEncoded = base64.b64encode(image_file.read()) return [initialGraphEncoded, finalGraphEncoded]