1
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に次の制約を追加します。質問:初心者合金は
- ( 直接ルートがないかもしれないが)あなたが車で、他のカフェに任意のカフェから取得することができます。
- カフェ間の歩行経路は双方向です。
- すべてのカフェは、1つまたは2つのステップで直接または他のすべてのカフェからアクセスできます。
- バスは、単一の非分岐ルートで各カフェを訪れます。 (注: おそらく少しこのためバス 関係の宣言を変更したくなるでしょう。)
私は合金で働いたことがありませんし、私のprofesserはやっとそれに触れています。私は本当に失われている、誰が何が起こっているか説明するのに役立つか、問題のいずれかで私を助けることができる?