为Z3'设置超时;s ctx解算器简化策略

为Z3'设置超时;s ctx解算器简化策略,z3,Z3,我是Z3的新手。这是我的代码: void timeout_c_api() { Z3_config cfg; cfg = Z3_mk_config(); Z3_set_param_value(cfg, "model", "true"); Z3_set_param_value(cfg, "timeout", "1"); Z3_global_param_set("timeout","1"); Z3_context ctx; ctx = Z3

我是Z3的新手。这是我的代码:

void timeout_c_api() {
    Z3_config  cfg;

    cfg = Z3_mk_config();
    Z3_set_param_value(cfg, "model", "true");
    Z3_set_param_value(cfg, "timeout", "1");
    Z3_global_param_set("timeout","1");

    Z3_context ctx;
    ctx = Z3_mk_context(cfg);
    auto t_params = Z3_mk_params(ctx);
    Z3_params_inc_ref(ctx, t_params);
    auto param_symbol = Z3_mk_string_symbol(ctx, "timeout");
    Z3_params_set_uint (ctx, t_params, param_symbol, 1);

    Z3_tactic tactic = Z3_mk_tactic(ctx, "ctx-solver-simplify");
    Z3_tactic_inc_ref(ctx, tactic);
    Z3_goal g = Z3_mk_goal(ctx, false, false, false);
    Z3_goal_inc_ref(ctx, g);
    Z3_ast ast;
    Z3_symbol symbols[3];
    symbols[0] = Z3_mk_string_symbol(ctx, "a");
    symbols[1] = Z3_mk_string_symbol(ctx, "b");
    symbols[2] = Z3_mk_string_symbol(ctx, "c");
    Z3_func_decl decls[3];
    auto x  = mk_int_var(ctx, "a");
    decls[0] = Z3_get_app_decl(ctx, Z3_to_app(ctx, x));
    auto y  = mk_int_var(ctx, "b");
    decls[1] = Z3_get_app_decl(ctx, Z3_to_app(ctx, y));
    auto z  = mk_int_var(ctx, "c");
    decls[2] = Z3_get_app_decl(ctx, Z3_to_app(ctx, z));
    auto thm = Z3_parse_smtlib2_string(ctx,
                                       "(declare-const a Int)\n"
                                       "(declare-const b Int)\n"
                                       "(declare-const c Int)(assert (or (and (> (+ c b) 2) (< (* (* (+ c b) c) ( * ( * ( + c -1) ( + b -1)) ( + ( + c b) -1))) 1234567)) ( and (not ( > ( + c b) 2)) ( < ( * ( * ( + c b) c) ( * ( + ( + c b) 1) b)) 1234567))))",
                                       0, nullptr, nullptr,
                                       0, symbols, decls);
    ast = Z3_ast_vector_get(ctx, thm, 0);
    Z3_goal_assert(ctx, g, ast);
    Z3_apply_result apply_result1 = Z3_tactic_apply(ctx, tactic, g);
    Z3_string z3_string = Z3_apply_result_to_string(ctx, apply_result1);
    std::cout<<z3_string<<"\n";
    Z3_goal_assert(ctx, g, ast);
}
void timeout\u c\u api(){
Z3_-config-cfg;
cfg=Z3_mk_config();
Z3设置参数值(cfg,“模型”,“真”);
Z3设置参数值(cfg,“超时”,“1”);
Z3全局参数集(“超时”,“1”);
Z3_-ctx;
ctx=Z3_mk_上下文(cfg);
自动t_参数=Z3_mk_参数(ctx);
Z3参数公司参考(ctx,t参数);
自动参数符号=Z3_mk_字符串符号(ctx,“超时”);
Z3参数集单元(ctx,t参数,参数符号,1);
Z3_策略=Z3_mk_策略(ctx,“ctx求解器简化”);
Z3战术公司(ctx,战术);
Z3_目标g=Z3_mk_目标(ctx,false,false,false);
Z3_goal_inc_ref(ctx,g);
Z3_ast;
Z3_符号[3];
符号[0]=Z3_mk_字符串_符号(ctx,“a”);
符号[1]=Z3_mk_字符串_符号(ctx,“b”);
符号[2]=Z3_mk_字符串_符号(ctx,“c”);
Z3_func_decl decls[3];
自动x=mk_int_var(ctx,“a”);
decls[0]=Z3_get_app_decl(ctx,Z3_to_app(ctx,x));
自动y=mk_int_var(ctx,“b”);
decls[1]=Z3_get_app_decl(ctx,Z3_to_app(ctx,y));
自动z=mk_int_var(ctx,“c”);
decls[2]=Z3_get_app_decl(ctx,Z3_to_app(ctx,z));
自动thm=Z3_解析_smtlib2_字符串(ctx,
“(声明常量为整数)\n”
“(声明常量b Int)\n”
“(声明常量c Int)(断言(或(和(>(+cb)2)(<(*(*(+cb)c)(*(*(+cb)c)(*(*(+c-1)(+cb-1))(+(+cb-1)))1234567))(和(而不是(>(+cb)2))(<(*(*((*(+cb)c)(*(+(+cb)1)b))1234567)))”,
0,nullptr,nullptr,
0,符号,数字);
ast=Z3_ast_向量_get(ctx,thm,0);
Z3目标断言(ctx、g、ast);
Z3_应用_结果应用_结果1=Z3_策略应用(ctx,策略,g);
Z3_字符串Z3_字符串=Z3_应用结果_到_字符串(ctx,应用结果1);
std::cout我通常使用:

Z3_global_param_set("timeout", "1000");
在创建上下文之前

编辑:

一个可能的解决方案是使用
Z3\u策略\u应用\u ex
()


另外,我们可以使用
Z3\u-tractic\u-try\u for
直接设置超时。

我没有注意到该函数已经被调用。查看
Z3\u-tractic\u-apply
的源代码,我发现它可能没有使用该值。要使其工作,应该使用
Z3\u-tractic\u-apply\u-ex
,并在那里设置超时参数。参见re:对不起,我真的不明白你在说什么……我是否应该澄清我的代码,因为在解算器的语言中有一些重复的定义?@NunoLopes我在创建上下文之前就把它放了,但仍然不起作用。你可以使用
Z3\u策略应用
而不是
Z3\u策略应用
。另一种选择是使用
Z这与上下文创建无关。
Z3\u-tractic\u-try\u for
适合我。非常感谢!我可以编辑你的答案并接受它吗?