Z3 C-API for solver timeout

被刻印的时光 ゝ 提交于 2019-12-11 03:08:30

问题


I am using Z3 4.1 C-API on linux. I want to specify a timeout for a solver.

I am using following commands, however I get a segmentation fault in the command Z3_solver_set_params().

Z3_context ctx = mk_context();     
    Z3_solver s = Z3_mk_solver(ctx);     

    Z3_params params = Z3_mk_params(ctx);     
    Z3_symbol r = Z3_mk_string_symbol(ctx, ":timeout");     

    Z3_params_set_uint(ctx, params, r, static_cast<unsigned>(10));     
    Z3_solver_set_params(ctx, s, params);     

It seems that I am not using APIs correctly.
I couldn't find any example for C-APIs to set a solver timeout in test_capi.c file containing examples. Can anyone help?


回答1:


You need to increment reference counts on the solver and parameters before doing anything else. Here is a snippet that will go through.

Z3_config cfg = Z3_mk_config();
Z3_context ctx = Z3_mk_context(cfg);     
Z3_solver s = Z3_mk_solver(ctx);   
Z3_solver_inc_ref(ctx, s); 
{

Z3_params params = Z3_mk_params(ctx);  
Z3_params_inc_ref(ctx, params);
{
Z3_symbol r = Z3_mk_string_symbol(ctx, ":timeout");    


Z3_params_set_uint(ctx, params, r, 10);
Z3_solver_set_params(ctx, s, params);  
Z3_params_dec_ref(ctx, params);
}
}
Z3_solver_dec_ref(ctx, s);
Z3_del_config(cfg);
Z3_del_context(ctx);


来源:https://stackoverflow.com/questions/12199929/z3-c-api-for-solver-timeout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!