def test_range2(self): tree = pt_utils.parse("*( a, b, τ)") pt_number.apply(tree, 'D', 1) alignments = [{ 'alignment': [('>>', None), ('>>', '2_s'), ('a', 'a'), ('>>', '2_e'), ('>>', '3_s'), ('b', 'b'), ('>>', '3_e'), ('>>', '2_s'), ('a', 'a'), ('>>', '2_e'), ('>>', '3_s'), ('b', 'b'), ('>>', '3_e'), ('>>', '2_s'), ('a', 'a'), ('>>', '2_e'), ('>>', None)], 'cost': 0, 'visited_states': 20, 'queued_states': 42, 'traversed_arcs': 42, 'fitness': 1 }] ranges = to_lock_align.compute_lock_range(tree, alignments, []) expect_ranges = [{ 1: [[0, 16]], 2: [[1, 3], [7, 9], [13, 15]], 3: [[4, 6], [10, 12]] }] self.assertEqual(str(expect_ranges), str(ranges))
def test_align_repair4(self): tree1 = pt_utils.parse("->( a, +(b, c)) ") tree2 = pt_utils.parse("->( a, X(b, c))") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) log = utils.create_event_log("abdc") alignments = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '3_tau_1'), ('>>', None)), (('>>', '4_s'), ('>>', '4_s')), (('>>', '5_s'), ('>>', '5_s')), (('t_b_1', 'b'), ('b', 'b')), (('t_d_2', '>>'), ('d', '>>')), (('t_c_3', 'c'), ('c', 'c')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '5_e'), ('>>', '5_e')), (('>>', '3_tau_2'), ('>>', None)), (('>>', '3_e'), ('>>', '3_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 5, 'visited_states': 18, 'queued_states': 37, 'traversed_arcs': 38, 'fitness': 0.8076923076923077}] a_repair = ar_lock.apply(tree1, tree2, log, alignments, self.parameters) exp_a_repair = [{'alignment': [], 'cost': 10, 'visited_states': 18, 'queued_states': 37, 'traversed_arcs': 38, 'fitness': 1 - 10 / (20 + 4)}] # l_alignments = [{'alignment': [('>>', '1_s'), ('>>', '2_s'), ('a', 'a'), ('>>', '2_e'), ('>>', None), # ('>>', '3_s'), ('>>', '4_s'), ('b', 'b'), ('>>', '4_e'), ('d', '>>'), # ('>>', '5_s'), ('c', 'c'), ('>>', '5_e'), ('>>', '3_e'), ('>>', None), # ('>>', '1_e')], 'cost': 5, 'visited_states': 7, 'queued_states': 14, # 'traversed_arcs': 14, 'fitness': 0.8076923076923077}] # l_a_repair = repair_alignment.apply(tree1, tree2, log, l_alignments, self.parameters_tuple_false) # exp_l_a_repair = [{'alignment': [('>>', '1_s'), ('>>', '2_s'), ('a', 'a'), ('>>', '2_e'), ('>>', None), # ('>>', '6_s'), ('>>', '8_s'), ('b', '>>'), ('d', '>>'), ('c', 'c'), # ('>>', '8_e'), ('>>', '6_e'), ('>>', None), ('>>', '1_e')], 'cost': 10, # 'visited_states': 6, 'queued_states': 6, 'traversed_arcs': 5, # 'fitness': 0.5833333333333333}] for i in range(len(alignments)): self.assertEqual(a_repair[i]["cost"], exp_a_repair[i]["cost"]) self.assertEqual(a_repair[i]["fitness"], exp_a_repair[i]["fitness"])
def test_scope_expand2(self): tree1 = pt_utils.parse("+( a, ->(b, c))") tree2 = pt_utils.parse("+( a, X(b, c))") # log = create_event_log("bac") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '1_tau_1'), ('>>', None)), (('>>', '3_s'), ('>>', '3_s')), (('>>', '2_s'), ('>>', '2_s')), (('>>', '4_s'), ('>>', '4_s')), (('t_b_0', 'b'), ('b', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '5_s'), ('>>', '5_s')), (('t_a_1', 'a'), ('a', 'a')), (('t_c_2', 'c'), ('c', 'c')), (('>>', '5_e'), ('>>', '5_e')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '1_tau_2'), ('>>', None)), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 0, 'visited_states': 24, 'queued_states': 57, 'traversed_arcs': 64, 'fitness': 1}] s_align = se_rd_lock.apply_with_lock(align, tree1, tree2) g_s_align = se_rd_lock_general.apply(align, tree1, tree2, self.parameters) e_s_align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '1_tau_1'), ('>>', None)), (('>>', '2_s'), ('>>', '2_s')), (('>>', '4_s'), ('>>', '4_s')), (('t_b_0', 'b'), ('b', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '5_s'), ('>>', '5_s')), (('t_a_1', 'a'), ('a', 'a')), (('t_c_2', 'c'), ('c', 'c')), (('>>', '5_e'), ('>>', '5_e')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '1_tau_2'), ('>>', None)), (('>>', '3_e'), ('>>', '3_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 0, 'visited_states': 24, 'queued_states': 57, 'traversed_arcs': 64, 'fitness': 1}] self.assertEqual(str(s_align), str(e_s_align)) self.assertEqual(str(g_s_align), str(e_s_align))
def test_range4(self): tree = pt_utils.parse("+( ->( + (a, b), X(c, d)), e") pt_number.apply(tree, 'D', 1) alignments = [{ 'alignment': [('>>', None), ('>>', None), ('>>', 'b'), ('a', 'a'), ('f', '>>'), ('e', 'e'), ('>>', None), ('d', 'd'), ('>>', None), ('g', '>>')], 'cost': 12, 'visited_states': 12, 'queued_states': 27, 'traversed_arcs': 28, 'fitness': 0.6363636363636364 }] ranges = to_lock_align.compute_lock_range(tree, alignments, []) expect_ranges = [{ 1: [[0, 9]], 2: [[2, 7]], 3: [[2, 3]], 4: [[3, 3]], 5: [[2, 2]], 6: [[7, 7]], 8: [[7, 7]], 9: [[5, 5]] }] self.assertEqual(str(expect_ranges), str(ranges))
def test_align_repair2(self): tree1 = pt_utils.parse("X( a, ->(b, c)) ") tree2 = pt_utils.parse("X( τ, ->(b, c))") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) log = utils.create_event_log("") alignments = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('>>', 'a'), ('>>', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 2, 'visited_states': 6, 'queued_states': 6, 'traversed_arcs': 6, 'fitness': 0.0}] a_repair = ar_lock.apply(tree1, tree2, log, alignments, self.parameters) exp_a_repair = [{'alignment': [(('>>', '6_s'), ('>>', '6_s')), (('>>', '7_s'), ('>>', '7_s')), (('t_a_0', 'a'), ('>>', None)), (('>>', '7_e'), ('>>', '7_e')), (('>>', '6_e'), ('>>', '6_e'))], 'cost': 0, 'visited_states': 9, 'queued_states': 13, 'traversed_arcs': 13, 'fitness': 1}] # l_alignments = [ # {'alignment': [('>>', '1_s'), ('>>', '2_s'), ('>>', 'a'), ('>>', '2_e'), ('>>', '1_e')], 'cost': 2, # 'visited_states': 2, 'queued_states': 2, 'traversed_arcs': 2, 'fitness': 0.0}] # # l_a_repair = repair_alignment.apply(tree1, tree2, log, l_alignments, self.parameters_tuple_false) # exp_l_a_repair = [ # {'alignment': [('>>', '6_s'), ('>>', '7_s'), ('>>', None), ('>>', '7_e'), ('>>', '6_e')], 'cost': 0, # 'visited_states': 2, 'queued_states': 2, 'traversed_arcs': 2, 'fitness': 1}] for i in range(len(alignments)): self.assertEqual(list(map(lambda x: x[1], a_repair[i]["alignment"])), list(map(lambda x: x[1], exp_a_repair[i]["alignment"]))) self.assertEqual(a_repair[i]["cost"], exp_a_repair[i]["cost"]) self.assertEqual(a_repair[i]["fitness"], exp_a_repair[i]["fitness"])
def test_scope_expand3(self): tree1 = pt_utils.parse("X( a, ->(b, c))") tree2 = pt_utils.parse("X( a, +(b, c))") # log = create_event_log("ebf") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) align = [{'alignment': [(('t_e_0', '>>'), ('e', '>>')), (('>>', '1_s'), ('>>', '1_s')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '4_s'), ('>>', '4_s')), (('t_b_1', 'b'), ('b', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '5_s'), ('>>', '5_s')), (('>>', 'c'), ('>>', 'c')), (('>>', '5_e'), ('>>', '5_e')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '1_e'), ('>>', '1_e')), (('t_f_2', '>>'), ('f', '>>'))], 'cost': 12, 'visited_states': 22, 'queued_states': 27, 'traversed_arcs': 27, 'fitness': 0.2941176470588235}] s_align = se_rd_lock.apply_with_lock(align, tree1, tree2) g_s_align = se_rd_lock_general.apply(align, tree1, tree2, self.parameters) e_s_align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '3_s'), ('>>', '3_s')), (('t_e_0', '>>'), ('e', '>>')), (('>>', '4_s'), ('>>', '4_s')), (('t_b_1', 'b'), ('b', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '5_s'), ('>>', '5_s')), (('>>', 'c'), ('>>', 'c')), (('>>', '5_e'), ('>>', '5_e')), (('t_f_2', '>>'), ('f', '>>')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 12, 'visited_states': 22, 'queued_states': 27, 'traversed_arcs': 27, 'fitness': 0.2941176470588235}] self.assertEqual(str(s_align), str(e_s_align)) self.assertEqual(str(g_s_align), str(e_s_align))
def apply(tree1, tree2, log, alignments, parameters=None): """ Alignment repair on tree2 based on the alignment of log on tree1 Parameters ----------- tree1 Process Tree tree2 Process Tree log EventLog alignments related alignment of log on tree1 parameters Returns ------------ alignments repaired alignments """ parameters = {} if parameters is None else parameters parameters['COMPARE_OPTION'] = 1 if parameters.get( 'COMPARE_OPTION') is None else parameters['COMPARE_OPTION'] ret_tuple_as_trans_desc = False if parameters.get(PARAM_ALIGNMENT_RESULT_IS_SYNC_PROD_AWARE) is None else \ parameters[PARAM_ALIGNMENT_RESULT_IS_SYNC_PROD_AWARE] # TODO: if the given alignment is not True, try-catch alignments = copy.deepcopy(alignments) com_res = pt_compare.apply(tree1, tree2, parameters['COMPARE_OPTION']) if com_res.value: return alignments else: tree1_total_number = pt_mani_utils.nodes_number(tree1) pt_number.apply(com_res.subtree2, 'D', tree1_total_number + 1) best_worst_cost = apply_pt_alignments(EventLog([Trace()]), tree2, parameters)[0]['cost'] for i in range(len(alignments)): align = alignments[i] if align.get("repair") is None: scope = detect_change_scope(align['alignment'], com_res.subtree1, log[i], ret_tuple_as_trans_desc) if not len(scope.traces) == 0: sub_aligns_before = apply_pt_alignments( EventLog(scope.traces), com_res.subtree1, parameters) sub_aligns_after = apply_pt_alignments( EventLog(scope.traces), com_res.subtree2, parameters) alignment_reassemble(align['alignment'], sub_aligns_after, scope.anchor_index, com_res.subtree1, ret_tuple_as_trans_desc) recompute_cost(align, sub_aligns_before, sub_aligns_after) recompute_fitness(align, log[i], best_worst_cost) align["repair"] = True for a in alignments: a.pop("repair") if a.get("repair") is not None else None return alignments
def compute_repair_result(mpt_index, align_mpt, expand_repair_file, result_file): """ Record repair alignment Records Format (repair) --------------- Alignments, time , cost Records Format (result) --------------- Alignment time without lock, time with lock, optimal cost, best_worst_cost, repair_alignments, time, cost, expand_repair_alignments, time, cost """ trees = object_read.read_trees_from_file(PT_FILE_NAME, 0) m_trees = object_read.read_trees_from_file(PT_FILE_NAME, mpt_index) logs = object_read.read_logs_from_file(LOG_FILE_NAME) alignments_t1 = object_read.read_align_from_file(ALIGN_FILE_NAME) alignments_t2 = object_read.read_align_from_file(align_mpt) base = excel_utils.create_workbook() expand_repair_repair = excel_utils.create_workbook() result_e_table, expand_e_table = None, None parameters = {'ret_tuple_as_trans_desc': True} for row, m_tree in enumerate(m_trees): if row % (PT_NUM[0] * MPT_NUM) == 0: result_e_table = ExcelTable( base.add_sheet(REPAIR_SHEET_NAME[row // (PT_NUM[0] * MPT_NUM)])) expand_e_table = ExcelTable( expand_repair_repair.add_sheet( ALIGN_SHEET_NAME[row // (PT_NUM[0] * MPT_NUM)])) pt_number.apply(trees[row // MPT_NUM], 'D', 1) pt_number.apply(m_tree, 'D', 1) repair_info = repair_align_info(trees[row // MPT_NUM], m_tree, logs[row // MPT_NUM], alignments_t1[row // MPT_NUM].aligns, alignments_t2[row].best_worst_cost, alignments_t2[row].cost_opt, parameters) expand_repair_info = expand_repair_align_info( trees[row // MPT_NUM], m_tree, logs[row // MPT_NUM], alignments_t1[row // MPT_NUM].aligns, alignments_t2[row].best_worst_cost, alignments_t2[row].cost_opt, parameters) excel_utils.write_column_to_table(expand_e_table.table, expand_e_table.column, expand_repair_info[0]) excel_utils.write_row_to_table( result_e_table.table, result_e_table.row, alignments_t2[row].get_opt_info() + repair_info[1] + expand_repair_info[1]) excel_utils.save(base, result_file) excel_utils.save(expand_repair_repair, expand_repair_file)
def test_scope_expand4(self): tree1 = pt_utils.parse("*( a, X(b, c), τ)") tree2 = pt_utils.parse("*( a, ->(b, c), τ)") # log = create_event_log("abeaf") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '4_s'), ('>>', '4_s')), (('t_b_1', 'b'), ('b', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '2_s'), ('>>', '2_s')), (('t_e_2', '>>'), ('e', '>>')), (('t_a_3', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '6_s'), ('>>', '6_s')), (('>>', '6_skip_1'), ('>>', None)), (('>>', '6_e'), ('>>', '6_e')), (('>>', '1_e'), ('>>', '1_e')), (('t_f_4', '>>'), ('f', '>>'))], 'cost': 10, 'visited_states': 31, 'queued_states': 50, 'traversed_arcs': 50, 'fitness': 0.6296296296296297}] s_align = se_rd_lock.apply_with_lock(align, tree1, tree2) g_s_align = se_rd_lock_general.apply(align, tree1, tree2, self.parameters) e_s_align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '4_s'), ('>>', '4_s')), (('t_b_1', 'b'), ('b', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('t_e_2', '>>'), ('e', '>>')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_3', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '6_s'), ('>>', '6_s')), (('>>', '6_skip_1'), ('>>', None)), (('>>', '6_e'), ('>>', '6_e')), (('>>', '1_e'), ('>>', '1_e')), (('t_f_4', '>>'), ('f', '>>'))], 'cost': 10, 'visited_states': 31, 'queued_states': 50, 'traversed_arcs': 50, 'fitness': 0.6296296296296297}] e_g_s_align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '4_s'), ('>>', '4_s')), (('t_b_1', 'b'), ('b', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('t_e_2', '>>'), ('e', '>>')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_3', 'a'), ('a', 'a')), (('t_f_4', '>>'), ('f', '>>')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '6_s'), ('>>', '6_s')), (('>>', '6_skip_1'), ('>>', None)), (('>>', '6_e'), ('>>', '6_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 10, 'visited_states': 31, 'queued_states': 50, 'traversed_arcs': 50, 'fitness': 0.6296296296296297}] self.assertEqual(str(s_align), str(e_s_align)) self.assertEqual(str(g_s_align), str(e_g_s_align))
def test_align_repair1(self): tree1 = pt_utils.parse("+( a, X( g, h ) ) ") tree2 = pt_utils.parse("+( a, ->( g, h ) )") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) log = utils.create_event_log("gah") alignments = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '1_tau_1'), ('>>', None)), (('>>', '3_s'), ('>>', '3_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_g_0', '>>'), ('g', '>>')), (('t_a_1', 'a'), ('a', 'a')), (('>>', '5_s'), ('>>', '5_s')), (('t_h_2', 'h'), ('h', 'h')), (('>>', '5_e'), ('>>', '5_e')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '1_tau_2'), ('>>', None)), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 5, 'visited_states': 18, 'queued_states': 35, 'traversed_arcs': 35, 'fitness': 0.736842105263158}] a_repair = ar_lock.apply(tree1, tree2, log, alignments, self.parameters) exp_a_repair = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '1_tau_1'), ('>>', None)), (('>>', '6_s'), ('>>', '6_s')), (('>>', '7_s'), ('>>', '7_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_g_0', 'g'), ('g', 'g')), (('>>', '7_e'), ('>>', '7_e')), (('>>', '8_s'), ('>>', '8_s')), (('t_a_1', 'a'), ('a', 'a')), (('t_h_1', 'h'), ('h', 'h')), (('>>', '8_e'), ('>>', '8_e')), (('>>', '6_e'), ('>>', '6_e')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '1_tau_2'), ('>>', None)), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 0, 'fitness': 1.0}] # l_alignments = [{'alignment': [('>>', '1_s'), ('>>', None), ('>>', '3_s'), ('g', '>>'), ('>>', '2_s'), # ('a', 'a'), ('>>', '2_e'), ('>>', '5_s'), ('h', 'h'), ('>>', '5_e'), # ('>>', '3_e'), ('>>', None), ('>>', '1_e')], 'cost': 5, 'visited_states': 7, # 'queued_states': 13, 'traversed_arcs': 15, 'fitness': 0.736842105263158}] # l_a_repair = repair_alignment.apply(tree1, tree2, log, l_alignments, self.parameters_tuple_false) # exp_l_a_repair = [{'alignment': [('>>', '1_s'), ('>>', None), ('>>', '6_s'), ('>>', '7_s'), ('g', 'g'), # ('>>', '7_e'), ('>>', '8_s'), ('a', 'a'), ('h', 'h'), ('>>', '8_e'), # ('>>', '6_e'), ('>>', None), ('>>', '1_e')], 'cost': 0, 'visited_states': 6, # 'queued_states': 13, 'traversed_arcs': 15, 'fitness': 1}] for i in range(len(alignments)): self.assertEqual(list(map(lambda x: x[1], a_repair[i]["alignment"])), list(map(lambda x: x[1], exp_a_repair[i]["alignment"]))) self.assertEqual(a_repair[i]["cost"], exp_a_repair[i]["cost"]) self.assertEqual(a_repair[i]["fitness"], exp_a_repair[i]["fitness"])
def test_range1(self): tree = pt_utils.parse("->( a, b, c)") pt_number.apply(tree, 'D', 1) alignments = [{ 'alignment': [('a', 'a'), ('b', 'b'), ('d', '>>'), ('c', 'c'), ('e', '>>')], 'cost': 10, 'visited_states': 6, 'queued_states': 11, 'traversed_arcs': 11, 'fitness': 0.6774193548387097 }] ranges = to_lock_align.compute_lock_range(tree, alignments, []) expect_ranges = [{1: [[0, 4]], 2: [[0, 0]], 3: [[1, 1]], 4: [[3, 3]]}] self.assertEqual(str(expect_ranges), str(ranges))
def test_range5(self): tree = pt_utils.parse("+( a, X(b, τ))") pt_number.apply(tree, 'D', 1) alignments = [{ 'alignment': [('>>', None), ('>>', '5_s'), ('a', 'a'), ('>>', None), ('>>', '5_e'), ('>>', None)], 'cost': 0, 'visited_states': 8, 'queued_states': 15, 'traversed_arcs': 16, 'fitness': 1 }] ranges = to_lock_align.compute_lock_range(tree, alignments, []) expect_ranges = [{1: [[0, 5]], 2: [[2, 2]], 3: [[1, 4]], 5: [[1, 4]]}] self.assertEqual(str(expect_ranges), str(ranges))
def apply_with_alignments(tree, m_tree, log, alignments, parameters=None, option=1): pt_number.apply(tree, 'D') pt_number.apply(m_tree, 'D') com_res = pt_compare.apply(tree, m_tree, option) if com_res.value: return alignments, copy.deepcopy(alignments) else: mapping_t, tree_info = dict(), dict() tree_utils.recursively_init_tree_tables(tree, tree_info, mapping_t, [1]) best_worst_cost = alignments_on_pt(EventLog([Trace()]), m_tree, parameters)[0]['cost'] repairing_alignment = compute_repairing_alignments( com_res, log, alignments, tree_info, mapping_t, parameters, best_worst_cost) return alignments, repairing_alignment
def test_scope_expand1(self): tree1 = pt_utils.parse("->( a, *( X(c, b), d, τ), e)") tree2 = pt_utils.parse("->( a, *(->(c, b), d, τ), e)") # log = create_event_log("abdce") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '4_s'), ('>>', '4_s')), (('>>', '6_s'), ('>>', '6_s')), (('t_b_1', 'b'), ('b', 'b')), (('>>', '6_e'), ('>>', '6_e')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '7_s'), ('>>', '7_s')), (('t_d_2', 'd'), ('d', 'd')), (('>>', '7_e'), ('>>', '7_e')), (('>>', '4_s'), ('>>', '4_s')), (('>>', '5_s'), ('>>', '5_s')), (('t_c_3', 'c'), ('c', 'c')), (('>>', '5_e'), ('>>', '5_e')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '8_s'), ('>>', '8_s')), (('>>', '8_skip_1'), ('>>', None)), (('>>', '8_e'), ('>>', '8_e')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '9_s'), ('>>', '9_s')), (('t_e_4', 'e'), ('e', 'e')), (('>>', '9_e'), ('>>', '9_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 0, 'visited_states': 33, 'queued_states': 71, 'traversed_arcs': 71, 'fitness': 1}] s_align = se_rd_lock.apply_with_lock(align, tree1, tree2) g_s_align = se_rd_lock_general.apply(align, tree1, tree2, self.parameters) e_s_align = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '4_s'), ('>>', '4_s')), (('>>', '6_s'), ('>>', '6_s')), (('t_b_1', 'b'), ('b', 'b')), (('>>', '6_e'), ('>>', '6_e')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '7_s'), ('>>', '7_s')), (('t_d_2', 'd'), ('d', 'd')), (('>>', '7_e'), ('>>', '7_e')), (('>>', '4_s'), ('>>', '4_s')), (('>>', '5_s'), ('>>', '5_s')), (('t_c_3', 'c'), ('c', 'c')), (('>>', '5_e'), ('>>', '5_e')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '8_s'), ('>>', '8_s')), (('>>', '8_skip_1'), ('>>', None)), (('>>', '8_e'), ('>>', '8_e')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '9_s'), ('>>', '9_s')), (('t_e_4', 'e'), ('e', 'e')), (('>>', '9_e'), ('>>', '9_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 0, 'visited_states': 33, 'queued_states': 71, 'traversed_arcs': 71, 'fitness': 1}] self.assertEqual(str(s_align), str(e_s_align)) self.assertEqual(str(g_s_align), str(e_s_align))
def test_range3(self): tree = pt_utils.parse("*( +( *(->( a, b), c, τ), d), X(e, f), τ)") pt_number.apply(tree, 'D', 1) alignments = [{ 'alignment': [('>>', None), ('>>', '2_s'), ('>>', None), ('>>', '4_s'), ('a', 'a'), ('d', 'd'), ('b', 'b'), ('>>', '4_e'), ('>>', '7_s'), ('c', 'c'), ('>>', '7_e'), ('>>', '4_s'), ('a', 'a'), ('b', 'b'), ('>>', '4_e'), ('>>', None), ('>>', None), ('>>', '2_e'), ('>>', '10_s'), ('e', 'e'), ('>>', '10_e'), ('>>', '2_s'), ('>>', None), ('>>', '4_s'), ('a', 'a'), ('b', 'b'), ('>>', '4_e'), ('>>', None), ('d', 'd'), ('>>', None), ('>>', '2_e'), ('>>', None)], 'cost': 0, 'visited_states': 39, 'queued_states': 97, 'traversed_arcs': 99, 'fitness': 1 }] ranges = to_lock_align.compute_lock_range(tree, alignments, []) expect_ranges = [{ 1: [[0, 31]], 2: [[1, 17], [21, 30]], 3: [[3, 14], [23, 26]], 4: [[3, 7], [11, 14], [23, 26]], 5: [[4, 4], [12, 12], [24, 24]], 6: [[6, 6], [13, 13], [25, 25]], 7: [[8, 10]], 9: [[5, 5], [28, 28]], 10: [[18, 20]], 11: [[19, 19]] }] self.assertEqual(str(ranges), str(expect_ranges))
def test_align_repair3(self): tree1 = pt_utils.parse("->( a, X(b, c)) ") tree2 = pt_utils.parse("->( a, X(b, τ))") pt_number.apply(tree1, 'D', 1) pt_number.apply(tree2, 'D', 1) log = utils.create_event_log("a") alignments = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '3_s'), ('>>', '3_s')), (('>>', '4_s'), ('>>', '4_s')), (('>>', 'b'), ('>>', 'b')), (('>>', '4_e'), ('>>', '4_e')), (('>>', '3_e'), ('>>', '3_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 2, 'visited_states': 11, 'queued_states': 15, 'traversed_arcs': 15, 'fitness': 0.7777777777777778}] a_repair = ar_lock.apply(tree1, tree2, log, alignments, self.parameters) exp_a_repair = [{'alignment': [(('>>', '1_s'), ('>>', '1_s')), (('>>', '2_s'), ('>>', '2_s')), (('t_a_0', 'a'), ('a', 'a')), (('>>', '2_e'), ('>>', '2_e')), (('>>', '6_s'), ('>>', '6_s')), (('>>', '8_s'), ('>>', '8_s')), (('>>', 'b'), ('>>', None)), (('>>', '8_e'), ('>>', '8_e')), (('>>', '6_e'), ('>>', '6_e')), (('>>', '1_e'), ('>>', '1_e'))], 'cost': 0, 'visited_states': 11, 'queued_states': 15, 'traversed_arcs': 15, 'fitness': 1}] # l_alignments = [{'alignment': [('>>', '1_s'), ('>>', '2_s'), ('a', 'a'), ('>>', '2_e'), ('>>', '3_s'), # ('>>', '5_s'), ('>>', 'c'), ('>>', '5_e'), ('>>', '3_e'), ('>>', '1_e')], # 'cost': 2, 'visited_states': 3, 'queued_states': 4, 'traversed_arcs': 5, # 'fitness': 0.7777777777777778}] # # l_a_repair = repair_alignment.apply(tree1, tree2, log, l_alignments, self.parameters_tuple_false) # exp_l_a_repair = [{'alignment': [('>>', '1_s'), ('>>', '2_s'), ('a', 'a'), ('>>', '2_e'), ('>>', '6_s'), # ('>>', '8_s'), ('>>', None), ('>>', '8_e'), ('>>', '6_e'), ('>>', '1_e')], # 'cost': 0, 'visited_states': 3, 'queued_states': 4, 'traversed_arcs': 5, 'fitness': 1}] for i in range(len(alignments)): self.assertEqual(list(map(lambda x: x[1], a_repair[i]["alignment"])), list(map(lambda x: x[1], exp_a_repair[i]["alignment"]))) self.assertEqual(a_repair[i]["cost"], exp_a_repair[i]["cost"]) self.assertEqual(a_repair[i]["fitness"], exp_a_repair[i]["fitness"])
def create_pts(): pts = list() for node_num in PT_RANGE: trees = pd.DataFrame(columns=['tree', '#node', 'depth', 'root-op']) for i in range(pt_num): tree = pt_create.apply(random.randint(node_num[0], node_num[1])) num_nodes = pt_number.apply(tree, 'D') trees.loc[i] = [ str(tree), num_nodes, pt_mani_utils.pt_depth(tree), str(tree.operator) ] pts.append(trees) return pts
def compute_repair_result_option2(repair_file_result, mpt_index, align_mpt, result_file): """ Records ---------- """ input_list = object_read.read_expand_repair_grade_not_equal_to_one( repair_file_result, mpt_index, align_mpt) base = excel_utils.create_workbook() expand_e_table = ExcelTable(base.add_sheet("COMPARE")) parameters = {'ret_tuple_as_trans_desc': True, 'COMPARE_OPTION': 2} for (o_info, tree, m_tree, log, alignment_t1, alignment_t2) in input_list: pt_number.apply(tree, 'D', 1) pt_number.apply(m_tree, 'D', 1) expand_repair_info = expand_repair_align_info( tree, m_tree, log, alignment_t1.aligns, alignment_t2.best_worst_cost, alignment_t2.cost_opt, parameters) excel_utils.write_column_to_table(expand_e_table.table, expand_e_table.column, o_info + expand_repair_info[1]) excel_utils.save(base, result_file)
def test_random_create_tree_node(self): for _ in range(100): no_num = random.randint(10, 35) tree = pt_create.apply(no_num) index_num = pt_number.apply(tree, 'D', 1) self.assertEqual(no_num, index_num)