forked from atary/runway-model-toomanybananas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoomanybananas.model
57 lines (51 loc) · 1.03 KB
/
toomanybananas.model
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
52
53
54
55
56
57
/*
* Copyright (c) 2016, Salesforce.com, Inc.
* All rights reserved.
* Licensed under the MIT license.
* For full license text, see LICENSE.md file in the repo root or
* https://opensource.org/licenses/MIT
*/
var bananas : 0..100 = 2;
var notePresent: Boolean;
type Person : either {
Happy,
Hungry,
GoingToStore,
ReturningFromStore {
carrying: 0..8
}
};
var roommates: Array<Person>[1..5];
rule step for state in roommates {
match state {
Happy {
state = Hungry;
}
Hungry {
if bananas == 0 {
if (notePresent) {
// Roommate at store: try again later
} else {
notePresent = True;
state = GoingToStore;
}
} else {
bananas -= 1;
state = Happy;
}
}
GoingToStore {
state = ReturningFromStore {
carrying: urandomRange(0, 8)
};
}
ReturningFromStore(bag) {
bananas += bag.carrying;
notePresent = False;
state = Hungry;
}
}
}
invariant BananaLimit {
assert bananas <= 8;
}