紧凑显示java,Alloy:一个紧凑的Java程序,用于执行不同的运行命令范围

假设我想创建一个Java程序来执行几个Alloy运行,为每个循环更改它们的范围值(从0到9的整数),以检查哪个将花费更少的时间用于解决方案 .

请注意,命令实际上是相同的,我的意思是,只有范围的值(以及保留字“完全”的存在/不存在)会有所不同 .

这是一个数字示例:

1st run → command: run MyPred for 3 but 5 Int, exactly 1 Sig_Scope1, 1 Sig_Scope2, exactly 1 Sig_Scope3

2nd run → command: run MyPred for 4 but 5 Int, 2 Sig_Scope1, exactly 2 Sig_Scope2, exactly 2 Sig_Scope3

3rd run → command: run MyPred for 4 but 5 Int, 2 Sig_Scope1, exactly 1 Sig_Scope2, 1 Sig_Scope3

依此类推,直到达到最大迭代次数(假设为10) .

10th run → command: run MyPred for 4 but 5 Int, 0 Sig_Scope1, exactly 2 Sig_Scope2, 0 Sig_Scope3

程序输出将是这样的:

1st run. Found solution: Yes. Spent time: 17 seconds

2nd run. Found solution: No. Spent time: [it may take a time until the Alloy analyzer is going to return no solution]

3nd run. Found solution: No. Spent time: [it may take a time until the Alloy analyzer is going to return no solution]

...

9th run. Found solution: Yes. Spent time: 21 seconds

10th run. Found solution: Yes. Spent time: 10 seconds

这里是我试图通过的伪代码,但有很多部分(文本问题)我不知道如何实现它或如何找到更多的学习材料:

...

A4Reporter rep = new A4Reporter() {...}

...

Module world = CompUtil.parseEverything_fromFile(rep, null, filename); //reading Alloy filename.

...

A4Options options = new A4Options(); //Analyzer’s options.

...

Command command: world.getAllCommands(); //I’am looking for Alloy’s ‘run’ commands, for instance, the first run command would be: run MyPred for 3 but 3 Int, exactly 1 Sig_Scope1, 1 Sig_Scope2, exactly 1 Sig_Scope3

...

Int max_number_of_runs = 10;

for(i = 0; i < max_number_of_runs; i++) {

A4Solution ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command, options); //get all Signatures, fine :)

System.out.println(ans); //printing the whole command.

if (ans.satisfiable()) {

//How can I get the amount of time (in seconds) to found a solution as an integer or String?

//Getting the label of the Sigs. I have got this way, however I do not know if it is the right one.

SafeList sigs = ans.getAllReachableSigs();

for (Sig sig : sigs) {

System.out.println(sig.shortLabel());

}

//For each Sig how can I get their values?

//How can I build a new command (Command new_built_command) for the next run? The values of scope Sig will come from a list or they will be generated through Java Random class (I mean a know how to generate random integers).

command = new_built_command;

} else {

//A message that the current command did not find a solution as a String!

}

}

你能帮我解决一下吗?

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值