有人可以帮我在Z3中使用C#Api。我不知道该怎么做: - (
我在Visual C#2010 Express中编写了后续程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Z3;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (Config cfg = new Config()) {
using (Context ctx = new Context(cfg)) {
Term x = ctx.MkConst("x", ctx.MkIntSort());
Term y = ctx.MkConst("y", ctx.MkIntSort());
Term zero = ctx.MkConst(0, ctx.MkIntSort());
Term one = ctx.MkConst(1, ctx.MkIntSort());
Term three = ctx.MkConst(3, ctx.MkIntSort());
Term fml = x > zero & ctx.MkEq(y, x + one) & y < three;
ctx.AssertCnstr(fml);
Model m = null;
LBool is_sat = ctx.CheckAndModel(out m);
System.Console.WriteLine(is_sat);
if (m != null)
{
m.Display(Console.Out);
m.Dispose();
}
}
}
}
}
}
发生以下错误:
谢谢
答案 0 :(得分:2)
要在C#项目中使用Microsoft Z3库,请执行以下步骤:
转到http://research.microsoft.com/en-us/downloads/0a7db466-c2d7-4c51-8246-07e25900c7e7/ 并下载+安装Z3包。
切换到Visual Studio。在Solution Explorer窗口中
右键单击References树节点,然后选择“Add Reference”
在“添加新引用”对话框中,导航到Microsoft.Z3.dll。你找到了
在c:\Program Files (x86)\Microsoft Research\Z3-3.2\bin
下的Microsoft.Z3.dll
Windows x64位计算机或c:\Program Files\Microsoft Research\Z3-3.2\bin
下
在Windows x86计算机上。要使用Parallel Z3库,请从中选择Microsoft.Z3.dll
c:\Program Files (x86)\Microsoft Research\Z3-3.2\bin_mt
或
c:\Program Files\Microsoft Research\Z3-3.2\bin_mt
目录。
关于您的代码的一些注释:
CheckAndModel()
类上没有名为Context
的方法。
只有一种名为CheckAndGetModel()
的方法。
此外,表单的MkConst()
没有重载
ctx.MkConst(1, ctx.MkIntSort());
而是使用以下重载:
ctx.MkConst("1", ctx.MkIntSort());
答案 1 :(得分:1)
请注意:
ctx.MkConst("1", ctx.MkIntSort());
不是数字1,而是一个未解释的常量,其名称为“1”。
如果您想要数字,请使用:
ctx.MkNumeral(1, ctx.MkIntSort());