简体   繁体   English

使用Alloy建模简单的库

[英]Use Alloy to model a simple library

In "fact F4_All_wanted_books_are_had_by_someone", I am trying to make all wanted books are on loan to some patron. 在“事实F4_All_wanted_books_are_had_by_someone”中,我试图使所有想要的书都借给某个赞助人。 Which is if a patron wants a book, it must be on load (otherwise it could be loaned to the patron that wants it). 如果顾客想要一本书,那一定是有书的(否则可以借给想要它的顾客)。 In "fact F7_Cannot_want_what_you_have", is a patron cannot want a book he or she already has. 在“事实F7_Cannot_want_what_you_have”中,是顾客不能想要他或她已经拥有的书。 But when I tried to execute the code. 但是当我尝试执行代码时。 it shows that there is no instance found, however, it supposed have instance found. 它显示没有找到实例,但是应该找到实例。

Before I add "fact F4" the instance still can found, but after I added F4, the instance cannot be found any more. 在添加“事实F4”之前,仍然可以找到该实例,但是在添加F4之后,无法再找到该实例。 Is there are anything wrong in "fact F4"? “事实F4”有什么问题吗? and how can I fix it. 以及如何解决。 thanks for your help. 谢谢你的帮助。

/**
 * 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

The meaning of your F4 is "for all patrons every book he wants is among those he has". F4的意思是“对于所有顾客来说,他想要的每本书都是他拥有的书之一”。 I suggest 我建议

fact F4 {
    all p:Patron | p.wants in (Patron - p).has
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM