コード例 #1
0
def dfa_tb_to_diagram(json_filename, output_filename):
    with open(json_filename) as json_file:
        dfa_tb = json.load(json_file)

    # construct nfa parameters
    alphabet = dfa_tb["alphabet"]
    states = dfa_tb["states"]
    dfa = dict()
    dfa["alphabet"] = set(alphabet)
    dfa["states"] = set(states)
    dfa["initial_state"] = dfa_tb["initial_state"]
    dfa["accepting_states"] = set(dfa_tb["accepting_states"])

    # construct dfa transitions from transition table
    transition_table = dfa_tb["transition_table"]
    if len(transition_table) != len(states):
        raise Exception(
            "number of rows in transition table not equal to number of states")
    if len(transition_table[0]) != len(alphabet):
        raise Exception(
            "number of columns in transition table not equal to number of elements in alphabet"
        )

    transitions = dict()
    for i in range(len(states)):
        for j in range(len(alphabet)):
            if len(transition_table[i][j]) > 0:
                transitions[(states[i], alphabet[j])] = transition_table[i][j]
    dfa["transitions"] = transitions
    print(dfa)
    automata_IO.dfa_to_dot(dfa, output_filename)
コード例 #2
0
def read_determinize_minimized_write(path, model):

    nfa = automata_IO.nfa_dot_importer(path + model)
    dfa = NFA.nfa_determinization(nfa)
    automata_IO.dfa_to_dot(dfa, model + '_det', path)
    new_dfa = DFA.dfa_minimization(dfa)
    automata_IO.dfa_to_dot(new_dfa, model + "_det_min", path)
コード例 #3
0
ファイル: index.py プロジェクト: Dragotic-PS/FA-Simulator
    def saveSVG(self, dfaPath=None, dfaName=None, svgPath=None):
        if dfaPath is None or dfaName is None or svgPath is None:
            return

        dfa = self.getFormattedDFA(dfaPath)

        automata_IO.dfa_to_dot(dfa, dfaName, svgPath)
コード例 #4
0
def check_relation(nfa1, nfa2):
    '''
    :param nfa1: nfa
    :param nfa2: nfa
    :return: - 1 if model1 includes model 2
             - -1 if model2 includes model 1
             - 0 if the models are equal
             - otherwise
    '''
    dfa1 = NFA.nfa_determinization(nfa1)
    dfa1_comp = DFA.dfa_complementation(dfa1)
    dfa2 = NFA.nfa_determinization(nfa2)
    dfa2_comp = DFA.dfa_complementation(dfa2)
    words_only_in_model2 = DFA.dfa_nonemptiness_check(DFA.dfa_intersection(dfa1_comp, dfa2))
    words_only_in_model1 = DFA.dfa_nonemptiness_check(DFA.dfa_intersection(dfa2_comp, dfa1))

    if words_only_in_model1\
            and not words_only_in_model2:
        return 1
    elif words_only_in_model2\
            and not words_only_in_model1:
        dfa_intersect = DFA.dfa_intersection(dfa1_comp, dfa2)
        dfa_intersect_minimized = DFA.dfa_co_reachable(DFA.dfa_minimization(dfa_intersect))
        automata_IO.dfa_to_dot(dfa_intersect_minimized, 'csv_intersect', path)
        return -1
    elif not words_only_in_model2\
            and not words_only_in_model1:
        return 0
    else:
        return -1
コード例 #5
0
ファイル: partialAutomata.py プロジェクト: MarcosFelipeBC/lfa
 def createImage(self):
     data = {
         'alphabet': self.partialAlphabet,
         'states': self.partialStates,
         'initial_state': self.completeAutomata.initialState,
         'accepting_states': self.partialAcceptingStates,
         'transitions': self.partialTransitions
     }
 
     automata_IO.dfa_to_dot(data, "partialAutomata", "./resources")
コード例 #6
0
def main():
    automataDict = automata_IO.dfa_json_importer("./resources/automata.json")

    alphabet = automataDict["alphabet"]
    initialState = automataDict["initial_state"]
    transitions = automataDict["transitions"]
    acceptingStates = automataDict["accepting_states"]

    automata_IO.dfa_to_dot(automataDict, "automata", "./resources")

    automata = Automata(alphabet, initialState, transitions, acceptingStates)

    _ = Screen("./resources/automata.dot.svg", automata)
コード例 #7
0
def main():
    automataDict = automata_IO.dfa_json_importer("./resources/AFD.json")

    alphabet = automataDict["alphabet"]
    initialState = automataDict["initial_state"]
    transitions = automataDict["transitions"]
    acceptingStates = automataDict["accepting_states"]
    '''Monta a imagem a partir do Json passado'''
    automata_IO.dfa_to_dot(automataDict, "AFD", "./resources")

    automata = Automata(alphabet, initialState, transitions, acceptingStates)
    '''Screen recebe como parametro o caminho da imagem e também o objeto automato'''
    _ = Screen("./resources/AFD.dot.svg", automata)
コード例 #8
0
ファイル: dfa.py プロジェクト: santo0/Finit_Automat
 def dot_dictionary(self, name: str) -> str:
     """
     Generate svg for automaton
     :param name:
     :param name of svg file:
     """
     dot = dict(initial_state=str(self._sets_start()),
                alphabet=self.__alphabet, states={str(x.state) for x in self.__states},
                accepting_states={str(x.state) for x in self.__states if x.is_final()},
                transitions={(str(x.state), i): x.morphs[i]
                             for x in self.__states for i in self.alphabet})
     automata_IO.dfa_to_dot(dot, name, ".")
     while True:
         if path.exists(f"{name}.dot.svg"):
             return f"./{name}.dot.svg"
コード例 #9
0
 def test_dfa_to_dot(self):
     """ Tests a simple dfa render thorough graphiz library"""
     automata_IO.dfa_to_dot(self.dfa_01, 'graphviz_dfa_render_test',
                            'tests/outputs')
コード例 #10
0
 def test_dfa_graphviz_intersection_render(self):
     """ Tests a rendering of a dfa resulting from an
     intersection, so consisting in more complex nodes"""
     automata_IO.dfa_to_dot(self.dfa_intersected,
                            'graphviz_dfa_intersection_render_test',
                            'tests/outputs')
コード例 #11
0
from PySimpleAutomata import automata_IO
import os, re

os.environ[
    "PATH"] += os.pathsep + 'C:\Program Files (x86)\Graphviz\release\bin'

__location__ = os.path.realpath(
    os.path.join(os.getcwd(), os.path.dirname(__file__)))

for filename in os.listdir(__location__):
    if re.match(".*hypo_\d+.json", filename):
        currdfa = automata_IO.dfa_json_importer(
            os.path.join(__location__, filename))
        automata_IO.dfa_to_dot(currdfa, filename.split('.')[0], __location__)
コード例 #12
0
ファイル: tarea1.py プロジェクト: maupeon/Compiladores
if __name__ == "__main__":
    automata = Automata()
    '''
    In order to run this program you must to create a file called, i.e., "RE.txt" which has to contain the 
    Regular expresion and the alphabet, such as:
    0*.1.0*.1.0*.1.0*
    0
    1
    Where the first line is the RE and the next ones are the alphabet
    '''
    automata.readFile("RE.txt")
    automata.convertREToPostfix()
    automata.convertREToNFA()
    automata.createTransitionMatrix()

    nfa_example = automata_IO.nfa_json_importer('quintuple_NFA.json')
    automata_IO.nfa_to_dot(nfa_example, 'graphic_NFA', './')

    automata.NFA_to_DFA()

    dfa_example = automata_IO.dfa_json_importer('quintuple_DFA.json')
    automata_IO.dfa_to_dot(dfa_example, 'graphic_DFA', './')

    automata.validateStrings()
    print(
        "The quintuple for the NFA is in 'quintuple_NFA.json', the graphic is in 'graphic_NFA.dot.svg'"
    )
    print(
        "The quintuple for the DFA is in 'quintuple_DFA.json', the graphic is in 'graphic_DFA.dot.svg'"
    )
コード例 #13
0
                       False)

        if type(f) == list:
            dfas.extend(f)
        else:
            dfas.append(f)

    if extension == 'pddl3':
        rewards = [1] * len(dfas)

    # return
    if dfa and rm:
        dfas = get_dfas(dfas, rewards, reward=True, minimize=False)
        for i in range(len(dfas)):
            if output == 'dot' or args.image:
                AutIO.dfa_to_dot(dfas[i], f'DFA_{i}')
                if not args.image:
                    os.system(f'rm DFA_{i}.dot.svg')
                else:
                    os.system(f'mv DFA_{i}.dot.svg DFA_{i}.svg')
            if output != 'dot':
                os.system(f'rm DFA_{i}.dot')
                write_output(output, dfas[i], f'DFA_{i}')

        reward_machine = dfa_intersection_to_rm(dfas, args.reduce, reward)
        if output == 'dot' or args.image:
            AutIO.dfa_to_dot(reward_machine, 'RewardMachine')
            if not args.image:
                os.system('rm RewardMachine.dot.svg')
            else:
                os.system(f'mv RewardMachine.dot.svg RewardMachine.svg')
コード例 #14
0
ファイル: 2.1.py プロジェクト: valeporti/imt
from PySimpleAutomata import automata_IO, DFA
import graphviz as gph

dfa = automata_IO.dfa_dot_importer('./parler.dot')
DFA.dfa_completion(dfa)
dfa_min = DFA.dfa_minimization(dfa)
dot_format = automata_IO.dfa_to_dot(dfa_min, 'parler_min')

gph.render('dot', 'png', './parler_min.dot')
#dg = gph.Digraph('parler', filename='parler.gv', engine='dot', format='png', body=dfa)
#dg.render(view=True)
コード例 #15
0
                    instance.read_and_store_states()
                    if is_dfa:
                        instance.read_and_store_initial_states(True)
                        instance.read_and_store_accepting_states()
                        instance.read_and_store_dfa_transitions()
                    else:
                        instance.read_and_store_initial_states()
                        instance.read_and_store_accepting_states()
                        instance.read_and_store_nfa_transitions()

                    with open("Part1.json", "w") as file:
                        json.dump(instance.getData(), file)

                    if is_dfa:
                        dfa = automata_IO.dfa_json_importer('Part1.json')
                        automata_IO.dfa_to_dot(dfa, 'dfa')
                    else:
                        nfa = automata_IO.nfa_json_importer('Part1.json')
                        automata_IO.nfa_to_dot(nfa, 'nfa')

                    is_dfa_nfa_selection_exit = True
                    is_exit = True

            if choice in ["2", 2]:
                instance = COMP5361()
                instance.read_and_store_alphabets()
                instance.read_and_store_states()
                instance.read_and_store_initial_states()
                instance.read_and_store_accepting_states()
                instance.read_and_store_nfa_transitions()
                instance.nfa_to_dfa_conversion()
コード例 #16
0
ファイル: Prueba.py プロジェクト: Jamidd/Flat
        for node in dfa:
            if node not in new_nodes:
                new_nodes[node] = i
                i += 1
            new_edges = {}
            for edge in dfa[node]:
                if dfa[node][edge] not in new_nodes:
                    new_nodes[dfa[node][edge]] = i
                    i += 1
                new_edges[edge] = new_nodes[dfa[node][edge]]
            full_dfa[new_nodes[node]] = new_edges

            if end_num in node:
                goals.add(new_nodes[node])

        return full_dfa, goals

    end_num = init_first_last_pos()
    set_first_last_pos(formula)
    set_follow_pos(formula)
    set_dfa()
    dfa, goals = prettify_dfa(end_num)
    return dfa, goals
"""
trans.pass_trough_mona(formula)
dfa = trans.read_dfa('dfa.txt')


automata_IO.dfa_to_dot(dfa, 'eliminar.dfa', './')