Beispiel #1
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'))
Beispiel #2
0
    ds_name = args.ds_name

    if not os.path.exists(f'{SAVE_PATH}/cnf_{ds_name}_raw/'):
        os.mkdir(f'{SAVE_PATH}/cnf_{ds_name}_raw/')
    if not os.path.exists(f'{SAVE_PATH}/ddnnf_{ds_name}_raw/'):
        os.mkdir(f'{SAVE_PATH}/ddnnf_{ds_name}_raw/')
    if not os.path.exists(f'{SAVE_PATH}/general_{ds_name}/'):
        os.mkdir(f'{SAVE_PATH}/general_{ds_name}/')

    fml_strings = pk.load(open(f'{SAVE_PATH}formula_strings_{ds_name}.pk', 'rb'))
    for fml_idx in tqdm(range(len(fml_strings))):
        this_fml = sympify(fml_strings[fml_idx], evaluate=False)
        clauses, atom_mapping = get_clauses(to_cnf(this_fml))
        f = formula.CNF()
        for c in clauses: f.append(c)
        st, sf = find(f, 5, assumptions=[])
        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
Beispiel #3
0
converter = Converter(var_pool, pres, objs)

f = pysat.formula.CNF()
for c in clauses:
    f.append([i for i in c])

for pos_rel in pos_rels:
    observation = [('_n_right', 'umbrella', 'table'),
                   ('_n_left', 'table', 'umbrella'),
                   ('_unique', 'table', 'table'),
                   ('_unique', 'umbrella', 'umbrella')]
    assumptions = gen_assumption(f, observation, converter)

    true_sols, false_sols = find(f,
                                 10,
                                 solver_name='Minisat22',
                                 assumptions=assumptions)
    for sol in true_sols:
        pos_sol = [i for i in sol if i > 0]
        print([converter.num2name(p_s) for p_s in pos_sol])

    break

with open('../resource/clauses.txt', 'w') as f:
    for c in clauses:
        f.write(str(c[0] / abs(c[0])) + str(converter.num2name(abs(c[0]))))
        f.write(' ')
        f.write(str(c[1] / abs(c[1])) + str(converter.num2name(abs(c[1]))))
        f.write('\n')