Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have an object in one set or another, but not both?

Tags:

alloy

This is homework and I'm having a lot of trouble with it. I am using Alloy to model a library. Here are the definitions of the objects:

sig Library {
    patrons : set Person,
    on_shelves : set Book,
}

sig Book {
    authors : set Person,
    loaned_to : set Person,
}

sig Person{}

Then we need to have to have a fact that states, every book is either on the shelf, or taken out by a patron. However, they cannot be in both places.

// Every book must either be loaned to a patron or
// on the shelves.
fact AllBooksLoanedOrOnShelves {}

I have tried this...

fact AllBooksLoanedOrOnShelves {
    some b : Book {
        one b.loaned_to =>
            no (b & Library.on_shelves)
        else
            b in Library.on_shelves
    }
}

But it's not working... the books always are on the shelves. want to say, "For every book, if it is not being loaned, it is on the shelf. Otherwise, it's out."

Corrections, examples, and hints are greatly appreciated.

like image 291
Ethan Mick Avatar asked Sep 17 '11 00:09

Ethan Mick


People also ask

What does a ∩ B mean?

The set A ∩ B—read “A intersection B” or “the intersection of A and B”—is defined as the set composed of all elements that belong to both A and B. Thus, the intersection of the two committees in the foregoing example is the set consisting of Blanshard and Hixon.

What do you call to the two sets which no common elements?

Two sets are called disjoint if they have no elements in common. For example: The sets S = { 2, 4, 6, 8 } and T = { 1, 3, 5, 7 } are disjoint.

What is disjoint set?

A pair of sets which does not have any common element are called disjoint sets. For example, set A={2,3} and set B={4,5} are disjoint sets.

What do you call the objects or things in a set?

The objects are called the elements of the set. If a set has finitely many elements, it is a finite set, otherwise it is an infinite set. If the number of elements in a set is not too many, we can just list them out.


2 Answers

If every book must be either on loan to someone or on the shelves, then (a) no book will be both on loan and on the shelves (assuming you mean that "or" as exclusive), so the intersection of the onloan set and the onshelf set will be empty, and (b) the set of books will be equal to the union of the onloan and onshelf sets.

The set of books on loan at any time is the domain of the loaned_to relation. The set of books on the shelf in a given library L is the value of L.onshelves; the set of books on the shelves in all known libraries is Library.onshelves.

So you might say

fact in_or_out_not_both {
  no Library.onshelves & loaned_to.Person 
}
fact all_books_in_or_out {
  Book = Library.onshelves + loaned_to.Person
}

Or you might need to say slightly different things, depending on just what you mean. Note that these constraints don't say that a book on loan must be on loan to a single borrower.

like image 55
C. M. Sperberg-McQueen Avatar answered Nov 12 '22 18:11

C. M. Sperberg-McQueen


Your fact is wrong. You want to say something for all books (not "some"). And that something is basically an XOR.

Here's one that works:

fact AllBooksLoanedOrOnShelves{
  all b : Book|
    (b in Library.on_shelves and no p:Person | p in b.loaned_to)
    or
    (not b in Library.on_shelves and one p:Person | p in b.loaned_to)
}
like image 22
Michalis Famelis Avatar answered Nov 12 '22 17:11

Michalis Famelis