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)
Example #2
0
    def test_minimize(self):

        dfa = SimpleDFA(
            {"q0", "q1", "q2", "q3", "q4"},
            MapAlphabet({"a", "b", "c"}),
            "q0",
            {"q3", "q4"},
            {
                "q0": {"a": "q1", "b": "q2"},
                "q1": {"c": "q3"},
                "q2": {"c": "q3"},
                "q3": {"c": "q4"},
                "q4": {"c": "q4"},
            },
        )

        actual_minimized_dfa = dfa.minimize()

        # the renaming of the states is non deterministic, so we need to compare every substructure.
        assert len(actual_minimized_dfa._states) == 4
        assert actual_minimized_dfa._alphabet == ArrayAlphabet(["a", "b", "c"])
        assert actual_minimized_dfa.is_complete()
Example #3
0
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]