Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Z3和c获取Unsat核心示例#_C#_Z3_Sat Solvers - Fatal编程技术网

C# 使用Z3和c获取Unsat核心示例#

C# 使用Z3和c获取Unsat核心示例#,c#,z3,sat-solvers,C#,Z3,Sat Solvers,我试图在C#实现中使用Z3 sat解算器。此代码非常接近Microsoft本身在“”中给出的示例。我的代码是: using (Context ctx = new Context(new Dictionary<string, string>() { { "proof", "true" } })) { ... Expr x = ctx.MkConst("x", ctx.MkIntSort()); Expr y = ctx.MkConst("y", ctx.MkIntSort()); Ex

我试图在C#实现中使用Z3 sat解算器。此代码非常接近Microsoft本身在“”中给出的示例。我的代码是:

using (Context ctx = new Context(new Dictionary<string, string>() { { "proof", "true" } }))
{
...
Expr x = ctx.MkConst("x", ctx.MkIntSort());
Expr y = ctx.MkConst("y", ctx.MkIntSort());
Expr zero = ctx.MkNumeral(0, ctx.MkIntSort());
Expr one = ctx.MkNumeral(1, ctx.MkIntSort());
Expr five = ctx.MkNumeral(5, ctx.MkIntSort());

Solver s = ctx.MkSolver();

s.Assert(ctx.MkGt((ArithExpr)x, (ArithExpr)zero)); // x > 0
s.Assert(ctx.MkLt((ArithExpr)y, (ArithExpr)five)); // y < 5
s.Assert(ctx.MkLt((ArithExpr)x, (ArithExpr)zero)); // x < 0
s.Assert(ctx.MkEq((ArithExpr)y, ctx.MkAdd((ArithExpr)x, (ArithExpr)one))); // y = x + 1

 Status result = s.Check();

 if (result == Status.UNSATISFIABLE)
 {
     Console.WriteLine("unsat");
     Console.WriteLine("proof: {0}", s.Proof);
     Console.WriteLine("core: ");
     foreach (Expr c in s.UnsatCore)
     {
         Console.WriteLine("{0}", c);
     }
 }

我希望UnsatCore返回“constraint1,constraint3”。有人能帮我解释一下我做错了什么吗?

在创建ctx时是否启用了证明生成(Solver.UnsatCore的文档说明,如果禁用,则结果为空)?您需要将字典(“proof->”true”)传递给上下文的构造函数才能执行此操作。

请添加您得到的输出和期望的输出。我希望返回第一个和最后一个约束。我还这样编写:BoolExpr constraint1=ctx.MkBoolConst(“constraint1”);s.AssertAndTrack(ctx.MkGt((ArithExpr)x,(ArithExpr)zero),constraint1);BoolExpr constraint2=ctx.MkBoolConst(“constraint2”);s.AssertAndTrack(ctx.MkLt((ArithExpr)y,(ArithExpr)five,constraint2);BoolExpr constraint3=ctx.MkBoolConst(“constraint3”);s.AssertAndTrack(ctx.MkLt((ArithExpr)x,(ArithExpr)zero),constraint3);BoolExpr=ctx.MkBoolConst(“constraint4”);s.AssertAndTrack(ctx.MkEq((ArithExpr)y,ctx.MkAdd((ArithExpr)x,(ArithExpr)one)),constraint4);但s.UnsatCore仍然是空的。请不要使用注释来提供有关以下问题的有用信息:编辑您的帖子。我也查看了这一点,但在Microsoft自身提供的示例代码中,这并没有完成。是的,在示例中完成了。请注意,UnsatCoreAndProofExample收到的ctx具有“证据”“在示例的第2155行,选项设置为true。我已经更新了我的原始代码,正如Christoph所说,我实际上也在设置UnsatCore选项。但UnsatCore仍然是空的。
BoolExpr constraint1 = ctx.MkBoolConst("Constraint1");
s.AssertAndTrack(ctx.MkGt((ArithExpr)x, (ArithExpr)zero), constraint1);
BoolExpr constraint2 = ctx.MkBoolConst("Constraint2");
s.AssertAndTrack(ctx.MkLt((ArithExpr)y, (ArithExpr)five), constraint2);
BoolExpr constraint3 = ctx.MkBoolConst("Constraint3");
s.AssertAndTrack(ctx.MkLt((ArithExpr)x, (ArithExpr)zero), constraint3);
BoolExpr constraint4 = ctx.MkBoolConst("Constraint4");
s.AssertAndTrack(ctx.MkEq((ArithExpr)y, ctx.MkAdd((ArithExpr)x, (ArithExpr)one)), constraint4);