• No results found

Implementation Notes

In document Epistemic Gossip Protocols (Page 125-129)

We now present some implementation specific notes. We discuss how we capture the details of the extension of an epistemic gossip protocol, and we present an approach we employed for parallel processing during execution of the EGP tool.

4.3.1 Protocol Extension

We adopt the standard extension as the basis for the comparison of the extension size of terminating epistemic gossip protocols. We measure the size of the standard extension of an epistemic gossip protocol by counting the number of leaf nodes in the gossip tree for the protocol, since this corresponds to the number of execution sequences that start from the initial gossip situation and reach termination. An execution sequence terminates either because it has achieved the goal state that every agent knows every other agent’s secret, or due to a deadlock in the resulting gossip situation due to the calling condition not being satisfied for any pair of agents to call each other although the goal state have not been reached. We also allow that an execution sequence can terminate due to a stoppage by the user of the EGP tool. When an execution sequence terminates, we record its length and note whether it is successful or not. Finally we count all the execution sequences of each length value, and calculate the average execution length of the protocol.

In order to capture all the execution sequences in a protocol’s extension, we need to explicitly keep all the execution sequences in memory during protocol execution. But this can be very demanding with respect to the computing time and memory resources especially with increasing number of agents in the scenario. However, we do not need to keep all the execution sequences in memory in order to: measure the size of the protocol’s standard extension, take the count of terminal execution sequences of various length values or calculate the average execution length of the protocol from the terminal execution sequences. Therefore in order to allow for various needs of the user of the EGP tool, we enable the user to run the tool in two modes, namely: (a) sparse tree mode, and (b) full tree mode. The sparse tree mode allows the protocols to run faster and with less memory, and gives results for the average execution length, the count of various terminal execution sequence length values and the standard extension size of the protocol, although the user will not obtain all the execution sequences in the protocols standard extension using this mode. The full standard extension of the protocol is obtained by using the full tree mode which is less memory and time efficient than the sparse tree mode.

Let us now briefly discuss the technique we use for the sparse tree mode.

Consider a branch of a gossip tree shown in Figure 4.7(a). The nodeσ0 is the parent node of σ1 and σ2. The node σ1 is due to a call ab at σ0, whereas the node σ2 is due

to a call baat σ0. It is obvious that all the agents know the same secrets at the gossip situation resulting from σ1 as they do for the gossip situation resulting from σ2. When

σ′

σ1

σ2

ab

ba

(a) A Branch of a Full Tree

σ′ ab σ

m= 2x

m=x

(b) A Branch of a Sparse Tree

Figure 4.7: Jointed versus non-jointed nodes.

such pair of callsabandbaoccur at the same node of a gossip tree we call themmirrored calls. Recall that we distinguish between the callaband the callba. One reason for this distinction is that under the epistemic gossip protocols both calls are not always jointly possible. For example, the epistemic calling condition may be satisfied for agentato call agent b, but the epistemic calling condition for agent b to call agent a is not satisfied. More concretely, take the Learn New Secrets protocol where an agentacan call another agentbif agentadoes not know the unique secret of agentb. Now consider the following execution sequence: bc;ac;. . ., after the first two calls agentacan no longer call agentb whose unique secret it learnt from agentc, but then agentbcan still call agentabecause bhave not yet learnt the unique secret of agenta. That said, it is clear that the extension of a protocol will not be fully captured if the sequence σ1 were always identified with

the sequence σ2. However, in the sparse tree mode, for the purpose of increasing time

and memory efficiency, we identify two such nodesσ1 andσ2, that is, instead of creating

two child nodes as a result of the mirrored calls at σ0, we create only one child node σ as a result of the mirrored calls. Let us then say we have joined suchσ1 and σ2 intoσ,

and refer to suchσ as ajointed node, and also refer to suchσ1 and σ2 as the jointees of

σ. Then, we keep track of the multiplicity value of the nodes as follows. The root node of a gossip tree has a multiplicity value of one. When a child node is produced from a parent node, the child node’s multiplicity initially takes the value of the multiplicity of its parent node. If a child node is a jointed node, then its multiplicity value becomes the value of its parent’s multiplicity multiplied by two. See Figure 4.7(b) for the jointed version of the branch shown in Figure 4.7(a). (Note that in Figure 4.7(b), m stands for the value of the multiplicity of a node).

Therefore in the sparse tree mode, when an execution sequence terminates, we incre- ment the size of the standard extension by the value of the multiplicity of the terminal (or leaf) node of that execution sequence. We now prove that the sparse tree represen- tation does not alter the satisfiability of the epistemic calling conditions when compared

with the full tree representation. Moreover, we show that the same standard extension size and counts of various execution sequence lengths is obtained for both the sparse tree representation and the full tree representation.

Lemma 4.35. Let σ be a jointed node and let σ1 and σ2 be jointees of σ. Then an

epistemic calling condition ϕ is satisfied in σ1 if and only ifϕ is satisfied in σ2.

Proof. Take two arbitrary agents ai 6=aj ∈Ag. Let the epistemic calling condition for agent ai to call agent aj be the formula Kaiϕ. From Definition 4.11, Kaiϕ is satisfied

at a node σ0 if ϕ is satisfied at every node σ00 ∈ Zai(σ0). But from the definition of

equivalence relation given in Definition 4.7, σ1 ≡ai σ2. Therefore Zai(σ1) = Zai(σ2).

And thereforeKaiϕis satisfied in σ1 if and only ifKaiϕis satisfied in σ2.

Lemma 4.36. Let σ be a jointed node and let σ1 and σ2 be jointees of σ. Then an

epistemic calling condition ϕ is satisfied in σ1 if and only ifϕ is satisfied in σ.

Proof. The proof follows directly from Lemma 4.35: a jointed node isequal to one of its jointees.

Proposition 4.37. The size of the standard extension obtained from the sparse tree is equal to the size of the standard extension obtained from the full tree.

Proof. Letσ1 andσ2 be child nodes of the root node of a gossip treeTg. Also letσ1 and

σ2 be jointees. Recall that the value of the multiplicity of the root node is one. Consider

the subtreeτ1 which hasσ1 as its root node, and the subtreeτ2 which hasσ2 as its root

node. From Lemma 4.35 and from Definition 4.7, it follows that τ1 is identical to τ2.

Therefore if we joinσ1 andσ2 into a node σ, then the number of paths in the subtreeτ

which has the jointed nodeσ as its root will be the number of paths inσ1 multiplied by

two. Thus the value of the multiplicity of σ is two. Inductively, assume that the value of the multiplicity of an arbitrary node σˆ0 in Tg is x. Suppose ˆσ is a child node of σˆ0, then the value of the multiplicity of σˆ is 2x if ˆσ is jointed, otherwise the value of the multiplicity ofσˆ is x. We therefore conclude that adding the value of the multiplicity of all the leaf nodes in a sparse tree yields the same number of paths, and thus the same standard extension size, as in the full tree, where such path starts from the root node and terminates in a leaf node of Tg.

4.3.2 Encoding the Agents and the Secrets

Given a scenario with n agents, the set Ag of agents is encoded as a set of consecutive natural numbers beginning with zero. That is,Ag={0,1, . . . , n−1}. The set of secrets known by each agenti∈Agis encoded as ann-sized binary word,ωi. Starting from the least significant bit ofωi, let thekth bit inωi beωi(k), then the(k+ 1)th bit ofωi is set to 1 if and only if agent i knows the secret of agent k. Therefore, at the initial gossip

situation where each agent knows only its unique secure, we have that: ωi(i+ 1) = 1 for all 0≤i≤n−1

ωi(j+ 1) = 0 for all 0≤i6=j≤n−1

For example, in a scenario with four agents, we have Ag = {0,1,2,3} and the set of secrets known by the agents0,1,2 and3 at the initial gossip situation are, respectively, encoded as 20 = 0001,21= 0010,22= 0100 and23 = 1000.

Furthermore, whenever an agent i learns a new secret, say the secret of agentj, we set ωi(j+ 1) to 1. So for an arbitrary round r of calls, and an arbitrary pair of agents i, j∈Ag, let the encoding for the secrets known by agent iand j at the end of round r beω0i andωj0 respectively. Observe that after a call betweeniandjat roundr+ 1, then the sets ω00i and ωj00 of secrets known by iand j, respectively, can be (and are) encoded as:

ω00ij00=ωi0⊕ω0j

Subsequently, to check if an agentiknows the secrets of agentj, we test ifωi(j+ 1) = 1. The number of secrets known by agent iis given by the number of bits in ωi that have the value of 1. Finally, an agent knows all the secrets in the scenario if and only if ωi = 2n−1.

4.3.3 Multithreading

To implement the ComputeNextLayer procedure, we createµ threads (lightweight pro- cesses),µ≥1, and then create as many parallel tasks as the number of tree nodesh0 in λk. A task generates all the successor nodesh ath0. We place each of the newly created tasks in atask pool, from where the threads take tasks to execute in parallel. The list of successor nodes is returned by each thread, and all such lists are merged to produce the nodes in the next layerλk+1 of the gossip tree. Program execution stops aftern(n−1)/2

rounds of calls. This corresponds to the maximum number of rounds needed to attain the goal state if there is no redundant call in an execution sequence, that is, in each call some agent learns some new secret (see Proposition 6.13 in Chapter 6).

We utilise the Java Executor service which provides life-cycle routines for dynamic threads, and handles the background management of such threads and their associated task pool. The Java Executor service also provides a mechanism calledFuture: for each new parallel task allocated to a dynamic thread, the executor framework returns a Future object which provides a handle to any result returned as a result of execution of the task. We could then go through the list of all Futures when all the tasks are completed to process their results. For optimal scheduling of the threads, careful consideration of the available CPUs and dynamic memory is important vis-`a-vis number of created threads.

In document Epistemic Gossip Protocols (Page 125-129)