[英]How to evaluate a predicate in Alloy source code?
I have a predicate in my Alloy model, called LS, which gets an instance of a sig called st. 在我的Alloy模型中,我有一个谓词LS,该谓词得到了一个称为st的信号实例。 I am trying to evaluate this predicate on an instance of st, called st$0, in the source code. 我正在尝试在源代码中名为st $ 0的st实例上评估此谓词。 I can find the solution of type A4Solution, called ans. 我可以找到类型为A4Solution的解决方案,称为ans。 But I don't know how I can evaluate this predicate on this solution. 但是我不知道如何评估此解决方案的谓词。
Here is how you can in general evaluate predicates using the API 通常,这是使用API评估谓词的方式
String fileName = "<file path to your alloy model>";
Module world = CompUtil.parseEverything_fromFile(rep, null, fileName);
A4Options opt = new A4Options();
opt.solver = A4Options.SatSolver.SAT4J;
// run the first command for the sake of this example
Command cmd = world.getAllCommands().get(0);
A4Solution sol = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), cmd, opt);
// evaluate the first defined function/predicate applied to the first defined Sig
Func func = world.getAllFunc().get(0);
Sig sig = world.getAllSigs().get(0);
System.out.println(sol.eval(func.call(sig)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.