Alloy Community

User login

How can I specify the multiset and tuple in alloy?

 
Posted on: Sat, 10/10/2009 - 01:08
Joined: 2008-10-27
Points: 13
User is offline
How can I specify the multiset and tuple in alloy?
Hello

In defining sig, the set relation can be specified as follows:

sig B
sig A
{
  r: set B
}

I want to model my project which is in the base of multiset (a set can have repeated member such as {1,1,2,2,2}) and tuple (an ordered set such as (1,2) which differ with (2,1)).
How can I specify the multiset and tuple in alloy?

Thanks
Ali Hosseini
 
Posted on: Sun, 10/11/2009 - 04:38    #1
Joined: 2008-06-06
Points: 93
User is offline
sig Element{}
sig Bag{ // multiset, absence treated as zero occurences
  content : Element ->one Nat
}

sig Pair{
  first, second : Element
}

Jeremy L. Jacob        Tel: +44-1904-43-2747    Fax: +44-1904-43-2767
Jeremy.Jacob@cs.york.ac.uk    http://www-users.cs.york.ac.uk/~jeremy/
Dept. of Computer Science, The University of York, YORK, YO10 5DD, UK
 
Posted on: Sun, 10/11/2009 - 22:35    #2
Joined: 2008-10-27
Points: 13
User is offline
Thank you for your answer.

In your way, cardinality (number of member) of tuple is constant. But I need the tuple with variable cardinality. It may be 2-tuple in first time and after a while is 4-tuple.
Please, help me again.
Thanks a lot.
 
Posted on: Mon, 10/12/2009 - 02:59    #3
Joined: 2008-06-06
Points: 93
User is offline
That is what the seq constructor is for:

sig A{
  field : seq B
}
sig B{}

Jeremy L. Jacob        Tel: +44-1904-43-2747    Fax: +44-1904-43-2767
Jeremy.Jacob@cs.york.ac.uk    http://www-users.cs.york.ac.uk/~jeremy/
Dept. of Computer Science, The University of York, YORK, YO10 5DD, UK
 
Posted on: Mon, 10/12/2009 - 12:53    #4
Joined: 2008-05-15
Points: 334
User is offline
Another possibility (with different scope and scalability behaviors)
might be to explicitly list out the different arities:

abstract sig Tuple { }

sig Pair extends Tuple { a, b: X }
sig Tripple extends Tuple { a, b, c: X }
sig Quad extends Tuple { a, b, c, d: X }

sig Something { someField: set Tuple }

(My example lists up to arity 4.  I omit arity 5 and above,
because with the other approach, Alloy Analyzer typically
won't perform well with arity 5 or above anyway...)
 
Posted on: Tue, 10/13/2009 - 02:44    #5
Joined: 2008-10-27
Points: 13
User is offline
seq constructor solves my problem.

I thought all things about alloy can be found in tutorial slide in address:
http://alloy.mit.edu/alloy4/tutorial/

But, there is not any things about seq in tutorial slide. Although I found it in what's new section:
http://alloy.mit.edu/alloy4/kb/seq.html

I suggest seq and another features which probably is not in tutorial slide, should be added to it.

Thanks a lot.

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