Alloy Community

User login

Which is the best solution?

 
Posted on: Thu, 06/25/2009 - 08:09
bernardofbbraga's picture
Joined: 2008-09-04
Points: 104
User is offline
Which is the best solution?
Suppose a scenario where there are Cats and they can be Male or Female, Black or White. They form two disjoint complete partitions of Cat. To represent this scenario I've come up with three diferent solutions, and would like some advice on which is the best, regarding computer effort
I'm concerned if the use of the universal quantifier is so bad it's worse than declaring 4 other functions. Consider also if there were more classes involved.. There would be more intersecting subclasses...

Solution 1:
sig Cat{}
sig Male in Cat{}
sig Female in Cat{}
sig Black in Cat{}
sig White in Cat{}
fact generalization_sets
{
   all c:Cat | (c in Male || c in Female) and (c in Black || c in White)
}

Solution 2:
sig Cat{}
sig Male in Cat{}
sig Female in Cat{}
sig Black in Cat{}
sig White in Cat{}
fact generalization_sets
{
   disj[Male,Female]
   disj[Black,White]
   all c:Cat | (c in Male + Female) and (c in Black + White)
}

Solution 3:
sig Cat{}
sig Black_Male extends Cat{}
sig Black_Female extends Cat{}
sig White_Male extends Cat{}
sig White_Female extends Cat{}
//use functions to refer to each separate subclass
fun Black:Cat{Black_Male+Black_Female}
fun White:Cat{White_Male+White_Female}
fun Male:Cat{Black_Male+White_Male}
fun Female:Cat{Black_Female+White_Female}
 
Posted on: Thu, 06/25/2009 - 09:47    #1
Joined: 2008-07-16
Points: 23
User is offline
I am afraid I can't help you with which is best in terms of computer effort, just a couple of minor comments. a) Your first solution allows a cat to be both male and female. b) Since your subsets completely partition the Cats set, you might want to declare Cat as an abstract sig.

A variant of your 2nd solution without quantification could be the following, but again I don't know how well it scales in terms of its computer effort:


abstract sig Cat{}

sig Male extends Cat{}
sig Female extends Cat{}

sig White in Cat{}
sig Black in Cat{}

fact {
White+Black = Male+Female
disj[Black,White]
}
 
Posted on: Fri, 06/26/2009 - 09:29    #2
bernardofbbraga's picture
Joined: 2008-09-04
Points: 104
User is offline
D'oh
yeah, that's what I get... I had the disj[Male,Female] and disj[Black,White] in the first solution but while writing this post I thought it was unnecessary.. Newb mistake to think or is xor. Correcting first solution:

Solution 1:
sig Cat{}
sig Male in Cat{}
sig Female in Cat{}
sig Black in Cat{}
sig White in Cat{}
fact generalization_sets
{
disj[Male,Female]
disj[Black,White]
all c:Cat | (c in Male || c in Female) and (c in Black || c in White)
}

I like your solution, I'll name it solution 4
here's solution 5 which also corrects solution1

Solution 5:
sig Cat{}
sig Male in Cat{}
sig Female in Cat{}
sig Black in Cat{}
sig White in Cat{}
fact generalization_sets
{
all c:Cat | (c in Male <=> c not in Female) and (c in Black <=> c not in White)
}
-----
Bernardo F. B. Braga
Undergraduate bachelor student at Universidade Federal do Espirito Santo (UFES)
Member of the Ontology and Conceptual Modelling Research Group (NEMO)
 
Posted on: Mon, 06/29/2009 - 02:53    #3
Joined: 2008-06-06
Points: 93
User is offline
sig Cat{}

sig Male in Cat{}
fun Female: set Cat{Cat-Male}
sig White in Cat{}
fun Black: set Cat{Cat-White}

This solution is ugly in that it is not symmetric.

A different approach which is symmetric:

enum Sex{Male, Female}
enum Colour{Black, White}
sig Cat{sex : Sex, colour : Colour}

fun Males : set Cat{sex.Male}
etc.
--
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

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