예제 #1
0
def generate_wcnfs(path, models_and_contexts):

    for i, elem in enumerate(models_and_contexts):
        model = elem["model"]
        contexts = elem["contexts"]

        wcnf = WCNF()
        for weight_clause in model:
            if weight_clause[0] == None:
                wcnf.append(tuple(weight_clause[1]))
            else:
                wcnf.append(tuple(weight_clause[1]), weight=weight_clause[0])
        wcnf.to_file(path + f"_{i}.wcnf")

        for j, context in enumerate(contexts):
            wcnf_context = wcnf.copy()
            #            print(context)
            for literals in context:
                wcnf_context.append((literals,))
            wcnf_context.to_file(path + f"_{i}_context_{j}.wcnf")
예제 #2
0
    mcsls, to_enum, improved, solver, verbose, files = parse_options()

    if files:
        # input WCNF formula with multiple observations
        wcnf = WCNF(from_file=files[0], comment_lead=['c', 'o'])

        # multiple observations
        mobs = list(filter(lambda x: x[0] == 'o', wcnf.comments))

        # list of lists of individual diagnoses
        diags = [[] for o in mobs]

        # going through all observations
        for i, o in enumerate(mobs):
            # creating a copy of the formula
            wcnf_o = wcnf.copy()
            for l in o.split()[1:-1]:
                wcnf_o.append([int(l)])

            if verbose:
                print('c observation', i + 1)

            # enumerating individual diagnoses
            with mcsls(wcnf_o, use_cld=True, solver_name=solver) as oracle:
                for j, mcs in enumerate(oracle.enumerate()):
                    if verbose > 1:
                        print('c I:', ' '.join([str(cl_id) for cl_id in mcs]),
                              '0')

                    if to_enum and j + 1 == to_enum:
                        break