Skip to content

Instantly share code, notes, and snippets.

@jorendorff
Created November 15, 2022 17:47
Show Gist options
  • Save jorendorff/3a3140355563c17968512e53312d83d6 to your computer and use it in GitHub Desktop.
Save jorendorff/3a3140355563c17968512e53312d83d6 to your computer and use it in GitHub Desktop.
Alloy 6 code for a talk, "Wolf, Goat, & Cabbages In Two Styles!!", at !!Con West 2020
abstract sig Object {
eats: set Object,
var location: one Riverbank
}
one sig Wolf extends Object {}
one sig Goat extends Object {}
one sig Cabbages extends Object {}
one sig Boat extends Object {}
fact foodWeb {
eats = (Wolf -> Goat) + (Goat -> Cabbages)
}
abstract sig Riverbank {}
one sig EastBank extends Riverbank {}
one sig WestBank extends Riverbank {}
pred done {
always location[Object] = WestBank // all objects are on the west bank
}
fact goals {
historically location[Object] = EastBank // all objects are on the east bank
eventually done // eventually all together on the other side
}
fact safety {
always no a: Object, b: a.eats |
a.location = b.location and Boat.location != b.location
}
fact movement {
{
let here = Boat.location, there = Boat.location' | {
here != there
some cargo: Object | {
location' = location - (Boat -> here) - (cargo -> here)
+ (Boat -> there) + (cargo -> there)
}
}
} until done
}
run {} for 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment