def detect_cut(self, second_iteration=False): """ Detect generally a cut in the graph (applying all the algorithms) """ if pkgutil.find_loader("networkx"): import networkx as nx else: msg = "networkx is not available. inductive miner cannot be used!" logging.error(msg) raise Exception(msg) if self.dfg: this_nx_graph = transform_dfg_to_directed_nx_graph(self.dfg, activities=self.activities) conn_components = detection_utils.get_connected_components(self.ingoing, self.outgoing, self.activities) strongly_connected_components = [list(x) for x in nx.strongly_connected_components(this_nx_graph)] xor_cut = self.detect_xor_cut(conn_components, this_nx_graph, strongly_connected_components) if xor_cut[0]: for comp in xor_cut[1]: new_dfg = filter_dfg_on_act(self.dfg, comp) self.detected_cut = "xor" self.children.append( SubtreeDFGBased(new_dfg, self.master_dfg, self.initial_dfg, comp, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities)) else: seq_cut = self.detect_sequential_cut(conn_components, this_nx_graph, strongly_connected_components) if seq_cut[0]: self.detected_cut = "sequential" for child in seq_cut[1]: dfg_child = filter_dfg_on_act(self.dfg, child) self.children.append( SubtreeDFGBased(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities)) self.put_skips_in_seq_cut() else: par_cut = self.detect_parallel_cut(conn_components, this_nx_graph, strongly_connected_components) if par_cut[0]: self.detected_cut = "parallel" for comp in par_cut[1]: new_dfg = filter_dfg_on_act(self.dfg, comp) self.children.append( SubtreeDFGBased(new_dfg, self.master_dfg, new_dfg, comp, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities)) else: loop_cut = self.detect_loop_cut(conn_components, this_nx_graph, strongly_connected_components) if loop_cut[0]: if loop_cut[2]: self.detected_cut = "loopCut" for index_enum, child in enumerate(loop_cut[1]): dfg_child = filter_dfg_on_act(self.dfg, child) next_subtree = SubtreeDFGBased(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities) if loop_cut[3]: next_subtree.must_insert_skip = True self.children.append(next_subtree) else: self.detected_cut = "sequential" self.need_loop_on_subtree = True for index_enum, child in enumerate(loop_cut[1]): dfg_child = filter_dfg_on_act(self.dfg, child) next_subtree = SubtreeDFGBased(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities) self.children.append(next_subtree) next_subtree.must_insert_skip = True else: if self.noise_threshold > 0: if not second_iteration: self.initialize_tree(self.dfg, self.initial_dfg, None, second_iteration=True) else: self.detected_cut = "flower" else: self.detected_cut = "flower" else: self.detected_cut = "base_xor"
def detect_cut(self, second_iteration=False): """ Detect generally a cut in the graph (applying all the algorithms) """ if self.dfg: # print("\n\n") conn_components = self.get_connected_components(self.ingoing, self.outgoing, self.activities) this_nx_graph = self.transform_dfg_to_directed_nx_graph() strongly_connected_components = [list(x) for x in nx.strongly_connected_components(this_nx_graph)] # print("strongly_connected_components", strongly_connected_components) xor_cut = self.detect_xor_cut(conn_components, this_nx_graph, strongly_connected_components) if xor_cut[0]: # print(self.rec_depth, "xor_cut", self.activities) for comp in xor_cut[1]: new_dfg = filter_dfg_on_act(self.dfg, comp) self.detected_cut = "xor" self.children.append( SubtreeDFGBased(new_dfg, self.master_dfg, self.initial_dfg, comp, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities)) else: seq_cut = self.detect_sequential_cut(conn_components, this_nx_graph, strongly_connected_components) if seq_cut[0]: # print(self.rec_depth, "seq_cut", self.activities) self.detected_cut = "sequential" for child in seq_cut[1]: dfg_child = filter_dfg_on_act(self.dfg, child) self.children.append( SubtreeDFGBased(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities)) self.put_skips_in_seq_cut() else: par_cut = self.detect_parallel_cut(conn_components, this_nx_graph, strongly_connected_components) if par_cut[0]: self.detected_cut = "parallel" for comp in par_cut[1]: new_dfg = filter_dfg_on_act(self.dfg, comp) self.children.append( SubtreeDFGBased(new_dfg, self.master_dfg, new_dfg, comp, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities)) else: loop_cut = self.detect_loop_cut(conn_components, this_nx_graph, strongly_connected_components) if loop_cut[0]: if loop_cut[2]: self.detected_cut = "loopCut" for index_enum, child in enumerate(loop_cut[1]): dfg_child = filter_dfg_on_act(self.dfg, child) next_subtree = SubtreeDFGBased(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities) if loop_cut[3]: next_subtree.must_insert_skip = True self.children.append(next_subtree) else: self.detected_cut = "sequential" self.need_loop_on_subtree = True for index_enum, child in enumerate(loop_cut[1]): dfg_child = filter_dfg_on_act(self.dfg, child) next_subtree = SubtreeDFGBased(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self.initial_start_activities, initial_end_activities=self.initial_end_activities) self.children.append(next_subtree) next_subtree.must_insert_skip = True else: if self.noise_threshold > 0: if not second_iteration: self.initialize_tree(self.dfg, self.initial_dfg, None, second_iteration=True) else: pass self.detected_cut = "flower" else: self.detected_cut = "base_xor"
def detect_cut(self, second_iteration=False): """ Detect generally a cut in the graph (applying all the algorithms) """ print('find cut') if self.dfg: # print("\n\n") conn_components = self.get_connected_components( self.ingoing, self.outgoing, self.activities) this_nx_graph = self.transform_dfg_to_directed_nx_graph() strongly_connected_components = [ list(x) for x in nx.strongly_connected_components(this_nx_graph) ] # print("strongly_connected_components", strongly_connected_components) xor_cut = self.detect_xor_cut(conn_components, this_nx_graph, strongly_connected_components) if xor_cut[0]: print('xor') # print(self.rec_depth, "xor_cut", self.activities) for i, comp in enumerate(xor_cut[1]): new_dfg = filter_dfg_on_act(self.dfg, comp) self.detected_cut = "xor" ChildDFG(new_dfg, self.master_dfg, self.initial_dfg, comp, self.counts, self.rec_depth + 1, self.noise_threshold, self.initial_start_activities, self.initial_end_activities, self.detected_cut, i, False, self.conf) self.child_names.append(i) # self.children.append( # SubtreeDFGBasedOne(new_dfg, self.master_dfg, self.initial_dfg, comp, self.counts, # self.rec_depth + 1, # noise_threshold=self.noise_threshold, # initial_start_activities=self.initial_start_activities, # initial_end_activities=self.initial_end_activities)) else: print('seq') seq_cut = self.detect_sequential_cut( conn_components, this_nx_graph, strongly_connected_components) if seq_cut[0]: # print(self.rec_depth, "seq_cut", self.activities) self.detected_cut = "sequential" print(self.conf) for i, child in enumerate(seq_cut[1]): dfg_child = filter_dfg_on_act(self.dfg, child) ChildDFG(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, self.noise_threshold, self.initial_start_activities, self.initial_end_activities, self.detected_cut, i, True, self.conf) self.child_names.append(i) # self.children.append( # SubtreeDFGBasedOne(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, # self.rec_depth + 1, # noise_threshold=self.noise_threshold, # initial_start_activities=self.initial_start_activities, # initial_end_activities=self.initial_end_activities)) #self.put_skips_in_seq_cut() else: print('par') par_cut = self.detect_parallel_cut( conn_components, this_nx_graph, strongly_connected_components) if par_cut[0]: self.detected_cut = "parallel" for i, comp in enumerate(par_cut[1]): new_dfg = filter_dfg_on_act(self.dfg, comp) ChildDFG(new_dfg, self.master_dfg, self.initial_dfg, comp, self.counts, self.rec_depth + 1, self.noise_threshold, self.initial_start_activities, self.initial_end_activities, self.detected_cut, i, False, self.conf) self.child_names.append(i) # self.children.append( # SubtreeDFGBasedOne(new_dfg, self.master_dfg, new_dfg, comp, self.counts, # self.rec_depth + 1, # noise_threshold=self.noise_threshold, # initial_start_activities=self.initial_start_activities, # initial_end_activities=self.initial_end_activities)) else: print('loop') loop_cut = self.detect_loop_cut( conn_components, this_nx_graph, strongly_connected_components) if loop_cut[0]: if loop_cut[2]: self.detected_cut = "loopCut" for index_enum, child in enumerate( loop_cut[1]): dfg_child = filter_dfg_on_act( self.dfg, child) ChildDFG(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, self.noise_threshold, self.initial_start_activities, self.initial_end_activities, self.detected_cut, index_enum, loop_cut[3], self.conf) self.child_names.append(index_enum) # next_subtree = SubtreeDFGBasedOne(dfg_child, self.master_dfg, self.initial_dfg, # child, # self.counts, self.rec_depth + 1, # noise_threshold=self.noise_threshold, # initial_start_activities=self.initial_start_activities, # initial_end_activities=self.initial_end_activities) # if loop_cut[3]: # next_subtree.must_insert_skip = True # self.children.append(next_subtree) else: print('sequential') self.detected_cut = "sequential" self.need_loop_on_subtree = True for index_enum, child in enumerate( loop_cut[1]): dfg_child = filter_dfg_on_act( self.dfg, child) ChildDFG(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, self.noise_threshold, self.initial_start_activities, self.initial_end_activities, self.detected_cut, index_enum, True, self.conf) self.child_names.append(index_enum) # next_subtree = SubtreeDFGBasedOne(dfg_child, self.master_dfg, self.initial_dfg, # child, # self.counts, self.rec_depth + 1, # noise_threshold=self.noise_threshold, # initial_start_activities=self.initial_start_activities, # initial_end_activities=self.initial_end_activities) # self.children.append(next_subtree) # next_subtree.must_insert_skip = True else: print('nothing') if self.noise_threshold > 0: if not second_iteration: self.initialize_tree(self.dfg, self.initial_dfg, None, second_iteration=True) else: pass print('flower') self.detected_cut = "flower" else: print('base_xor') self.detected_cut = "base_xor"
def detect_cut(initial_dfg, dfg, parent, conf, process, initial_start_activities, initial_end_activities, activities): """ Detect generally a cut in the graph (applying all the algorithms) """ if dfg: # print('DFG' + str(dfg) + ' will be cut on ' + str(conf)) # print(dfg) # Find in order: xor, seq, par, loop, seq, flower ingoing = get_ingoing_edges(dfg) outgoing = get_outgoing_edges(dfg) start_activities = infer_start_activities(dfg) end_activities = infer_end_activities(dfg) if parent == "m": initial_start_activities = start_activities initial_end_activities = end_activities activities = get_activities_from_dfg(dfg) else: activities = set(activities) conn_components = detection_utils.get_connected_components(ingoing, outgoing, activities) # print("Init Start: " + str(initial_start_activities) + ", Init End: " + str(initial_end_activities)) # print(activities) xor_cut = detect_xor_cut(dfg, conn_components) if xor_cut[0]: found_cut = "xor" print(found_cut) for index, comp in enumerate(xor_cut[1]): # print(comp) filtered_dfg = filter_dfg_on_act(dfg, comp) save_cut(filtered_dfg, comp, parent, found_cut, index, conf, process, initial_start_activities, initial_end_activities) else: this_nx_graph = detection_utils.transform_dfg_to_directed_nx_graph(activities, dfg) strongly_connected_components = [list(x) for x in nx.strongly_connected_components(this_nx_graph)] # print(strongly_connected_components) seq_cut = detect_sequential_cut(dfg, strongly_connected_components) if seq_cut[0]: found_cut = "seq" print("seq") for index, comp in enumerate(seq_cut[1]): # print(comp) filter_dfg = filter_dfg_on_act(dfg, comp) print(filter_dfg) save_cut(filter_dfg, comp, parent, found_cut, index, conf, process, initial_start_activities, initial_end_activities) # self.put_skips_in_seq_cut()? else: negated_dfg = detection_utils.negate(dfg) negated_ingoing = get_ingoing_edges(negated_dfg) negated_outgoing = get_outgoing_edges(negated_dfg) par_cut = detect_parallel_cut(this_nx_graph, strongly_connected_components, negated_ingoing, negated_outgoing, activities, dfg, initial_start_activities, initial_end_activities, initial_dfg) if par_cut[0]: found_cut = "par" print("par") i = 0 for comp in par_cut[1]: i += 1 # print(comp) filtter_dfg = filter_dfg_on_act(dfg, comp) save_cut(filtter_dfg, comp, parent, found_cut, i, conf, process, initial_start_activities, initial_end_activities) else: start_activities = infer_start_activities(dfg) end_activities = infer_end_activities(dfg) loop_cut = detect_loop_cut(dfg, activities, start_activities, end_activities) if loop_cut[0]: if loop_cut[2]: found_cut = "loop" print("loop") for index, comp in enumerate(loop_cut[1]): # print(comp) filter_dfg = filter_dfg_on_act(dfg, comp) save_cut(filter_dfg, comp, parent, found_cut, index, conf, process, initial_start_activities, initial_end_activities) # if loop_cut[3]: # insert_skip else: found_cut = "seq2" print('seq 2') # self.need_loop_on_subtree = True for index, comp in enumerate(loop_cut[1]): # print(comp) filter_dfg = filter_dfg_on_act(dfg, comp) save_cut(filter_dfg, comp, parent, found_cut, index, conf, process, initial_start_activities, initial_end_activities) #insert_skip else: pass found_cut = "flower" print("flower") #save_cut(dfg, comp, parent, found_cut, 0, conf, process) return found_cut else: print("no DFG or base_xor") return "base_xor"
def detect_cut(self, second_iteration=False): """ Detect generally a cut in the graph (applying all the algorithms) """ if self.dfg: # print("\n\n") conn_components = get_connected_components(self.ingoing, self.outgoing, self.activities) this_nx_graph = None strongly_connected_components = None conc_cut = self.detect_concurrent_cut( conn_components, this_nx_graph, strongly_connected_components) seq_cut = self.detect_sequential_cut( conn_components, this_nx_graph, strongly_connected_components) par_cut = self.detect_parallel_cut(conn_components, this_nx_graph, strongly_connected_components) loop_cut = self.detect_loop_cut(conn_components, this_nx_graph, strongly_connected_components) if conc_cut[0]: for comp in conc_cut[1]: new_dfg = filter_dfg_on_act(self.dfg, comp) self.detected_cut = "concurrent" self.children.append( Subtree(new_dfg, self.master_dfg, self.initial_dfg, comp, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self. initial_start_activities, initial_end_activities=self. initial_end_activities)) else: if seq_cut[0]: self.detected_cut = "sequential" for child in seq_cut[1]: dfg_child = filter_dfg_on_act(self.dfg, child) self.children.append( Subtree(dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self. initial_start_activities, initial_end_activities=self. initial_end_activities)) else: if par_cut[0]: union_acti_comp = set() for comp in par_cut[1]: union_acti_comp = union_acti_comp.union(comp) diff_acti_comp = set( self.activities).difference(union_acti_comp) for act in diff_acti_comp: par_cut[1] = add_to_most_probable_component( par_cut[1], act, self.ingoing, self.outgoing) for comp in par_cut[1]: new_dfg = filter_dfg_on_act(self.dfg, comp) self.detected_cut = "parallel" self.children.append( Subtree(new_dfg, self.master_dfg, new_dfg, comp, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self. initial_start_activities, initial_end_activities=self. initial_end_activities)) else: if loop_cut[0]: self.detected_cut = "loopCut" for child in loop_cut[1]: dfg_child = filter_dfg_on_act(self.dfg, child) self.children.append( Subtree( dfg_child, self.master_dfg, self.initial_dfg, child, self.counts, self.rec_depth + 1, noise_threshold=self.noise_threshold, initial_start_activities=self. initial_start_activities, initial_end_activities=self. initial_end_activities)) else: if self.noise_threshold > 0: if not second_iteration: self.initialize_tree(self.dfg, self.initial_dfg, None, second_iteration=True) else: pass self.detected_cut = "flower" else: self.detected_cut = "base_concurrent"