问题
suppose I have the following model :
sig counter{
value: Int,
}
{
value > 0
value < 3
}
pred show{}
run show for exactly 1 counter
I would like to generate the als files corresponding to the two instances of this model :
open counter
one sig counter_1 extends counter{}{ value=1 }
fact { counter = {counter_1}}
and,
open counter
one sig counter_2 extends counter{}{ value=2 }
fact { counter = {counter_2}}
I have used the Alloy API to generate the instances but I cant find the method to export them to als files (unless parsing xml or txt files).
I can imagine there exist such a method especial for people who do model transformation (which is my case since I want to transform the instances back to the original méta model)
Any hints? Thanks
回答1:
I do not think there is a way to do this easily. There is a pkriens/api branch that provides and API that would make it easier to export this since you can get the solution as easy to use API objects.
回答2:
It seems that you already have .als files that match your description; they are given in the second and third code blocks of your question.
What am I missing? (Or, not quite the same thing, what requirements are missing from your question?)
回答3:
We had the same needs when developing Lightning, we called that "instance promotion".
To implement instance promotion, we developed an algorithm that consisted in going through the A4Solution generated (see going through an A4Solution) and generating for each element some Alloy code that would then be persisted into an .als file.
I will try to put the source code of the tool online. Worst case, you'll have to redo it from scratch, it won't be too hard I believe.
回答4:
go to this place in your computer
C:\Users\'the name of user'\Desktop\alloy4.2\models\util
, you will find there are a lot of .als files that are saved here. next step save your file there.
but... try to save the counter in the same folder that you will create the second one. I had solved all the examples that you attached here.
> module Counter
>
> sig counter{ value: Int, } { value > 0 value < 3 } pred show{}
>
> run show for exactly 1 counter
this is your first example:
module test
open counter
one sig counter_1 extends counter{}{ value=1
} fact { counter = {counter_1}}
and this is your second example:
module test2
open counter
one sig counter_2 extends counter{}{ value=2 }
fact { counter = {counter_2}}
来源:https://stackoverflow.com/questions/59466605/generating-als-files-corresponding-to-model-instances-with-alloy-api