I prefer to assign sample values manually to sig, for example:
sig A{}
sig B{ab: A}
pred show
{
A={(a0), (a1), (a2)}
B={(b0), (b1), (b2)}
ab={(a0, b1), (a1,b2)}
}
But, Alloy generates error message.
I do this work because I want to check this sample value in order to satisfy my facts.
I want to know that if I have wrong grammar or Alloy doesn't allow to manual assignment.
I appreciate if someone can help me regarding this problem.
There is no such "{(a0), (a1), (a2)}" syntax.
The Alloy syntax for tuple is "->", and union is "+".
So the predicate needs to be:
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = a0->b1 + a1->b2
}
But the names a0, a1, a2, b0, b1, b2 are not defined
in the model; if you always want there to be a0..a2 and b0..b2,
you need to declare them. One common way is as follows:
abstract sig A { }
one sig a0, a1, a2 extends A { }
abstract sig B { ab: A }
one sig b0, b1, b2 extends B { }
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = a0->b1 + a1->b2
}
Note that when you put the above model into Alloy,
it will warn that there is a type mismatch (since ab is declared
inside the B signature, so ab is a relation from B to A,
rather than from A to B).
Suppose we then reverse it:
abstract sig A { }
one sig a0, a1, a2 extends A { }
abstract sig B { ab: A }
one sig b0, b1, b2 extends B { }
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = b0->a1 + b1->a2
}
run show
Alloy will still say it is impossible.
That's because the way you declared "ab",
it says every B must map to exactly one A,
but the predicate above does not give a
value to b2.
abstract sig A { }
one sig a0, a1, a2 extends A { }
abstract sig B { ab: A }
one sig b0, b1, b2 extends B { }
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = b0->a1 + b1->a2 + b2->a2
}
run show
Now it finally produces an instance (in fact,
it's an exact instance).
The Alloy syntax for tuple is "->", and union is "+".
So the predicate needs to be:
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = a0->b1 + a1->b2
}
But the names a0, a1, a2, b0, b1, b2 are not defined
in the model; if you always want there to be a0..a2 and b0..b2,
you need to declare them. One common way is as follows:
abstract sig A { }
one sig a0, a1, a2 extends A { }
abstract sig B { ab: A }
one sig b0, b1, b2 extends B { }
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = a0->b1 + a1->b2
}
Note that when you put the above model into Alloy,
it will warn that there is a type mismatch (since ab is declared
inside the B signature, so ab is a relation from B to A,
rather than from A to B).
Suppose we then reverse it:
abstract sig A { }
one sig a0, a1, a2 extends A { }
abstract sig B { ab: A }
one sig b0, b1, b2 extends B { }
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = b0->a1 + b1->a2
}
run show
Alloy will still say it is impossible.
That's because the way you declared "ab",
it says every B must map to exactly one A,
but the predicate above does not give a
value to b2.
abstract sig A { }
one sig a0, a1, a2 extends A { }
abstract sig B { ab: A }
one sig b0, b1, b2 extends B { }
pred show
{
A = a0 + a1 + a2
B = b0 + b1 + b2
ab = b0->a1 + b1->a2 + b2->a2
}
run show
Now it finally produces an instance (in fact,
it's an exact instance).