コード例 #1
0
ファイル: raw2data.py プロジェクト: thomastanck/LENSR
        if len(st) < 1:
            continue

        variables, relations, identified_var, pt = make_graph(this_fml, features=features, type_map=type_map)

        with open(f'{SAVE_PATH}/general_{ds_name}/{fml_idx}' + '.var', 'w') as f:
            for var in variables:
                f.write('\t'.join(list(map(str, var))))
                f.write('\n')
        with open(f'{SAVE_PATH}/general_{ds_name}/{fml_idx}' + '.rel', 'w') as f:
            for rel in relations:
                f.write('\t'.join(list(map(str, rel))))
                f.write('\n')

        # write cnf for fml
        cnf_to_dimacs(f'{SAVE_PATH}/cnf_{ds_name}_raw/{fml_idx}.cnf', clauses, len(atom_mapping) - 1)
        dimacs_to_nnf(f'{SAVE_PATH}/cnf_{ds_name}_raw/{fml_idx}.cnf',
                      f'{SAVE_PATH}/ddnnf_{ds_name}_raw/{fml_idx}.nnf',
                      '../c2d_linux')

        for ii, tt in enumerate(st):
            tt_sym = ['~' + atom_mapping[abs(i)] if i < 0 else atom_mapping[abs(i)] for i in tt]
            tt_variables = []
            tt_relations = []
            tt_variables.append([0] + list(features['Global']) + [type_map['Global']])
            tt_variables.append([1] + list(features['And']) + [type_map['And']])
            idx = 2
            for tt_sym_i in tt_sym:
                if tt_sym_i[0] == '~':
                    tt_variables.append([idx] + list((-1) * features[tt_sym_i[1]]) + [type_map['Symbol']])
                else:
コード例 #2
0
    symbol = []
    for i in range(atoms):
        symbol.append(0)
    for n in range(num_vars):
        sloution = []
        a = n
        ##确定符号,即将n二进制化
        for i in range(atoms):
            symbol[atoms-i-1] = a%2
            a = int(a/2)
        for i in range(atoms):
            if symbol[i] == 0:
                sloution.append(-(i+1))
            else:
                sloution.append(i+1)
        cnf_to_dimacs(f'{SAVE_PATH}/sol_cnf_{ds_name}_raw/{n}.cnf', [[i] for i in sloution], atoms)
        dimacs_to_nnf(f'{SAVE_PATH}/sol_cnf_{ds_name}_raw/{n}.cnf',
                      f'{SAVE_PATH}/sol_ddnnf_{ds_name}_raw/{n}.nnf',
                      '../c2d_linux')
    ##cnf2data
    save_path = SAVE_PATH

    directory_in_str = f'{save_path}/sol_cnf_{ds_name}_raw/'
    directory_in_str_out = f'{save_path}/sol_cnf_{ds_name}/'
    if not os.path.exists(directory_in_str_out):
        os.mkdir(directory_in_str_out)

    for file in tqdm(os.listdir(directory_in_str)):
        if file.endswith(".cnf"):
            input_dire = os.path.join(directory_in_str, file)
            output_dire = [os.path.join(directory_in_str_out, file[:-4] + '.var'),
コード例 #3
0
    img_filenames = []
    idx = 0

    if not os.path.exists('../dataset/VRD/vrd_raw/'):
        os.mkdir('../dataset/VRD/vrd_raw/')

    for key, anno in tqdm(annotation.items()):
        if len(anno) == 0:
            continue
        img_filenames.append(key)
        r_clauses, r_container = prepare_clauses(clauses, anno, converter,
                                                 objs)
        num_atom = max([
            abs(j) for i in r_container.get_relevant_formula().clauses
            for j in i
        ])
        cnf_to_dimacs(f'../dataset/VRD/vrd_raw/{idx}.cnf',
                      r_container.get_relevant_formula().clauses, num_atom)
        r_sol_t, r_sol_f = find(r_container.get_relevant_formula(),
                                5,
                                assumptions=[])
        for sol_t_idx in range(len(r_sol_t)):
            cnf_to_dimacs(f'../dataset/VRD/vrd_raw/{idx}.st{sol_t_idx}.cnf',
                          [[i] for i in r_sol_t[sol_t_idx]], num_atom)
            cnf_to_dimacs(f'../dataset/VRD/vrd_raw/{idx}.sf{sol_t_idx}.cnf',
                          [[i] for i in r_sol_f[sol_t_idx]], num_atom)
        idx += 1
    pk.dump(img_filenames, open(f'../dataset/VRD/vrd_raw/idx2filename.pk',
                                'wb'))