text
stringlengths
0
828
transitions_map.items(),
key=lambda x: len(
x[1]))
if len(sorted_transitions) == 1:
# Just put 1 symbol is enough all other'input_string will be generalized
# by the guardgen algorithm
chars_in_smi.append(self.alphabet[0])
else:
# Otherwise insert in smi_vector all transitions as explicit except
# the one from the sink transition where we add just enough
# explicity transitions to make sure that this state will be
# selected as the sink state.
#
# If no transition has a clear advantage in terms of symbols then
# just add all transitions in explicit form because it may be the
# case the guardgen() will generalize in the wrong transition.
for (_, char_list) in sorted_transitions[:-1]:
chars_in_smi += char_list
sink_chars = len(sorted_transitions[-2][1]) + 1
chars_in_smi.extend(sorted_transitions[-1][1][:sink_chars])
access_string = access_strings_map[selected_state.stateid]
smi.extend([access_string + character for character in chars_in_smi])
return smi"
1558,"def _init_using_k_equivalence(self, given_graph, sfa=False):
""""""
Args:
given_graph (DFA): The DFA states
sfa (boolean): A boolean for chosing SFA
Return:
list, list, list: sm_vector, smi_vector, em_vector initialization vectors
""""""
graph = DFA(self.alphabet)
graph.init_from_acceptor(given_graph)
graph.fixminimized(self.alphabet)
# Access Strings
self.access_strings_map = self._bfs_path_states(graph, sorted(
graph.states, key=attrgetter('initial'), reverse=True)[0])
# Find Q
set_q = set(self._object_set_to_state_list(graph.states))
# We will work with states addresses here instead of states stateid for
# more convenience
set_f = set(self._object_set_to_state_list(self._get_accepted(graph)))
# Perform P := {F, Q-F}
set_nf = set_q.copy() - set_f.copy()
self.groups = [set_f.copy(), set_nf.copy()]
self.bookeeping = [(set_f, set_nf, '')]
done = False
while not done:
done = True
new_groups = []
for selectgroup in self.groups:
# _check for each letter if it splits the current group
for character in self.alphabet:
# print 'Testing symbol: ', c
target = defaultdict(list)
target_states = defaultdict(int)
new_g = [set(selectgroup)]
for sid in selectgroup:
# _check if all transitions using c are going in a state
# in the same group. If they are going on a different
# group then split
deststate = self._delta(graph, graph[sid], character)
destgroup = self._get_group_from_state(
deststate.stateid)
target[destgroup].append(sid)
target_states[destgroup] = deststate.stateid
if len(target) > 1:
inv_target_states = {
v: k for k, v in target_states.iteritems()}
new_g = [set(selectedstate) for selectedstate in target.values()]
done = False
# Get all the partitions of destgroups
queue = [set([x for x in target_states.values()])]
while queue:
top = queue.pop(0)
(group1, group2, distinguish_string) = self._partition_group(top)
ng1 = self._reverse_to_source(
target, [inv_target_states[x] for x in group1])
ng2 = self._reverse_to_source(
target, [inv_target_states[x] for x in group2])
dist_string = character + distinguish_string
self.bookeeping.append((ng1, ng2, dist_string))
if len(group1) > 1:
queue.append(group1)
if len(group2) > 1:
queue.append(group2)
break
new_groups += new_g
# End of iteration for the k-equivalence
# Assign new groups and check if any change occured