Exemplo n.º 1
0
def find_011_se_conditions_non_same_rules():
    file = config.get_isc_results_file_path(*kmn_data["0-1-1"], "")
    conditions = iscu.load_iconditions_from_file(file)
    non_same_conditions = list()
    same_rule_isets = {8, 17, 35, 44}
    for ic in conditions:
        ne_isets = ic.ne_iset_ids
        if ne_isets.issubset(same_rule_isets):
            print(ic)
        else:
            non_same_conditions.append(ic)

    simplified_dnf, sim_dnf = iscu.simplify_iconditions(non_same_conditions)
    ne_isets = iscu.get_iconditions_ne_isets(non_same_conditions)
    print(ne_isets)
    print(simplified_dnf)
Exemplo n.º 2
0
def check_110_icondition():
    ne_isets = {35}
    icondition_space_isets = {0, 1, 4, 8, 12, 17, 32, 35, 36, 40, 44}
    meta = ITaskMeta.load_itask_meta_data_from_file(config.isc_meta_data_file)
    meta_key = "1-1-0-lpmln-3"
    meta_data = meta[meta_key]
    condition_comp = iscu.complete_and_analyse_icondition(
        ne_isets, icondition_space_isets, meta_data)

    rule_sets = iscu.get_rule_sets(2, False)
    rule_set_size = 3

    for i in range(len(rule_sets)):
        if i % rule_set_size == 0:
            print("\n")
        key = rule_sets[i]
        print(key, ":", condition_comp[key])
Exemplo n.º 3
0
def process_010_iconditions():
    key = "0-1-0"
    file = config.get_isc_results_file_path(*kmn_data[key])
    conditions = iscu.load_iconditions_from_file(file, False)
    new_file = config.get_isc_results_file_path(*kmn_data[key], "ne")
    with open(new_file, encoding="utf-8", mode="w") as outf:
        for ic in conditions:
            outf.write(str(ic))
            outf.write("\n")
Exemplo n.º 4
0
def check_111_icondition_1():
    file = config.get_isc_results_file_path(*kmn_data["1-1-1"])
    conditions = iscu.load_iconditions_from_file(file)
    # iscu.normalize_iconditions(conditions)
    iscu.count_ne_iset_occurrences(conditions)

    ne_isets = {291, 35, 63, 81, 99, 127, 136, 163}
    conditions = iscu.get_iconditions_not_contains_all_ne_isets(
        conditions, ne_isets)
    print("has %d iconditions" % len(conditions))

    outf = r"C:\Users\wangb\Desktop\111-1.csv"
    iscu.normalize_iconditions(conditions, outf)

    ne_isets = iscu.get_iconditions_ne_isets(conditions)
    print("ne isets: ", [i + 1 for i in ne_isets], len(ne_isets))
    ignore_ne_isets = iscu.find_common_ne_isets_from_iconditions(conditions)
    print("common ne isets: ", [i + 1 for i in ignore_ne_isets],
          len(ignore_ne_isets))
    iscu.count_ne_iset_occurrences(conditions)
Exemplo n.º 5
0
def check_120_icondition_with_292():
    file = config.get_isc_results_file_path(*kmn_data["1-2-0"])
    conditions = iscu.load_iconditions_from_file(file)
    # iscu.normalize_iconditions(conditions)
    iscu.count_ne_iset_occurrences(conditions)

    # outf = r"C:\Users\wangb\Desktop\120.csv"
    # iscu.normalize_iconditions(conditions, outf)

    ne_isets = {291}
    conditions = iscu.get_iconditions_contains_at_least_one_of_ne_isets(
        conditions, ne_isets)
    ne_isets = iscu.get_iconditions_ne_isets(conditions)
    print("ne isets: ", [i + 1 for i in ne_isets], len(ne_isets))
    ignore_ne_isets = iscu.find_common_ne_isets_from_iconditions(conditions)
    print("common ne isets: ", [i + 1 for i in ignore_ne_isets],
          len(ignore_ne_isets))
    print("\n 1st occurrences: ")
    iscu.count_ne_iset_occurrences(conditions)
    print("\n 2nd occurrences: ")
    iscu.count_ne_iset_co_occurrences(conditions, 2)
Exemplo n.º 6
0
def check_021_icondition():
    ne_isets = {291}
    icondition_space_isets = {291, 99, 7, 72, 267, 15, 145, 127, 63}
    meta = ITaskMeta.load_itask_meta_data_from_file(config.isc_meta_data_file)
    meta_key = "2-1-0-lpmln-3"
    meta_data = meta[meta_key]
    condition_comp = iscu.complete_and_analyse_icondition(
        ne_isets, icondition_space_isets, meta_data)

    rule_sets = iscu.get_rule_sets(3, False)
    rule_set_size = 3

    for i in range(len(rule_sets)):
        if i % rule_set_size == 0:
            print("\n")
        key = rule_sets[i]
        print(key, ":", condition_comp[key])

    file = config.get_isc_results_file_path(*kmn_data["0-2-1"])
    conditions = iscu.load_iconditions_from_file(file)
    iscu.normalize_iconditions(conditions)
Exemplo n.º 7
0
def group_111_iconditions(type):
    print("compute preliminary_group_kmn_iconditions ... ")
    iscu.preliminary_group_kmn_iconditions(*kmn_data["1-1-1"], type)
    print("compute refine_iconditions_groups ... ")
    iscu.refine_iconditions_groups(*kmn_data["1-1-1"], type)
    print("compute compute_common_isets")
    iscu.compute_common_isets(*kmn_data["1-1-1"], type)
Exemplo n.º 8
0
def simplify_kmn_se_conditions(k_size, m_size, n_size, min_ne, max_ne, type, result_postfix=""):
    group_file = iscu.get_icondition_refine_group_file(k_size, m_size, n_size, min_ne, max_ne, type)
    clique_file = iscu.get_icondition_refine_group_file(k_size, m_size, n_size, min_ne, max_ne, type) + ".clique"
    sim_file = iscu.get_icondition_simplified_file(k_size, m_size, n_size, min_ne, max_ne, type, result_postfix)

    logging.info("init simplify_kmn_se_conditions ... ")

    groups = iscu.load_iconditions_groups(group_file)
    ic_file = config.get_isc_results_file_path(k_size, m_size, n_size, min_ne, max_ne, type)

    logging.info("load iconditions from %s " % ic_file)
    iconditions = iscu.load_iconditions_from_file(ic_file)
    all_icondition_ids = get_all_icondition_ids_from_kmn_groups(groups)

    logging.info("init groups data ...")
    for g in groups:
        desc = get_group_descentdants(groups, g)
        asc = get_group_ascentdants(groups, g)
        groups[g].group_parents = asc
        groups[g].group_children = desc

    logging.info("compute single root groups ... ")
    single_root_groups = split_kmn_group_into_single_root_groups(groups)
    logging.info("simplify %d-%d-%d (%d ~ %d) %s iconditions, load %d iconditions, find %d single root gropus" % (
        k_size, m_size, n_size, min_ne, max_ne, type, len(iconditions), len(single_root_groups)))
    clique_data = list()

    for sg in single_root_groups:
        cliques = get_all_kmn_cliques(sg, iconditions)
        clique_data.extend(cliques)

    is_finish = check_iconditions_in_cliques(all_icondition_ids, clique_data)
    clique_icondition_ids = get_clique_data_icondition_ids(clique_data)
    remained_iconditions = all_icondition_ids.difference(clique_icondition_ids)

    logging.info(("total find %d cliques, is finish %s, remain %d iconditions, remained iconditions " % (
        len(clique_data), str(is_finish), len(remained_iconditions)), remained_iconditions))

    if not is_finish:
        raise RuntimeError("clique not complete ...")

    max_clique_ids = find_max_cliques_from_clique_data(clique_data)
    all_ne_isets = iscu.get_iconditions_ne_isets(iconditions)
    all_singleton_isets = iscu.get_iconditions_singleton_isets(iconditions)
    max_clique_data = list()
    for m in max_clique_ids:
        common_empty_isets = all_ne_isets.difference(clique_data[m][2])
        may_non_empty_isets = all_ne_isets.difference(common_empty_isets)
        singletons_isets = all_singleton_isets.intersection(may_non_empty_isets)
        max_clique_data.append((clique_data[m][0], clique_data[m][1], common_empty_isets, singletons_isets))

    logging.info("\nmax cliques: \n")
    prettify_max_clique_from_clique_data(max_clique_data, clique_file)
    dump_simplified_se_conditions(max_clique_data, sim_file)
    logging.info("max cliques output to %s , %s " % (clique_file, sim_file))
Exemplo n.º 9
0
def group_kmn_iconditions(kmn_key, type):
    param = kmn_data[kmn_key]
    print("compute preliminary_group_kmn_iconditions ... ")
    iscu.preliminary_group_kmn_iconditions(*param, type)
    print("compute refine_iconditions_groups ... ")
    iscu.refine_iconditions_groups(*param, type)
    print("compute compute_common_isets")
    iscu.compute_common_isets(*param, type)
Exemplo n.º 10
0
def check_111_icondition_3():
    file = config.get_isc_results_file_path(*kmn_data["1-1-1"])
    conditions = iscu.load_iconditions_from_file(file)
    total_ne_isets = {
        1, 2, 8, 9, 10, 16, 17, 18, 36, 64, 73, 82, 100, 128, 137, 146, 164,
        256, 258, 265, 268, 272, 274, 289, 292
    }
    # iscu.normalize_iconditions(conditions)
    # iscu.count_ne_iset_occurrences(conditions)
    ne_isets = {291, 35, 63, 81, 99, 127, 136, 163}
    conditions = iscu.get_iconditions_contains_at_least_one_of_ne_isets(
        conditions, ne_isets)

    ne_isets = {35, 63, 81, 99, 127, 136, 163, 255, 257, 271, 273}
    conditions = iscu.get_iconditions_contains_at_least_one_of_ne_isets(
        conditions, ne_isets)

    print("has %d iconditions" % len(conditions))
    iscu.count_ne_iset_occurrences(conditions)

    total_ne_isets = iscu.get_iconditions_ne_isets(conditions)
    print("\ntotal ne isets ", total_ne_isets, len(total_ne_isets))
    ignore_remove_isets = {8, 17, 72, 145}
    # total_ne_isets = total_ne_isets.difference(ignore_remove_isets)
    total_ne_isets = list(total_ne_isets)
    total_ne_isets.sort()
    remove_ne_isets = set()
    for ne in total_ne_isets:
        remove_ne_isets.add(ne)
        print("remove ne ", remove_ne_isets)
        conditions = iscu.get_iconditions_not_contains_all_ne_isets(
            conditions, {ne})

        print("has %d iconditions" % len(conditions))

        ne_isets = iscu.get_iconditions_ne_isets(conditions)
        print("ne isets: ", [i + 1 for i in ne_isets], len(ne_isets))
        ignore_ne_isets = iscu.find_common_ne_isets_from_iconditions(
            conditions)
        print("common ne isets: ", [i + 1 for i in ignore_ne_isets],
              len(ignore_ne_isets))
        # iscu.count_ne_iset_occurrences(conditions)
        print("\n")
Exemplo n.º 11
0
def group_and_simplify_se_condtions(k_size, m_size, n_size, min_ne, max_ne, type):
    print("compute preliminary_group_kmn_iconditions ... ")
    iscu.preliminary_group_kmn_iconditions(k_size, m_size, n_size, min_ne, max_ne, type)
    print("compute refine_iconditions_groups ... ")
    iscu.refine_iconditions_groups(k_size, m_size, n_size, min_ne, max_ne, type)
    print("compute compute_common_isets ...")
    iscu.compute_common_isets(k_size, m_size, n_size, min_ne, max_ne, type)
    print("start simplify SE-conditions ...")
    simplify_kmn_se_conditions(k_size, m_size, n_size, min_ne, max_ne, type)
Exemplo n.º 12
0
def get_all_kmn_cliques(kmn_groups, iconditions):
    all_icondition_ids = get_all_icondition_ids_from_kmn_groups(kmn_groups)
    group_iconditions = list()
    for g in kmn_groups:
        group_iconditions.append(iconditions[g])

    group_ne_isets = iscu.get_iconditions_ne_isets(group_iconditions)
    check_cases = 2 ** len(group_ne_isets) - 1
    logging.info("kmn groups has %d non-empty isets, check %d cases" % (len(group_ne_isets), check_cases))
    empty_isets = empty_isets_generator(group_ne_isets)

    clique_data = list()

    for eis in empty_isets:
        clique_meta = list()
        new_kmn_groups = get_kmn_groups_from_iconditions_contain_all_isets(kmn_groups, iconditions, set(eis))
        cliques = check_cliques_of_kmn_groups(new_kmn_groups, iconditions)
        for cq in cliques:
            clique_meta.append(len(cq[0]))
        clique_data.extend(cliques)
        is_finish = check_iconditions_in_cliques(all_icondition_ids, clique_data)
        logging.info(("\t check non-empty isets: ", [i+1 for i in eis],
              ", find %d cliques, is finish %s, clique sizes: " % (len(cliques), str(is_finish)), clique_meta))
        if is_finish:
            break

        clique_meta = list()
        new_kmn_groups = get_kmn_groups_from_iconditions_contain_none_of_isets(kmn_groups, iconditions, set(eis))
        cliques = check_cliques_of_kmn_groups(new_kmn_groups, iconditions)
        for cq in cliques:
            clique_meta.append(len(cq[0]))
        clique_data.extend(cliques)
        is_finish = check_iconditions_in_cliques(all_icondition_ids, clique_data)
        logging.info(("\t check empty isets: ",  [i+1 for i in eis],
              ", find %d cliques, is finish %s, clique sizes: " % (len(cliques), str(is_finish)), clique_meta))

        if is_finish:
            break

    return clique_data
Exemplo n.º 13
0
def check_isc_data(kmn_key, type, is_simplify=True):
    print(kmn_key, "iset conditions: ")
    file = config.get_isc_results_file_path(*kmn_data[kmn_key], type)
    conditions = iscu.load_iconditions_from_file(file)
    ne_isets = iscu.get_iconditions_ne_isets(conditions)
    print("ne isets: ", [i + 1 for i in ne_isets])
    ignore_ne_isets = iscu.find_common_ne_isets_from_iconditions(conditions)
    print("common ne isets: ", [i + 1 for i in ignore_ne_isets])
    ignore_ne_isets = set()
    ne_symbols = iscu.get_iconditions_ne_isets_logic_symbols(
        conditions, ignore_ne_isets)
    print("ne logic symbols: ", ne_symbols)

    # for c in conditions:
    #     print(c, " : ", iscu.convert_icondition_2_conjunctive_formula(c, ne_symbols))

    if is_simplify:
        dnf = iscu.convert_iconditions_2_disjunctive_formula(
            conditions, ne_symbols)
        print("dnf: ", dnf)
        simp, simp_dnf = iscu.simplify_iconditions(conditions, ignore_ne_isets)
        print("simplified: ", simp)
        print("simplified dnf: ", simp_dnf)
Exemplo n.º 14
0
def check_010_iconditions():
    key = "0-1-0"
    file = config.get_isc_results_file_path(*kmn_data[key], "ne")
    conditions = iscu.load_iconditions_from_file(file)
    outf = r"C:\Users\wangb\Desktop\010.csv"
    iscu.normalize_iconditions(conditions, outf)
Exemplo n.º 15
0
def check_111_icondition_3_3():
    file = config.get_isc_results_file_path(*kmn_data["1-1-1"])
    conditions = iscu.load_iconditions_from_file(file)
    ne_isets = {291, 35, 63, 81, 99, 127, 136, 163}
    conditions = iscu.get_iconditions_contains_at_least_one_of_ne_isets(
        conditions, ne_isets)

    ne_isets = {35, 63, 81, 99, 127, 136, 163, 255, 257, 271, 273}
    conditions = iscu.get_iconditions_contains_at_least_one_of_ne_isets(
        conditions, ne_isets)

    ne_isets = {291, 273, 255, 163, 136, 127, 99, 81, 267, 288}
    conditions = iscu.get_iconditions_contains_at_least_one_of_ne_isets(
        conditions, ne_isets)

    ne_isets = {291, 273, 264, 163, 136, 127, 35}
    conditions = iscu.get_iconditions_contains_at_least_one_of_ne_isets(
        conditions, ne_isets)

    print("has %d iconditions" % len(conditions))
    iscu.count_ne_iset_occurrences(conditions)

    remove_ne_isets = {291, 163, 35}
    print("remove ne ", remove_ne_isets)
    conditions = iscu.get_iconditions_not_contains_all_ne_isets(
        conditions, remove_ne_isets)

    outf = r"C:\Users\wangb\Desktop\111.csv"
    iscu.normalize_iconditions(conditions, outf)

    print("has %d iconditions" % len(conditions))

    ne_isets = iscu.get_iconditions_ne_isets(conditions)
    print("ne isets: ", [i + 1 for i in ne_isets], len(ne_isets))
    ignore_ne_isets = iscu.find_common_ne_isets_from_iconditions(conditions)
    print("common ne isets: ", [i + 1 for i in ignore_ne_isets],
          len(ignore_ne_isets))
    iscu.count_ne_iset_occurrences(conditions)
    print("\n")
Exemplo n.º 16
0
def find_max_clique(kmn_key, type):
    print("find max clique ...")
    clique_data = iscu.find_max_clique_3(*kmn_data[kmn_key], type)
    return clique_data
Exemplo n.º 17
0
def group_and_find_max_clique_kmn_iconditions(kmn_key, type):
    group_kmn_iconditions(kmn_key, type)
    print("find max clique ...")
    clique_data = iscu.find_max_clique_3(*kmn_data[kmn_key], type)
    return clique_data
Exemplo n.º 18
0
def find_021_max_clique():
    param = kmn_data["0-2-1"]
    iscu.find_max_clique(*param, "")