Ejemplo n.º 1
0
def example_repair_alignment():
    """
    Repair Alignment

    Input:
        Two Numbered Process Tree
        Event Log
    Output:
        Alignment on One Tree1,
        Repaired Alignment On Tree2
    """
    print_spilt_start("optimal-alignment-repair")
    tree1 = pm4py.objects.process_tree.pt_util.parse("+( a, X( g, h ) ) ")
    tree2 = pm4py.objects.process_tree.pt_util.parse("+( a, ->( g, h ) )")
    log = create_event_log("agh")
    parameters = {'ret_tuple_as_trans_desc': True}
    state = repair_alignment.algo.repair.repair.Version.AR_LINEAR
    option = 1
    alignments, repair_alignments = repair_alignment.algo.repair.repair.apply(tree1, tree2, log, state, parameters,
                                                                              option)

    print("Tree1:", tree1)
    print("Tree2:", tree2)
    print("Event Log:", end=" ")
    print_event_log(log)
    print("Alignment on Tree1:\n\t", alignments)
    print("Repaired Alignment on Tree2:\n\t", repair_alignments)
    print_spilt_end()
Ejemplo n.º 2
0
def example_repair_alignment_with_lock():
    """
    Repair Alignment

    Input:
        Two Numbered Process Tree
        Event Log
        Alignment on One Process Tree
    Output:
        Repaired Alignment On Tree2
    """
    print_spilt_start("alignment-repair")
    tree1 = pm4py.objects.process_tree.pt_util.parse("+( a, X( g, h ) ) ")
    tree2 = pm4py.objects.process_tree.pt_util.parse("+( a, ->( g, h ) )")
    repair_alignment.process_tree.operation.pt_number.apply(tree1, 'D', 1)
    repair_alignment.process_tree.operation.pt_number.apply(tree2, 'D', 1)
    log = create_event_log("agh")
    alignment_on_tree1 = alignment_on_lock_pt(tree1, log)

    repaired_alignment = repair_alignment.deprecation.ar_lock. \
        apply(tree1, tree2, log, alignment_on_tree1, {'ret_tuple_as_trans_desc': True})

    print("Tree1:", tree1)
    print("Tree2:", tree2)
    print("Event Log:", end=" ")
    print_event_log(log)
    print("Alignment on Tree1:\n\t", alignment_on_tree1)
    print("Repaired Alignment on Tree2:\n\t", repaired_alignment)
    print_spilt_end()
Ejemplo n.º 3
0
def compute_align_grade(num, version, option, file):
    mp_trees = pd.read_excel(m_tree_file, sheet_name=SHEET_NAME)
    # logs = pd.read_excel(log_file, sheet_name=SHEET_NAME)

    align_result = list()
    for i in mp_trees:
        # log_list = logs[i]['log'].tolist()
        log_list = pd.read_csv(PATH + '/0.2/log' + i + ".csv")['log'].tolist()
        tree_list = mp_trees[i]['tree'].tolist()
        mpt_list = mp_trees[i]['m_tree'].tolist()
        align_info = pd.DataFrame(columns=[
            "optimal time", "optimal cost", "repair align time",
            "repair align cost", "grade"
        ])
        for j, m_tree in enumerate(mpt_list):
            m_tree = pt_utils.parse(m_tree)
            tree = pt_utils.parse(tree_list[j])
            log = create_event_log(log_list[j // num])
            align_info.loc[len(align_info.index)] = apply_align_on_one_pt(
                tree, m_tree, log, version, option)
        align_result.append(align_info)
        return
    with pd.ExcelWriter(file) as writer:
        for i, align in enumerate(align_result):
            align.to_excel(writer, sheet_name=SHEET_NAME[i], index=False)
def test_compute_cost_time(parameters):
    tree1 = pt_utils.parse("->( a, *( *( c, X( d, e ), τ ), b, τ ) )")
    tree2 = pt_utils.parse("->( a, *( *( τ, X( d, e ), τ ), b, τ ) )")
    log = create_event_log("chcb")

    result = compute_cost_and_time(tree1, tree2, log, parameters)
    print_tree_align_compare(result)
Ejemplo n.º 5
0
def compute_align_grade1(num):
    trees = pd.read_excel(tree_file, sheet_name=SHEET_NAME)
    mp_trees = pd.read_excel(m_tree_file, sheet_name=SHEET_NAME)
    # logs = pd.read_excel(log_file, sheet_name=SHEET_NAME)

    align_result = list()
    align_result2 = list()
    align_result3 = list()
    # align_result4 = list()
    for i in trees:
        itree_list = trees[i]['tree'].tolist()
        log_list = pd.read_csv(PATH + 'log' + i + ".csv")['log'].tolist()
        # log_list = logs[i]['log'].tolist()
        tree_list = mp_trees[i]['tree'].tolist()
        mpt_list = mp_trees[i]['m_tree'].tolist()

        align_info = pd.DataFrame(columns=[
            "optimal time", "optimal cost", "repair align time",
            "repair align cost", "grade"
        ])
        align_info2 = pd.DataFrame(columns=[
            "optimal time", "optimal cost", "repair align time",
            "repair align cost", "grade"
        ])
        align_info3 = pd.DataFrame(columns=[
            "optimal time", "optimal cost", "repair align time",
            "repair align cost", "grade"
        ])
        # align_info4 = pd.DataFrame(columns=["optimal time", "optimal cost", "best worst cost",
        #                                     "repair align time", "repair align cost", "grade"])
        for k, tree in enumerate(tree_list):
            log = create_event_log(log_list[k])
            alignments = alignment_on_pt(tree, log)
            for j in range(num):
                m_tree = pt_utils.parse(mpt_list[k * num + j])
                info = apply_align_on_one_pt2(tree, m_tree, log, alignments)
                align_info.loc[len(align_info.index)] = info[0]
                align_info2.loc[len(align_info.index)] = info[1]
                align_info3.loc[len(align_info.index)] = info[2]
            # align_info4.loc[len(align_info.index)] = info[3]
        align_result.append(align_info)
        align_result2.append(align_info2)
        align_result3.append(align_info3)
        # align_result4.append(align_info4)

    with pd.ExcelWriter(PATH + 'ar.xlsx') as writer:
        for i, align in enumerate(align_result):
            align.to_excel(writer, sheet_name=SHEET_NAME[i], index=False)

    with pd.ExcelWriter(PATH + 'iar.xlsx') as writer:
        for i, align in enumerate(align_result2):
            align.to_excel(writer, sheet_name=SHEET_NAME[i], index=False)

    with pd.ExcelWriter(PATH + 'iar_ud.xlsx') as writer:
        for i, align in enumerate(align_result3):
            align.to_excel(writer, sheet_name=SHEET_NAME[i], index=False)
Ejemplo n.º 6
0
def compute_alignment1(version, option):
    # tree_num, mutated_num, log_num, non_fit_pro = 10, 5, 5, 0.2
    # node_num = [20, 25]
    # tree = [pt_create.apply(random.randint(node_num[0], node_num[1])) for _ in range(tree_num)]
    # m_tree = [[pt_mutate.apply(tree) for _ in range(mutated_num)] for tree in tree]
    # log = [log_create.apply(tree, log_num, non_fit_pro) for tree in tree]
    # for i in range(len(tree)):
    #     for j in range(len(m_tree[0])):
    #         optimal_time, optimal_cost, best_worst_cost, ra_time, ra_cost, grade = \
    #             align_info(tree[i], m_tree[i][j], log[i], apply, option)
    data = pd.read_excel(PATH + "MProcessTree.xlsx",
                         sheet_name='16-18',
                         header=0)
    log_d = pd.read_excel(PATH + "0.2/log.xlsx", sheet_name='16-18', header=0)
    trees = data['tree']
    m_trees = data['m_tree']
    logs = log_d['log']
    optimal_time, optimal_cost, best_worst_cost = list(), list(), list()
    ra_time, ra_cost, grade = list(), list(), list()
    for i in range(len(trees)):
        info = align_info(pt_utils.parse(trees[i]), pt_utils.parse(m_trees[i]),
                          create_event_log(logs[i // 15]), version, option)
        optimal_time.append(info[0])
        optimal_cost.append(info[1])
        best_worst_cost.append(info[2])
        ra_time.append(info[3])
        ra_cost.append(info[4])
        grade.append(info[5])
        if i > 200:
            repair_align_compare(pt_utils.parse(trees[i]),
                                 pt_utils.parse(m_trees[i]),
                                 create_event_log(logs[i // 15]))
    df = pd.DataFrame({
        "optimal time": optimal_time,
        "optimal cost": optimal_cost,
        "best worst cost": best_worst_cost,
        "repair align time": ra_time,
        "repair align cost": ra_cost,
        "grade": grade
    })
    df.to_csv(PATH + "align_repair_opt2.csv")
Ejemplo n.º 7
0
def read_logs_from_file(file):
    data = excel_utils.open_excel(file)
    logs = list()
    for index in range(len(LOG_SHEET_NAME)):
        table = data.sheets()[index]
        for col in range(table.ncols):
            s_log = ", ".join(
                list(
                    map(lambda t: t[0],
                        excel_utils.read_table_columns(table, [col]))))
            logs.append(create_event_log(s_log))
    return logs
                             '2: improved alignment repair with lock; ' \
                             '3: improved alignment repair Up to Down; '\
                             'default 3', metavar='version')
    parser.add_argument('--o', nargs='?', default=1, type=int,
                        help='1: return the smallest changed scope; '
                             '2: return the subtree of the parent of the changed scope if ' \
                             'the parent of the smallest changed scope has loop operator; '
                             'default 1', metavar='option')
    parser.add_argument('--s', nargs='?', default=False, type=bool,
                        help='indicate whether to write to file, ' \
                             'default=False', metavar='save', choices=[False, True])

    args = parser.parse_args()
    # print("start of plugin with arguments: ", args)
    #
    T1 = args.t1
    T2 = args.t2
    A1 = args.a1
    paras = args.parameter
    version = args.v
    option = args.o
    save_to_file = args.s
    tree = pt_utils.parse(
        "*( X( ->( b, c ), +( X( i, j ), X( g, h, ->( d, e, f ) ) ) ), a, τ )")
    m_tree = pt_utils.parse(
        "*( X( ->( b, c ), +( X( i, j ), X( g, h, ->( d, e, f, l ) ) ) ), a, τ )"
    )
    log = create_event_log("jfljgabc")
    a1, a2 = apply(tree, m_tree, log, version, option=option)
    print(a2)