forked from jad-hamza/networking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaderPP.scala
129 lines (100 loc) · 3.15 KB
/
LeaderPP.scala
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
125
126
127
128
129
package distribution
import leon.collection._
import leon.proof._
import Protocol._
import ProtocolProof._
import Networking._
import FifoNetwork._
import Quantifiers._
object PrettyPrinting {
def stateToString(s: State) = {
s match {
case Participant() => "Participant"
case NonParticipant() => "NonParticipant"
case KnowLeader(i) => "KnowLeader(" + i + ")"
}
}
def actorIdToString(id: ActorId) = {
id match {
case UID(uid) => "u" + uid
}
}
def statesToString(n: BigInt, m: MMap[ActorId,State]): String = {
def loop(i: BigInt) : String = {
if (i == n) ""
else if (m.contains(UID(i)))
actorIdToString(UID(i)) + " -> " + stateToString(m(UID(i))) + "\n" + loop(i+1)
else
actorIdToString(UID(i)) + " -> Nothing\n" + loop(i+1)
}
"\n"+loop(0)
}
def noParamStatesToString(m: MMap[ActorId,State]): String = statesToString(5, m)
def messageToString(m: Message) = {
m match {
case Election(i) => "Election(" + i + ")"
case Elected(i) => "Elected(" + i + ")"
}
}
def messageListToString(ms: List[Message]): String = {
ms match {
case Nil() => "[]"
case Cons(x, xs) => messageToString(x) + ", " + messageListToString(xs)
}
}
def messagesToString(n: BigInt, m: MMap[(ActorId,ActorId), List[Message]]): String = {
def loop(i: BigInt) : String = {
require(0 <= i && i <= n)
if (i == n) ""
else
actorIdToString(UID(i)) + "," + actorIdToString(UID(increment(i,n))) + ": " + messageListToString(m.getOrElse((UID(i),UID(increment(i,n))), Nil())) + "\n" + loop(i+1)
}
if (n >= 0)
"\n"+loop(0)
else ""
}
def noParamMessagesToString(m: MMap[(ActorId,ActorId), List[Message]]): String = {
messagesToString(5, m)
}
def actorToString(a: Actor) = {
a match {
case Process(id, ssn) => "Process(" + actorIdToString(id) + ", " + ssn + ")"
}
}
def getActorToString(n: BigInt, getActor: MMap[ActorId,Actor]) = {
def loop(i: BigInt) : String = {
require(0 <= i && i <= n)
if (i == n) ""
else if (getActor.contains(UID(i))) {
"getActor(" + i + ") = " + actorToString(getActor(UID(i))) + "\n" + loop(i+1)
} else {
"getActor(" + i + ") = Nothing\n" + loop(i+1)
}
}
if (n >= 0)
"\n"+loop(0)
else ""
}
def noParamGetActorToString(getActor: MMap[ActorId,Actor]) = {
getActorToString(5,getActor)
}
def ssnsToString(n: BigInt, ssns: BigInt => BigInt): String = {
def loop(i: BigInt): String = {
require(0 <= i && i <= n)
if (i == n) ""
else "ssns(" + i + ") = " + ssns(i) + "\n" + loop(i+1)
}
if (n >= 0) "\n"+loop(0)
else ""
}
def networkToString(net: VerifiedNetwork): String = {
val VerifiedNetwork(p, states, messages, getActor) = net
val Params(n, starterProcess, ssns) = p
"\n\nNumber of processes: " + n.toString + "\n" +
"Starting Process: " + starterProcess + "\n\n" +
ssnsToString(n, ssns) + "\n\n" +
statesToString(n, states) + "\n\n" +
messagesToString(n, messages) + "\n\n" +
getActorToString(n, getActor) + "\n"
}
}