[英]Use Alloy to model a simple library
在“事實F4_All_wanted_books_are_had_by_someone”中,我試圖使所有想要的書都借給某個贊助人。 如果顧客想要一本書,那一定是有書的(否則可以借給想要它的顧客)。 在“事實F7_Cannot_want_what_you_have”中,是顧客不能想要他或她已經擁有的書。 但是當我嘗試執行代碼時。 它顯示沒有找到實例,但是應該找到實例。
在添加“事實F4”之前,仍然可以找到該實例,但是在添加F4之后,無法再找到該實例。 “事實F4”有什么問題嗎? 以及如何解決。 謝謝你的幫助。
/**
* The books in a library.
*/
some sig Book{}
/**
* Patrons of the library, in general, have some books (on loan)
* and want some other books.
*/
some sig Patron {
has : set Book,
wants : set Book
}
/**
* The library has some books on reserve, some on the shelves,
* and some on hold because patrons want them (are waiting for
* them).
*
* Note: The books on loan are exactly those all the Patrons as
* a group "have".
*/
one sig Library {
onReserve : set Book,
onShelves : set Book
}
/**
* All wanted books are on loan to some patron (that is,
* some patron has the wanted book). Note that a patron
* *MAY* have a book out that nobody else wants.
*/
fact F4_All_wanted_books_are_had_by_someone {
all b : Patron | b.wants in b.has
}
/**
* Two different patrons cannot have the same book.
*/
fact F5_No_loan_conflicts {
all disj b1, b2 : Patron | no (b1.has & b2.has)
}
/**
* A patron cannot want a book he or she already has.
*/
fact F7_Cannot_want_what_you_have {
all b : Patron | no (b.wants & b.has)
}
run{
some onReserve
some onShelves - onReserve
some wants
some has
some Patron.has - Patron.wants
some Patron.has & Patron.wants
some has.Book & wants.Book
} for exactly 3 Patron, exactly 8 Book
F4的意思是“對於所有顧客來說,他想要的每本書都是他擁有的書之一”。 我建議
fact F4 {
all p:Patron | p.wants in (Patron - p).has
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.