废止算法应用于回波算法

1、不管开始多少次波动,只有一个波动进行判定,即:具有最小初始进程的波动进行判定。在发生判定之前,所有其他波动将会被中止。

2、假设对于所有p∈P,udef>q。一旦接收带有r<cawp的消息<tok,r>,由于稍早对cawp的赋值,就会执行条件为r=cawp的if语句。当进程p当选时,接收到来自每个近邻的消息<tok,p>,p将消息<ldr,p>分散到所有进程中,通知它们是领导人,使得它们终止算法的执行。

3、算法

var  cawp:P init udef;

      recp:integer init 0;

      fatherp:P init   udef;

      lrecp:integer init 0;

     winp:P  init udef;

begin if p is initiator then

         begin cawp:=p;

                   forall q∈Neighp do send <tok,q> to q

         end;

         while lrecp<#Neighp do

                  begin receive msg form q;

                            if msg=<ldr,r> then

                               begin if lrecp=0 then

                                           forall q∈Neighp do send <ldr,r> to q;

                                           lrecp:=lrecp+1;winp:=r

                               end

                            else

                               begin if r<cawp then

                                         begin cawp:=r;recp:=0;fatherp:=q;

                                                   forall s∈Neighp,s≠q

                                                             do send <tok,r> to s     

                                         end;

                                         if r=cawp then

                                            begin recp:=recp+1;

                                                      if recp=#Neighp then

                                                         if cawp=p

                                                            then forall sNeighp

                                                                    do send <ldr,p> to s

                                                           else send <tok,cawp> to fatherpo

                                                         end

                                                  end

                                     end;

                                   if winp=p then statep:=leader else statep:=lost

             end

你可能感兴趣的:(算法)