2

C-APIでZ3を使用しています。C-APIでの戦術と目標の使い方を理解しようとしています。Z3の例をチェックインしましたが、自分に合ったものが見つかりませんでした。

私は以下のように私のC-API疑似コードを持っています-

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);

今、私はいくつかの戦術をmygoalに適用したいと思います。ただし、C-APIがどの程度正確に従うべきかを知ることはできません。ドキュメントを確認しましたが、これを行う例が見つかりませんでした。

私が試したのはZ3_goal_assert ();APIを使うことです。しかし、それはどういうわけか機能しませんでした。誰かがC-APIの簡単な例を教えてもらえますか?

更新:次のCコードを試しましたが、機能しません。関数呼び出しZ3_tactic_apply()で、ソルバーは次のようなエラーをスローします-

pure virtual method called
terminate called without an active exception

コードの一部:

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);

また、戦術を簡素化するためにパラメーターを追加するもう1つのオプションを試しました。

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);

しかし、再び機能しません。

ありがとう。

4

1 に答える 1

4

Z3 4.xには、Z3 C APIをはるかに使いやすくするC++ヘッダーファイルが付属しています(file include/z3++.h)。また、C ++(ファイル)に基づく例もありますexamples/c++/example.cpp。このファイルには、戦術オブジェクトを使用した多くの例が含まれています。

そうは言っても、戦術は目標に適用されるべきです。便宜上、戦術からソルバーを作成するAPIも提供していますZ3_mk_solver_from_tactic。このAPIによって返されるソルバーオブジェクトは、指定された戦術を使用して充足可能性クエリを解決しようとします。

于 2012-09-17T17:30:39.247 に答える