C Z3使用目标和战术
我将Z3与C-API一起使用。我试图理解如何使用C-API中的战术和目标。我查看了Z3的示例,但没有找到适合我的 我的C-API psuedo代码如下-C Z3使用目标和战术,c,z3,C,Z3,我将Z3与C-API一起使用。我试图理解如何使用C-API中的战术和目标。我查看了Z3的示例,但没有找到适合我的 我的C-API psuedo代码如下- contextId = mk_context(); solverId = Z3_mk_solver(contextId); Z3_solver_inc_ref(contextId, solverId); ... then some assertions like x > 0, y > 0 and so on.. ... // no
contextId = mk_context();
solverId = Z3_mk_solver(contextId);
Z3_solver_inc_ref(contextId, solverId);
...
then some assertions like x > 0, y > 0 and so on..
...
// now comes the final goal
mygoal = Z3_mk_less_than(contextId, ...) // x < 50
Z3_solver_assert (contextId, solverId, mygoal)
...
// finally check
Z3_solver_check(contextId, solverId)
Z3_reset_memory();
Z3_del_context(contextId);
Z3_solver_dec_ref(contextId, solverId);
一段代码:
goalId = Z3_mk_goal();
Z3_goal_inc_ref(context, goalId);
assertionVector = Z3_solver_get_assertions (context, solver);
int vectorSize = Z3_ast_vector_size(assertionVector);
for(int i=0;i<vectorSize;i++)
Z3_goal_assert(context, goalId, Z3_ast_vector_get(context, assertionVector, i));
Z3_goal_assert(context, goalId, Z3_mk_eq(context, totalProcDecl, Z3_mk_int(context, numProcessors, int_sort)));
Z3_goal_assert(context, goalId, Z3_mk_eq(contextlatencyDecl, Z3_mk_int(context, latencyConstraint, int_sort)));
// This is what I am trying to apply
// (check-sat-using (then (! simplify :arith-lhs true) solve-eqs lia2pb pb2bv bit-blast sat))
tactic0 = Z3_mk_tactic (context, "simplify");
Z3_tactic_inc_ref (context,tactic0);
tactic1 = Z3_mk_tactic (context, "solve-eqs");
Z3_tactic_inc_ref (context, tactic1);
tactic2 = Z3_mk_tactic (context, "lia2pb");
Z3_tactic_inc_ref (context, tactic2);
tactic3 = Z3_mk_tactic (context, "pb2bv");
Z3_tactic_inc_ref (context, tactic3);
tactic4 = Z3_mk_tactic (context, "bit-blast");
Z3_tactic_inc_ref (context, tactic4);
tactic5 = Z3_mk_tactic (context, "sat");
Z3_tactic_inc_ref (context, tactic5);
temp = Z3_tactic_and_then (context, tactic0, tactic1);
temp = Z3_tactic_and_then (context, temp, tactic2);
temp = Z3_tactic_and_then (context, temp, tactic3);
temp = Z3_tactic_and_then (context, temp, tactic4);
temp = Z3_tactic_and_then (context, temp, tactic5);
result = Z3_tactic_apply (context, temp, goalId);
printf("Result : %s\n", Z3_apply_result_to_string (context, result));
// Finished Solving.
Z3_goal_dec_ref (context, goalId);
Z3_tactic_dec_ref (context, tactic0);
Z3_tactic_dec_ref (context, tactic1);
Z3_tactic_dec_ref (context, tactic2);
Z3_tactic_dec_ref (context, tactic3);
Z3_tactic_dec_ref (context, tactic4);
Z3_tactic_dec_ref (context, tactic5);
但这同样不起作用
谢谢。
Z3 4。X附带了C++头文件,使Z3C API更容易使用(文件<代码>包含/Z3++.H/COM>)。 它还具有基于C++的文件实例(文件<代码>实例/ C++ +示例。CPP < /代码>)。该文件包含许多使用战术对象的示例
也就是说,战术应该应用于进球。为了方便起见,我们还提供了一个API,它可以从策略
Z3\u mk\u solver\u from\u tractic
创建一个解算器。此API返回的解算器对象将尝试使用给定策略解决可满足性查询>P3 4 .x附带C++头文件,使Z3C API更容易使用(文件<代码>包含/Z3++ .H</代码>)。
它还具有基于C++的文件实例(文件<代码>实例/ C++ +示例。CPP < /代码>)。该文件包含许多使用战术对象的示例
也就是说,战术应该应用于进球。为了方便起见,我们还提供了一个API,它可以从策略
Z3\u mk\u solver\u from\u tractic
创建一个解算器。此API返回的解算器对象将尝试使用给定策略解决可满足性查询 是的,我们可以将解算器
对象中的断言转换为目标
对象。下面是一个如何执行的示例:在我们将其转换为目标
对象后,我们可以使用策略来解决它。您问题中的代码缺少几个Z3_*\u inc\u ref
调用。原则上,您必须为Z3返回的每个对象调用这种API。您得到的错误是由于内存访问冲突造成的。我强烈建议您在examples/c++/example.cpp
中的示例也非常有用,并说明了如何使用此包装器。另一个选项是.Net或PythonZ3API。如果你使用java中的Z3,那么使用C++ API将没有多大帮助。我认为手动管理参考计数器很困难。是否可以使用类似于用于Z3的Python包装器API中使用的方法。python包装器API的源代码包含在Z3发行版(目录python
)中。关于Z3\u apply\u result
to\u string
API,它返回一个以(目标
。然后,它包括每个子目标的字符串表示。如果一个目标无法满足,那么它将被打印为false
。关于使用
检查sat,您可以使用APIZ3_mk_solver\u from_tractic
将策略转换为Z3_solver
对象。这就是使用
检查sat是的,我们可以将解算器
对象中的断言转换为目标
对象。下面是一个如何执行的示例:在我们将其转换为目标
对象后,我们可以使用策略来解决它。您问题中的代码缺少几个Z3*inc\u ref
调用。原则上,您必须调用对于Z3返回的每个对象都是API。您的错误是由于内存访问违规。我强烈建议您使用“C++”中的C++包装对象,包括/Z3++.H./C>。它们将自动管理您的引用计数器。在python
)中。关于Z3\u应用\u结果
到\u字符串
API,它返回一个以(目标
。然后,它包括每个子目标的字符串表示。如果一个目标无法满足,那么它将被打印为false
。关于使用
检查sat,您可以使用APIZ3_mk_solver\u from_tractic
将策略转换为Z3_solver
对象。这就是使用
检查sat实现了。
goalId = Z3_mk_goal();
Z3_goal_inc_ref(context, goalId);
assertionVector = Z3_solver_get_assertions (context, solver);
int vectorSize = Z3_ast_vector_size(assertionVector);
for(int i=0;i<vectorSize;i++)
Z3_goal_assert(context, goalId, Z3_ast_vector_get(context, assertionVector, i));
Z3_goal_assert(context, goalId, Z3_mk_eq(context, totalProcDecl, Z3_mk_int(context, numProcessors, int_sort)));
Z3_goal_assert(context, goalId, Z3_mk_eq(contextlatencyDecl, Z3_mk_int(context, latencyConstraint, int_sort)));
// This is what I am trying to apply
// (check-sat-using (then (! simplify :arith-lhs true) solve-eqs lia2pb pb2bv bit-blast sat))
tactic0 = Z3_mk_tactic (context, "simplify");
Z3_tactic_inc_ref (context,tactic0);
tactic1 = Z3_mk_tactic (context, "solve-eqs");
Z3_tactic_inc_ref (context, tactic1);
tactic2 = Z3_mk_tactic (context, "lia2pb");
Z3_tactic_inc_ref (context, tactic2);
tactic3 = Z3_mk_tactic (context, "pb2bv");
Z3_tactic_inc_ref (context, tactic3);
tactic4 = Z3_mk_tactic (context, "bit-blast");
Z3_tactic_inc_ref (context, tactic4);
tactic5 = Z3_mk_tactic (context, "sat");
Z3_tactic_inc_ref (context, tactic5);
temp = Z3_tactic_and_then (context, tactic0, tactic1);
temp = Z3_tactic_and_then (context, temp, tactic2);
temp = Z3_tactic_and_then (context, temp, tactic3);
temp = Z3_tactic_and_then (context, temp, tactic4);
temp = Z3_tactic_and_then (context, temp, tactic5);
result = Z3_tactic_apply (context, temp, goalId);
printf("Result : %s\n", Z3_apply_result_to_string (context, result));
// Finished Solving.
Z3_goal_dec_ref (context, goalId);
Z3_tactic_dec_ref (context, tactic0);
Z3_tactic_dec_ref (context, tactic1);
Z3_tactic_dec_ref (context, tactic2);
Z3_tactic_dec_ref (context, tactic3);
Z3_tactic_dec_ref (context, tactic4);
Z3_tactic_dec_ref (context, tactic5);
tactic0_without_param = Z3_mk_tactic (context, "simplify");
Z3_tactic_inc_ref (context,tactic0_without_param);
paramsId = Z3_mk_params(context);
Z3_params_inc_ref(context, paramsId);
Z3_params_set_bool (context, p, paramsId, Z3_mk_string_symbol(context, ":arith-lhs"), true);
tactic0 = Z3_tactic_using_params (context, tactic0, paramsId);