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
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)
 def test_nfa_determinization_bis(self):
     """ Tests an other correct nfa determinization """
     dfa_determined = NFA.nfa_determinization(
         self.nfa_determinization_test_02)
     # automata_IO.dfa_to_dot(dfa_determined, 'nfa_determined_2')
     self.assertEqual(len(dfa_determined['alphabet']), 3)
     self.assertEqual(len(dfa_determined['states']), 14)
     self.assertEqual(len(dfa_determined['accepting_states']), 11)
     self.assertEqual(len(dfa_determined['transitions']), 39)
 def test_nfa_determinization(self):
     """ Tests a correct nfa determinization """
     dfa_determined = NFA.nfa_determinization(
         self.nfa_determinization_test_01)
     # automata_IO.dfa_to_dot(dfa_determined, 'nfa_determined')
     self.assertEqual(len(dfa_determined['alphabet']), 2)
     self.assertEqual(len(dfa_determined['states']), 10)
     self.assertEqual(len(dfa_determined['accepting_states']), 6)
     self.assertEqual(len(dfa_determined['transitions']), 19)
 def test_nfa_determinization_empty_states(self):
     """ Tests a NFA determinization with an empty NFA """
     dfa_determined = NFA.nfa_determinization(
         self.nfa_determinization_test_empty)
     # automata_IO.dfa_to_dot(dfa_determined,
     # 'nfa_determined_empty_States')
     self.assertDictEqual(
         dfa_determined, {
             'alphabet': set(),
             'states': set(),
             'initial_state': None,
             'accepting_states': set(),
             'transitions': {}
         })
 def test_nfa_determinization_empty_transitions(self):
     """ Tests a NFA determinization with a NFA without
     transitions """
     self.nfa_determinization_test_01['transitions'] = {}
     dfa_determined = NFA.nfa_determinization(
         self.nfa_determinization_test_01)
     # automata_IO.dfa_to_dot(dfa_determined,
     # 'nfa_determined_empty_transition')
     self.assertDictEqual(
         dfa_determined, {
             'alphabet':
             self.nfa_determinization_test_01['alphabet'],
             'states':
             {str(self.nfa_determinization_test_01['initial_states'])},
             'initial_state':
             str(self.nfa_determinization_test_01['initial_states']),
             'accepting_states':
             set(),
             'transitions': {}
         })
 def test_nfa_determinization_side_effects(self):
     """ Tests the function doesn't make any side effect on
     the input """
     before = copy.deepcopy(self.nfa_determinization_test_01)
     NFA.nfa_determinization(self.nfa_determinization_test_01)
     self.assertDictEqual(before, self.nfa_determinization_test_01)
 def test_nfa_determinization_wrong_dict(self):
     """ Tests the function using an input different from a
     well formatted dict representing a nfa. [EXPECTED
     FAILURE] """
     NFA.nfa_determinization({'goofy': 'donald'})
 def test_nfa_determinization_wrong_input(self):
     """ Tests the function using an input different from a
     dict object. [EXPECTED FAILURE] """
     NFA.nfa_determinization(0)