I have read his seminal paper, Self-stabilizing systems in spite of distributed control. However, I don't quite get how the self-stabilizing algorithm works. I am most interested in his, 'solution' of k-state machines. The density of the paper is quite intense and I can't make much sense of it. How does this algorithm work in plain English?
I can try to explain it in plain English...
First you should have a look at the link Jean-Francois Corbett wrote as a comment.
(from Wikipedia)
A system is self-stabilizing if and only if:
- Starting from any state, it is guaranteed that the system will eventually reach a correct state (convergence).
- Given that the system is in a correct state, it is guaranteed to stay in a correct state, provided that no fault happens (closure).
Same as the one on the seminar paper
In his paper Dijkstra defines a self stabilizing system as follow:
Consider a circle graph with N+1 nodes. (From 0 to N+1)
Each node can be in different states.
Each node can have different privilege. (for example xS = xR can be a privilege)
At each step if in one node a privilege is present we will apply a certain rule :
if privilege then "what to do" endif
He defines a legitimate state to be a state with only one privilege present.
If you apply the different rules in Dijkstra's paper for the described system you will get a self-stabilizing system. (cf definition.)
i.e. from any state with n privilege presents (even with multiple privileges for one node) you will reach in a finite number of states a state with only one privilege present, and stay in legitimate states after this state. And you will be able to reach any legitimate state.
You can try yourself with a simple example.
Let's take only a bottom node and a top node:
starting point: (upT,xT) = (0,0) and
(upB,xB) = (1,0)
state1: (upT,xT) = (0,0) and
(upB,xB) = (1,1)
only one privilege present on B => legitimate
state2: (upT,xT) = (0,1) and
(upB,xB) = (1,1)
only one privilege present on T => legitimate
state3: (upT,xT) = (0,1) and
(upB,xB) = (1,0)
only one privilege present on B => legitimate
state4: (upT,xT) = (0,0) and
(upB,xB) = (1,0)
only one privilege present on T => legitimate
and here is a result for 3 nodes: bottom (0) middle (1) top (2): I start with 2 privileges (not legitimate state, then once I get into a legitimate state I stay in it):
{0: [True, False], 1: [False, False], 2: [False, True]}
privilege in bottom
privilege in top
================================
{0: [True, True], 1: [False, False], 2: [False, False]}
first privilege in middle
================================
{0: [True, True], 1: [True, True], 2: [False, False]}
privilege in top
================================
{0: [True, True], 1: [True, True], 2: [False, True]}
second privilege in middle
================================
{0: [True, True], 1: [False, True], 2: [False, True]}
privilege in bottom
================================
{0: [True, False], 1: [False, True], 2: [False, True]}
first privilege in middle
================================
{0: [True, False], 1: [True, False], 2: [False, True]}
privilege in top
================================
{0: [True, False], 1: [True, False], 2: [False, False]}
second privilege in middle
================================
{0: [True, False], 1: [False, False], 2: [False, False]}
privilege in bottom
... etc
Here is a small Python [<=2.7] code (I am not very good at python so it's may be ugly) to test the 4 states methods with a system of n nodes, it stops when you find all the legitimate states:
from copy import deepcopy
import random
n=int(raw_input("number of elements in the graph:"))-1
L=[]
D={}
D[0]=[True,random.choice([True,False])]
for i in range(1,n):
D[i]=[random.choice([True,False]),random.choice([True,False])]
D[n]=[False,random.choice([True,False])]
L.append(D)
D1=deepcopy(D)
def nextStep(G):
N=len(G)-1
print G
Temp=deepcopy(G)
privilege=0
if G[0][1] == G[1][1] and (not G[1][0]):
Temp[0][1]=(not Temp[0][1])
privilege+=1
print "privilege in bottom"
if G[N][1] != G[N-1][1]:
Temp[N][1]=(not Temp[N][1])
privilege+=1
print "privilege in top"
for i in range(1,N):
if G[i][1] != G[i-1][1]:
Temp[i][1]=(not Temp[i][1])
Temp[i][0]=True
print "first privilege in ", i
privilege+=1
if G[i][1] == G[i+1][1] and G[i][0] and (not G[i+1][0]):
Temp[i][0]=False
print "second privilege in ", i
privilege+=1
print "number of privilege used :", privilege
print '================================'
return Temp
D=nextStep(D)
while(not (D in L) ):
L.append(D)
D=nextStep(D)