分布式计算-cidon深度优先搜索

1、进程p把它最新向近邻的令牌发送记录在变量mrsp中。

2、当令牌只对树边(深度优先搜索树的边)进行遍历时,下一次进程p从同一近邻mrsp接收令牌。 进程p从不同的近邻接收<tok>消息,即从r接收。这种情况忽略了其它近邻的令牌。进程将rp标记为使用过,就好像消息<ris>从r已经被接收。

3、向p发送<tok>令牌之后,进程r接收p的<ris>消息(因为r向p发送了<tok>,所以mrsr为p),这种情况,r好像没有向p发送令牌(在第2点中会被忽略),r选择下一个近邻并转发令牌

4、算法

var usedp[q] :boolean init false for each qNeighp;

      fatherp   :process init udef;

      mrsp      :process init udef;

 

for the initiator only,execute once:

     begin fatherp:=p;choose q∈Neighp;

               forall rNeighp do send <vis> to r;

               usedp[q]:=true;mrsp:=q;send <tok> to q

    end

 

for each process,upon receipt of <vis> from q0:

     begin usedp[q0]:=true;

               if q0=mrsp then  (*发送令牌后才接收到vis消息,选择另一个近邻转发令牌*)      

                   forward <tok> message as upon receipt of <tok> message  (*收到<tok>后转发给另一个近邻*)

     end    

 

for each process,upon receipt of <tok> from q0:

     begin if mrsp≠udef and mrsp≠q0

             (*this is a frond edge,interpret as <vis> message*)

             then usedp[q0]:=true  (*非树边忽略令牌*)

    else    (*Act as in previous algorithm*)

             begin if fatherp=udef then

                         begin fatherp:=q0;

                                forall r∈Neighp\{fatherp} do

                                        send <ris> to r

                         end;

                       if p is the initiator and 所有q∈Neighp:usedp[q]

                          then decide

                       else if 存在q∈Neighp:(q≠fatherp∧┐usedp[q])

                                  then begin if fatherp≠q0∧ ┐usedp[q0]

                                                       then q:=q0

                                                       else choose qNeighp\{fatherp} with ┐usedp[q];

                                                    usedp[q]:=true;mrsp:=q;

                                                    send <tok> to q

                                          end

                                  else begin usedp[fatherp]:=true;

                                                    send <tok> to fatherp

                                          end

                 end

end

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