def __construct_min_dfa_from_marked_states(self, marked_states): sigma = self.get_sigma() final_states = self.get_final_states() unmarked_states = self.__get_unmarked_states(marked_states) new_delta_table = {} new_states = [] ##print 'Unmarked state pairs:' ##print_unmarked_state_pairs(marked_states) for old_state in self.get_states(): eqc = self.__construct_equivalence_class_for_state( old_state, unmarked_states) if len(eqc) > 0 and not eqc in new_states: new_states.append(eqc) old_start_state = self.get_start_state() ##print 'New States: ', str(new_states) new_start_state = [s for s in new_states if old_start_state in s][0] ##print 'New Start State: ', new_start_state ##return None q_of_states = [new_start_state] explored_states = {} while len(q_of_states) != 0: ##print q_of_states curr_state = q_of_states.pop() explored_states[curr_state] = True for s in sigma: old_state = self.delta(curr_state[0], s) new_state = self.__find_equivalence_class_for_state( old_state, new_states) if new_state == None: new_state = old_state, new_delta_table[(curr_state, s)] = new_state if not explored_states.has_key(new_state): q_of_states.append(new_state) rslt_dfa = DFA() rslt_dfa.set_states(set([x[0] for x in new_delta_table.iterkeys()])) rslt_dfa.set_sigma(sigma) rslt_dfa.set_start_state(new_start_state) rslt_dfa.set_delta_table(new_delta_table) rslt_dfa.set_final_states( set([ x[0] for x in new_delta_table.iterkeys() if len(final_states.intersection(set(x[0]))) > 0 ])) return rslt_dfa
def __construct_min_dfa_from_marked_states(self, marked_states): sigma = self.get_sigma() final_states = self.get_final_states() unmarked_states = self.__get_unmarked_states(marked_states) new_delta_table = {} new_states = [] ##print 'Unmarked state pairs:' ##print_unmarked_state_pairs(marked_states) for old_state in self.get_states(): eqc = self.__construct_equivalence_class_for_state(old_state, unmarked_states) if len(eqc) > 0 and not eqc in new_states: new_states.append(eqc) old_start_state = self.get_start_state() ##print 'New States: ', str(new_states) new_start_state = [s for s in new_states if old_start_state in s][0] ##print 'New Start State: ', new_start_state ##return None q_of_states = [new_start_state] explored_states = {} while len(q_of_states) != 0: ##print q_of_states curr_state = q_of_states.pop() explored_states[curr_state] = True for s in sigma: old_state = self.delta(curr_state[0], s) new_state = self.__find_equivalence_class_for_state(old_state, new_states) if new_state == None: new_state = old_state, new_delta_table[(curr_state, s)] = new_state if not explored_states.has_key(new_state): q_of_states.append(new_state) rslt_dfa = DFA() rslt_dfa.set_states(set([x[0] for x in new_delta_table.iterkeys()])) rslt_dfa.set_sigma(sigma) rslt_dfa.set_start_state(new_start_state) rslt_dfa.set_delta_table(new_delta_table) rslt_dfa.set_final_states(set([x[0] for x in new_delta_table.iterkeys() if len(final_states.intersection(set(x[0]))) > 0])) return rslt_dfa