forked from hwayne/learntla-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatemachines.xml
127 lines (106 loc) · 2.63 KB
/
statemachines.xml
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?xml version="1.0"?>
<root folder="statemachines">
<spec name="pluscal" num="1">
---- MODULE $name ----
(*--algorithm lamp
variable state = "BothOff";
process StateMachine = "SM"
begin
Action:
either \* this is the state machine
await state = "BothOff";
state := "WallOff";
or
await state = "BothOff";
state := "LampOff";
or
await state = "LampOff";
state := "BothOff";
or
await state = "LampOff";
state := "On";
or
await state = "WallOff";
state := "BothOff";
or
await state = "WallOff";
state := "On";
or
await state = "On";
state := "LampOff";
or
await state = "On";
state := "WallOff";
end either;
goto Action;
end process;
end algorithm; *)
====
</spec>
<spec name="sm_tla" num="1">
---- MODULE $name ----
VARIABLE state
Trans(a, b) ==
/\ state = a
/\ state' = b
Init == state = "BothOff"
Next ==
\/ Trans("BothOff", "WallOff")
\/ Trans("BothOff", "LampOff")
\/ Trans("WallOff", "On")
\/ Trans("WallOff", "BothOff")
\/ Trans("LampOff", "BothOff")
\/ Trans("LampOff", "On")
\/ Trans("On", "WallOff")
\/ Trans("On", "LampOff")
\/ Trans("error", "fetching")
Spec == Init /\ [][Next]_state
====
</spec>
<spec name="hsm" num="1">
---- MODULE $name ----
EXTENDS TLC \* For @@
VARIABLE state
States == {
"LogOut",
"LogIn", "Main", "Settings",
"Reports", "Report1", "Report2"
}
TopDown == [LogIn |-> {"Main", "Settings", "Reports"},
Reports |-> {"Report1", "Report2"}] @@ [s \in States |-> {}]
\* @@ is function left-merge ^^
BottomUp == [Report1 |-> "Reports", Report2 |-> "Reports",
Reports |-> "LogIn", Main |-> "LogIn", Settings |-> "LogIn"]
\* For TopDown we need to make sure that there are no double-parents
ASSUME \A s1, s2 \in States: s1 # s2 => TopDown[s1] \cap TopDown[s2] = {}
RECURSIVE InTD(_, _)
InTD(s, p) ==
\/ s = p
\/ \E c \in TopDown[p]:
InTD(s, c)
RECURSIVE InBU(_, _)
InBU(s, p) ==
\/ s = p
\/ \E c \in DOMAIN BottomUp:
/\ p = BottomUp[c]
/\ InBU(s, c)
\* Check the two are identical
ASSUME \A s, s2 \in States: InTD(s, s2) <=> InBU(s, s2)
Trans(from, to) ==
/\ InTD(state, from)
/\ state' = to
Init == state = "LogOut"
Next ==
\/ Trans("LogOut", "Main")
\/ Trans("Main", "Settings")
\/ Trans("Settings", "Main")
\/ Trans("LogIn", "LogOut")
\/ Trans("LogIn", "Report1")
\/ Trans("Report1", "Report2")
\/ Trans("Report2", "Report1")
\/ Trans("Reports", "Main")
Spec == Init /\ [][Next]_state
AlwaysInLeaf == TopDown[state] = {}
====
</spec>
</root>