问题描述
我需要在程序中从.als生成随机的.xml实例。我设法通过在后台运行合金(不可见的JFrame)并调用doOpen,doExecuteLatest和doShowLatest函数来做到这一点。但每次运行我的代码时都要等合金开始是一件痛苦的事。我认为如果我只使用合成代码部分执行此程序(我想这将是kodkod)会更有效率。
有谁知道怎么做?我发现合金的代码非常令人困惑......
I need to generate random .xml instances from an .als in my program. I managed to do that by running alloy in background (invisible JFrame) and calling the doOpen, doExecuteLatest and doShowLatest functions. But having to wait alloy to start every time I run my code is a pain. I think it would be more efficient if I simply used the alloy code section that does this procedure (I imagine that would be kodkod).Does anyone know how to do that? I found alloy's code to be pretty confusing...
推荐答案
您可以使用Alloy API。
生成实例并将其写为XML文件可以按照以下步骤轻松完成:
You can use the Alloy API.Generating an instance and writing it as an XML file can be easily done following those steps:
-
读取合金来自其源文件的模型。
Read the alloy model from its source file.
获取执行命令。例如:
Get the command to execute. for example :
使用步骤2中获得的命令执行模型
Execute the model using the command obtained in step 2
写下在步骤3中生成的解决方案
Write the solution generated in step 3
可以在Alloy jar文件的edu.mit.csail.sdg.alloy4whole包中找到示例
Examples can be found in the edu.mit.csail.sdg.alloy4whole package of the Alloy jar file
这篇关于Alloy - 从.als生成.xml实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!