Alloy Community

User login

How does I assign sample values manually to sig?

 
Posted on: Sat, 07/18/2009 - 04:52
Joined: 2008-10-27
Points: 13
User is offline
How does I assign sample values manually to sig?
Hello

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.
 
Posted on: Sat, 07/18/2009 - 10:03    #1
Joined: 2008-05-15
Points: 334
User is offline
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).
 
Posted on: Sun, 07/19/2009 - 00:43    #2
Joined: 2008-10-27
Points: 13
User is offline
Thanks a lot for your help

Syndicate content  

The development of this site is supported by the National Science Foundation under Computing Research Infrastructure Grant No. 0707612.

Theme originally designed by Chris Herberte