码迷,mamicode.com
首页 > 其他好文 > 详细

拜占庭将军问题

时间:2016-01-08 20:08:52      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

Seven machines send information to each other.As long as the number sent is within 2.0 of the correct number,the answer is correct.Two of the machines are faulty.Find the number that each machine would compute it it use:

 

Sender

1

2

3

4

5

6

7

Receiver

OK

OK

OK

OK

OK

Faulty

Faulty

1

3

1.1

2.5

4.7

1.4

4.5

4.8

2

3

1.1

2.5

4.7

1.4

5

5

3

3

1.1

2.5

4.7

1.4

4.9

5

4

3

1.1

2.5

4.7

1.4

1

0.9

5

3

1.1

2.5

4.7

1.4

5

4.7

6

3

1.1

2.5

4.7

1.4

1.2

1

7

3

1.1

2.5

4.7

1.4

5.1

5.1

 

Dolev算法:

算法步骤:

1.去除每个PE所收到的信号的t=2个最大值,和t=2个最小值;(此处t为允许出错的最大PE数,t=(N-1)/3)

2.对每个PE保留的其余值求均值;

3.将每个PE得到的均值作为该PE的新信号发给其他PE,但6#、7#PE因故障仍然按最初的情形将信号发给其他PE。

4.再从第1步开始新的迭代,当各PE的均值收敛时,停止迭代。

Mathematica程序:

r={{3,1.1,2.5,4.7,1.4,4.5,4.8},{3,1.1,2.5,4.7,1.4,5,5},{3,1.1,2.5,4.7,1.4,4.9,5},{3,1.1,2.5,4.7,1.4,1,0.9},{3,1.1,2.5,4.7,1.4,5,4.7},{3,1.1,2.5,4.7,1.4,1.2,1},{3,1.1,2.5,4.7,1.4,5.1,5.1}};
d=Length[r];
n=IntegerPart[(d-1)/3];
m=TrimmedMean[Transpose[r],n/d];
a={};
While[Variance[m] > 0.0001, r[[All, 1 ;; (d - n)]] = Drop[m, -n]; m = TrimmedMean[Transpose[r], n/d]; AppendTo[a, m]]; m
ListLinePlot[a,AxesOrigin->{1,2.5}]
r=d=n=m=a=.

运行结果:

{3.4, 3.4, 3.4, 3.39259, 3.4, 3.39259, 3.4}

技术分享

(未完待续)

 

拜占庭将军问题

标签:

原文地址:http://www.cnblogs.com/neutrontsingh/p/5114215.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!