예제 #1
0
파일: benchmarks.py 프로젝트: jiry17/IntSy
def std_unification_solver(theory, syn_ctx, synth_funs, grammar_map, specification, verifier):
    if len(synth_funs) > 1:
        raise UnsuitableSolverException("DT Unification Solver: Multi-function unification not supported")
    if specification.is_multipoint:
        raise UnsuitableSolverException("Multi point specification")

    synth_fun = synth_funs[0]
    grammar = grammar_map[synth_fun]

    decomposed_grammar = grammar.decompose(syn_ctx.macro_instantiator)
    if decomposed_grammar == None:
        raise UnsuitableSolverException("DT Unification Solver: Unable to decompose grammar")
    term_grammar, pred_grammar, reverse_mapping = decomposed_grammar

    generator_factory = enumerators.PointDistinctGeneratorFactory(specification)
    term_generator = term_grammar.to_generator(generator_factory)
    pred_generator = pred_grammar.to_generator(generator_factory)
    solver = solvers.Solver(syn_ctx)
    term_solver = termsolvers.PointDistinctTermSolver(specification.term_signature, term_generator)
    unifier = unifiers.PointDistinctDTUnifier(pred_generator, term_solver, synth_fun, syn_ctx)
    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(
            generator_factory,
            term_solver,
            unifier,
            verifier,
            verify_term_solve=True
            )
    solution = next(solutions)
    final_solution = rewrite_solution([synth_fun], solution, reverse_mapping)
    return final_solution
예제 #2
0
def std_unification_solver(theory,
                           syn_ctx,
                           synth_funs,
                           grammar_map,
                           specification,
                           verifier,
                           phog_file,
                           options=options):
    if len(synth_funs) > 1:
        raise UnsuitableSolverException(
            "DT Unification Solver: Multi-function unification not supported")
    if specification.is_multipoint:
        raise UnsuitableSolverException("Multi point specification")

    synth_fun = synth_funs[0]
    grammar = grammar_map[synth_fun]

    decomposed_grammar = grammar.decompose(syn_ctx.macro_instantiator)
    if decomposed_grammar == None:
        raise UnsuitableSolverException(
            "DT Unification Solver: Unable to decompose grammar")
    term_grammar, pred_grammar, reverse_mapping = decomposed_grammar
    generator_factory = enumerators.PointDistinctGeneratorFactory(
        specification)
    term_generator = term_grammar.to_generator(generator_factory)
    pred_generator = pred_grammar.to_generator(generator_factory)
    solver = solvers.Solver(syn_ctx)
    term_phog = SPhog(term_grammar, phog_file, synth_fun.range_type, specification, for_eusolver=True, for_pred_exprs=False) if options.use_sphog() else \
        Phog(term_grammar, phog_file, synth_fun.range_type, for_eusolver=True, for_pred_exprs=False)
    pred_phog = SPhog(pred_grammar, phog_file, synth_fun.range_type, specification, for_eusolver=True, for_pred_exprs=True, ref_grammar=term_grammar) if options.use_sphog() else \
        Phog(pred_grammar, phog_file, synth_fun.range_type, for_eusolver=True, for_pred_exprs=True)

    if term_phog.stat_map is None:
        print(
            'No model available for this problem. We use the classic EUSolver ...'
        )
        term_phog = None
        pred_phog = None
    if pred_phog is not None and pred_phog.stat_map is None:
        pred_phog = None

    term_solver = termsolvers.PointDistinctTermSolver(
        specification.term_signature, term_generator, stat_model=term_phog)
    unifier = unifiers.PointDistinctDTUnifier(pred_generator,
                                              term_solver,
                                              synth_fun,
                                              syn_ctx,
                                              stat_model=pred_phog)
    solver = solvers.Solver(syn_ctx)
    solutions = solver.solve(generator_factory,
                             term_solver,
                             unifier,
                             verifier,
                             verify_term_solve=True)
    solution = next(solutions)
    final_solution = rewrite_solution([synth_fun], solution, reverse_mapping)
    return final_solution
예제 #3
0
 def __init__(self,
              pred_generator,
              term_solver,
              synth_fun,
              syn_ctx,
              stat_model=None):
     super().__init__(pred_generator, term_solver, syn_ctx)
     indicator_fun, compute_indicator = \
             self._dummy_spec(synth_fun)
     self.pred_solver = termsolvers.PointDistinctTermSolver(
         compute_indicator, pred_generator, stat_model=stat_model)