Z3JAVA,关于Z3 for Java的性能问题

I am running into some performance issues in my current project with Z3 for Java:

Basically most of my current constraints are pretty simple:

e.g: (f(x) = 2 && f(y) <= 3) || f(x) <=5

I am using static context and solver instances shared by the whole project:

public class ConstraintManager {

static Context ctx;

static Solver solver;

...

}

If I generate expr by the same instance of ctx for billions of times, is that going to an issue? When is the best time to invoke ctx.Dispose(), or, what's the best way to manage ctx?

I invoked expr.Simplify() to simplify some constraints like: f(x)=3 && f(x)<=2.

But this API turned out to be very slow. Especially the length of constraint increased. Is this a known issue or is that because I used it incorrectly?

I am using expr.substitute(expr1, expr2), but I notice that z3 will turn the expr into a let-binding form after substitution. Is this for making the formula more compact?

解决方案

Simplify performs simple algebraic simplifications. You can control its behavior in some cases. For example * distributes over +, but this can cause real overhead and one can turn off simplifications of this kind. Use z3 -pm:simplify from the command-line to inspect parameters. (on the other hand, Z3 will unlikely be able to solve the formulas where this simplification is too expensive).

The "let-bindings" are supplied by the printer. Internally, terms are represented as directed acyclic graphs where nodes are shared. Printing a DAG as a tree can be extremely expensive (exponential in the worst case). So the printer introduces let expressions when it determines that this gives a shorter print-length.

The .NET and Java APIs use the garbage collector to manage lifetimes of terms. They get recycled at the discretion of the GC. For top performance you can manage reference counts on your own, but then you have to bypass the supported API. The released source code contains the JNI/pinvoke relevant to do this. Note that rolling your own low level API is a lot of work and the low level reference counting is also not as easy to program with as the supported API.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值