Algorithm “随机游走”算法是如何工作的?
下面的算法是用伪代码编写的,为了简单起见,不包括数据结构中实际路由的存储Algorithm “随机游走”算法是如何工作的?,algorithm,routing,pseudocode,tor,Algorithm,Routing,Pseudocode,Tor,下面的算法是用伪代码编写的,为了简单起见,不包括数据结构中实际路由的存储 LengthFromSrc = 0; LengthFromDest = 0; TotalNumberHops = 0; X = SRC; /*Last Node Visited from Random walk starting at SRC;*/ Y = DEST; /*Last Node Visited from Random walk starting at DEST;*/
LengthFromSrc = 0;
LengthFromDest = 0;
TotalNumberHops = 0;
X = SRC; /*Last Node Visited from Random walk starting at SRC;*/
Y = DEST; /*Last Node Visited from Random walk starting at DEST;*/
/* Randomly select a route length */
do {
Length = rand( ) % Max;
while( Length < Min );
while( TotalNumberHops < Length ) {
Next = Toss Coin to Pick Random Walk from Src or from Dest;
if( Next == RandWalkFromSrc ) {
Z = Randomly select an adjacent node to X;
TotalNumberHops = 1 + LengthFromSrc + LengthFromDest
+ shortest-path from Z to Y;
if( TotalNumberHops > Length )
break;
X = Z; /*include the node in the route*/
Store X in the route data structure
LengthFromSrc++;
}
else { /* Next = RandWalkFromDest */
Z = Randomly select an adjacent node to Y;
TotalNumberHops = 1 + LengthFromSrc + LengthFromDest
+ shortest-path from Z to X;
if( TotalNumberHops > Length )
break;
Y = Z;
Store Y in the route data structure
LengthFromDest++;
}
}
是否有人会给我一个简单的算法分析/或带我浏览代码,因为我想更好地理解它?我的主要问题是理解第一部分:
do {
Length = rand( ) % Max;
while( Length < Min );
while( TotalNumberHops < Length )
PS:我的源代码是我要说的是代码缺少a}尽管它是伪代码,所以任何事情都会发生
do {
Length = rand() % Max;
}
while( Length < Min );
或者,因为这是伪代码:
Length = random number in the range [Min, Max)
代码的其余部分同时从源和目标生成两条路径,然后在使用最短路径链接它们时停止,这将导致比长度更长的行走。想象rand给出的值介于0和非常大的值之间。%Max确保该值小于Max。然后,如果小于Min,则重试。
Length = random number in the range [Min, Max)