示例#1
0
文件: api_solver.cpp 项目: levnach/z3
 static Z3_lbool _solver_check(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[]) {
     for (unsigned i = 0; i < num_assumptions; i++) {
         if (!is_expr(to_ast(assumptions[i]))) {
             SET_ERROR_CODE(Z3_INVALID_ARG, "assumption is not an expression");
             return Z3_L_UNDEF;
         }
     }
     expr * const * _assumptions = to_exprs(assumptions);
     unsigned timeout     = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit      = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     bool     use_ctrl_c  = to_solver(s)->m_params.get_bool("ctrl_c", false);
     cancel_eh<reslimit> eh(mk_c(c)->m().limit());
     api::context::set_interruptable si(*(mk_c(c)), eh);
     lbool result;
     {
         scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
         scoped_timer timer(timeout, &eh);
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         try {
             result = to_solver_ref(s)->check_sat(num_assumptions, _assumptions);
         }
         catch (z3_exception & ex) {
             to_solver_ref(s)->set_reason_unknown(eh);
             if (!mk_c(c)->m().canceled()) {
                 mk_c(c)->handle_exception(ex);
             }
             return Z3_L_UNDEF;
         }
     }
     if (result == l_undef) {
         to_solver_ref(s)->set_reason_unknown(eh);
     }
     return static_cast<Z3_lbool>(result);
 }
示例#2
0
文件: api_solver.cpp 项目: levnach/z3
 Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, 
                                     Z3_solver s,
                                     Z3_ast_vector assumptions,
                                     Z3_ast_vector variables,
                                     Z3_ast_vector consequences) {
     Z3_TRY;
     LOG_Z3_solver_get_consequences(c, s, assumptions, variables, consequences);
     ast_manager& m = mk_c(c)->m();
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     init_solver(c, s);
     expr_ref_vector _assumptions(m), _consequences(m), _variables(m);
     ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
     for (ast* e : __assumptions) {
         if (!is_expr(e)) {
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             SET_ERROR_CODE(Z3_INVALID_USAGE, "assumption is not an expression");
             return Z3_L_UNDEF;
         }
         _assumptions.push_back(to_expr(e));
     }
     ast_ref_vector const& __variables = to_ast_vector_ref(variables);
     for (ast* a : __variables) {
         if (!is_expr(a)) {
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             SET_ERROR_CODE(Z3_INVALID_USAGE, "variable is not an expression");
             return Z3_L_UNDEF;
         }
         _variables.push_back(to_expr(a));
     }
     lbool result = l_undef;
     unsigned timeout     = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit      = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     bool     use_ctrl_c  = to_solver(s)->m_params.get_bool("ctrl_c", false);
     cancel_eh<reslimit> eh(mk_c(c)->m().limit());
     api::context::set_interruptable si(*(mk_c(c)), eh);
     {
         scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
         scoped_timer timer(timeout, &eh);
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         try {
             result = to_solver_ref(s)->get_consequences(_assumptions, _variables, _consequences);
         }
         catch (z3_exception & ex) {
             to_solver_ref(s)->set_reason_unknown(eh);
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             mk_c(c)->handle_exception(ex);
             return Z3_L_UNDEF;
         }
     }
     if (result == l_undef) {
         to_solver_ref(s)->set_reason_unknown(eh);
     }
     for (expr* e : _consequences) {
         to_ast_vector_ref(consequences).push_back(e);
     }
     return static_cast<Z3_lbool>(result); 
     Z3_CATCH_RETURN(Z3_L_UNDEF);        
 }
示例#3
0
文件: api_solver.cpp 项目: ai-se/z3
 Z3_solver Z3_API Z3_solver_translate(Z3_context c, Z3_solver s, Z3_context target) {
     Z3_TRY;
     LOG_Z3_solver_translate(c, s, target);
     RESET_ERROR_CODE();
     params_ref const& p = to_solver(s)->m_params; 
     Z3_solver_ref * sr = alloc(Z3_solver_ref, 0);
     sr->m_solver = to_solver(s)->m_solver->translate(mk_c(target)->m(), p);
     mk_c(target)->save_object(sr);
     Z3_solver r = of_solver(sr);
     RETURN_Z3(r);
     Z3_CATCH_RETURN(0);
 }
示例#4
0
文件: api_solver.cpp 项目: levnach/z3
 void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s) {
     Z3_TRY;
     LOG_Z3_solver_reset(c, s);
     RESET_ERROR_CODE();
     to_solver(s)->m_solver = nullptr;
     Z3_CATCH;
 }
示例#5
0
文件: api_solver.cpp 项目: levnach/z3
 void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s) {
     Z3_TRY;
     LOG_Z3_solver_dec_ref(c, s);
     RESET_ERROR_CODE();
     to_solver(s)->dec_ref();
     Z3_CATCH;
 }
示例#6
0
文件: api_solver.cpp 项目: levnach/z3
 Z3_param_descrs Z3_API Z3_solver_get_param_descrs(Z3_context c, Z3_solver s) {
     Z3_TRY;
     LOG_Z3_solver_get_param_descrs(c, s);
     RESET_ERROR_CODE();
     Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref, *mk_c(c));
     mk_c(c)->save_object(d);
     bool initialized = to_solver(s)->m_solver.get() != nullptr;
     if (!initialized)
         init_solver(c, s);
     to_solver_ref(s)->collect_param_descrs(d->m_descrs);
     context_params::collect_solver_param_descrs(d->m_descrs);
     if (!initialized)
         to_solver(s)->m_solver = nullptr;
     Z3_param_descrs r = of_param_descrs(d);
     RETURN_Z3(r);
     Z3_CATCH_RETURN(nullptr);
 }
示例#7
0
文件: api_solver.cpp 项目: levnach/z3
 Z3_string Z3_API Z3_solver_get_help(Z3_context c, Z3_solver s) {
     Z3_TRY;
     LOG_Z3_solver_get_help(c, s);
     RESET_ERROR_CODE();
     std::ostringstream buffer;
     param_descrs descrs;
     bool initialized = to_solver(s)->m_solver.get() != nullptr;
     if (!initialized)
         init_solver(c, s);
     to_solver_ref(s)->collect_param_descrs(descrs);
     context_params::collect_solver_param_descrs(descrs);
     if (!initialized)
         to_solver(s)->m_solver = nullptr;
     descrs.display(buffer);
     return mk_c(c)->mk_external_string(buffer.str());
     Z3_CATCH_RETURN("");
 }
示例#8
0
文件: api_solver.cpp 项目: ai-se/z3
    void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p) {
        Z3_TRY;
        LOG_Z3_solver_set_params(c, s, p);
        RESET_ERROR_CODE();

        if (to_solver(s)->m_solver) {
            bool old_model = to_solver(s)->m_params.get_bool("model", true);
            bool new_model = to_param_ref(p).get_bool("model", true);
            if (old_model != new_model)
                to_solver_ref(s)->set_produce_models(new_model);
            param_descrs r;
            to_solver_ref(s)->collect_param_descrs(r);
            context_params::collect_solver_param_descrs(r);
            to_param_ref(p).validate(r);
            to_solver_ref(s)->updt_params(to_param_ref(p));
        }
        to_solver(s)->m_params.append(to_param_ref(p));
        Z3_CATCH;
    }
示例#9
0
文件: api_solver.cpp 项目: levnach/z3
 Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vs, unsigned cutoff) {
     Z3_TRY;
     LOG_Z3_solver_cube(c, s, vs, cutoff);
     ast_manager& m = mk_c(c)->m();
     expr_ref_vector result(m), vars(m);
     for (ast* a : to_ast_vector_ref(vs)) {
         if (!is_expr(a)) {
             SET_ERROR_CODE(Z3_INVALID_USAGE, "cube contains a non-expression");
         }
         else {
             vars.push_back(to_expr(a));
         }
     }
     unsigned timeout     = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit      = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     bool     use_ctrl_c  = to_solver(s)->m_params.get_bool("ctrl_c", false);
     cancel_eh<reslimit> eh(mk_c(c)->m().limit());
     api::context::set_interruptable si(*(mk_c(c)), eh);
     {
         scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
         scoped_timer timer(timeout, &eh);
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         try {
             result.append(to_solver_ref(s)->cube(vars, cutoff));
         }
         catch (z3_exception & ex) {
             mk_c(c)->handle_exception(ex);
             return nullptr;
         }
     }
     Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
     mk_c(c)->save_object(v);
     for (expr* e : result) {
         v->m_ast_vector.push_back(e);
     }
     to_ast_vector_ref(vs).reset();
     for (expr* a : vars) {
         to_ast_vector_ref(vs).push_back(a);
     }
     RETURN_Z3(of_ast_vector(v));
     Z3_CATCH_RETURN(nullptr);
 }
示例#10
0
文件: api_solver.cpp 项目: levnach/z3
 static void init_solver_core(Z3_context c, Z3_solver _s) {
     Z3_solver_ref * s = to_solver(_s);
     bool proofs_enabled, models_enabled, unsat_core_enabled;
     params_ref p = s->m_params;
     mk_c(c)->params().get_solver_params(mk_c(c)->m(), p, proofs_enabled, models_enabled, unsat_core_enabled);
     s->m_solver = (*(s->m_solver_factory))(mk_c(c)->m(), p, proofs_enabled, models_enabled, unsat_core_enabled, s->m_logic);
     
     param_descrs r;
     s->m_solver->collect_param_descrs(r);
     context_params::collect_solver_param_descrs(r);
     p.validate(r);
     s->m_solver->updt_params(p);
 }
示例#11
0
文件: api_solver.cpp 项目: levnach/z3
    void solver_from_stream(Z3_context c, Z3_solver s, std::istream& is) {
        scoped_ptr<cmd_context> ctx = alloc(cmd_context, false, &(mk_c(c)->m()));
        ctx->set_ignore_check(true);
        std::stringstream errstrm;
        ctx->set_regular_stream(errstrm);

        if (!parse_smt2_commands(*ctx.get(), is)) {
            ctx = nullptr;
            SET_ERROR_CODE(Z3_PARSER_ERROR, errstrm.str().c_str());
            return;
        }

        bool initialized = to_solver(s)->m_solver.get() != nullptr;
        if (!initialized)
            init_solver(c, s);
        for (expr * e : ctx->assertions()) {
            to_solver_ref(s)->assert_expr(e);
        }
        to_solver_ref(s)->set_model_converter(ctx->get_model_converter());
    }
示例#12
0
文件: api_solver.cpp 项目: levnach/z3
 static void init_solver(Z3_context c, Z3_solver s) {
     if (to_solver(s)->m_solver.get() == nullptr)
         init_solver_core(c, s);
 }