module cafeMap
-- Hipsters spend their days traveling from one cafe to another.
-- They use various means of transportation: by car, by bus, and by foot.
sig Cafe {
walk: set Cafe, -- there is a walking path between cafes
car: set Cafe, -- there is a street between cafes
bus: set Cafe -- there is a direct bus route between cafes
}
-- All Cafe pairs with a direct travel link (walk, car or bus)
fun travel[]: Cafe->Cafe {
car+walk+bus
}
-- All Cafe pairs with direct "green" travel links (walk or bus)
fun greentravel[]: Cafe->Cafe {
walk+bus
}
-- Does relation r contain every possible pair of Cafes?
pred complete[r: Cafe->Cafe] {
--your code goes here
}
-- For every pair (c,d) in r, is the reverse pair (d,c) also in r?
pred symmetric[r: Cafe->Cafe] {
r=~r
}
-- Does r contain no pairs of the form (c,c)?
pred irreflexive[r: Cafe->Cafe] {
no r & iden -- Is the intersection of r and the identity relation empty?
}
fact {
irreflexive[walk+car+bus] -- eliminate "self loops"
}
fact {
symmetric[walk]
}
pred show {}
run show for exactly 5 Cafe
将以下约束添加到 cafe.als:
- 您可以从任何一家咖啡馆开车到任何其他咖啡馆(尽管可能没有直达路线)。
- 咖啡馆之间的步行道是双向的。
- 每家咖啡馆都可以从其他咖啡馆直接到达,只需一两步。
- 公共汽车在一条非分支路线上访问每家咖啡馆。(注意:您可能希望为此稍微更改总线关系的声明。)
我从未与 Alloy 合作过,我的教授也几乎没有接触过它。我真的迷路了,任何人都可以帮助解释发生了什么或帮助我解决任何问题吗?