forked from wenhuizhang/summer-school-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise02.dfy
52 lines (40 loc) · 1.52 KB
/
exercise02.dfy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//#title Dining Philosophers
//#desc A more challenging state machine: define the state datatype.
// Define the state machine for the Dining Philosophers.
// There are N philosophers sitting around a round table.
// Between every pair of philosophers lies a chopstick.
// Every philosopher has three possible actions:
// * Acquire the chopstick to their left.
// * Acquire the chopstick to their right.
// * Release both chopsticks (in a single step).
datatype Constants = Constants(tableSize:nat)
//Use this datatype to define all the relevant state
datatype Variables = Variables()
// An initial predicate to define well-formed constants.
// Feel free to add more if you need them
predicate WellFormedConstants(c:Constants) {
&& 0 < c.tableSize
}
// An initial predicate to define well-formed state.
// Feel free to add to this predicate, if necessary
predicate WellFormed(c:Constants, v:Variables) {
&& WellFormedConstants(c)
}
predicate Init(c:Constants, v:Variables) {
true // Replace me
}
// Philosopher with index pi acquires left chopstick
predicate AcquireLeft(c:Constants, v:Variables, v':Variables, pi:nat) {
true // Replace me
}
// Philosopher with index pi acquires right chopstick
predicate AcquireRight(c:Constants, v:Variables, v':Variables, pi:nat) {
true // Replace me
}
// Philosopher with index pi releases both chopsticks
predicate ReleaseBoth(c:Constants, v:Variables, v':Variables, pi:nat) {
true // Replace me
}
predicate Next(c:Constants, v:Variables, v':Variables) {
true // Replace me
}