gpsr core

本文介绍了一种基于伪代码的路由算法,包括贪心转发(greedy_forward)、平面化(rng_planarize/gg_planarize)、角度计算(angle)、判断线段是否相交(intersect)以及周边转发(perimeter_forward)等步骤。通过这些算法可以实现有效的路径选择。

pseudo-code

note:

C : Current node.
D : Destination node.
set_C : Set of neighbor nodes of C.
M,N:the neighbor of C.
flag : neighbor node is available or not
d_(neighbor→D ): The distance from neighbor to D.
θ_neighbor : The corresponding angle of neighbor.
Q : The allowed communication area.


greedy_forward
Caculate min = d_(C->D);
Initialize nexthop;

while(N in set_C)//对当前节点的所有邻居节点
	Caculate d_(N->D)
	if d_(N->D)<min then
		min = d_(N->D);
		nexthop <- N;
	end if
end while

return nexthop;

rng_planarize
while(N in set_C)  do //对当前节点的所有邻居节点
	Caculate d_(N->C); 
	
	while(M in set_C) do
		Caculate d_(M->C);
		Caculate d_(M->N);
		if d_(M->C)<d(N->C) && d_(M->N)<d(N->C) then
			N <- unavailable;
			//remove node N from the list
			break; //舍弃节点N
		end if
	end while 
		
	if(N is available) then 
		add the node into newset;
	end if
end while

return newset;

gg_planarize
while(N in set_C) do
	Caculate d_(C->middle);

	while(M in set_C) do
		if(N != M) then
			Caculate d_(M->middle);
			if(d(M->caculate) < d(C->middle)) then
				N <- unavailable;
				//remove node N from the list
				break; //舍弃节点N
			end if
		end if
	end while

	if(N is available) then
		add the node into newset;
	end if
end while
return nweset;

angle

exist two nodes R1(x1, y1) and R2(x2, y2)
caculate the relative angle of line R1->R2

Caculate d_(R1->R2);
if d_(R1->R2) then
	R1 and R2 are the same;
else
	Caculate sin = (y2-y1) / d_(R1->R2);
	Caculate cos = (x2-x1) / d_(R1->R2);
	Caculate theta = arccos(cos);
	if sin < 0 then
		//R2 在 R1 的负方向
		theta = 2*PI - theta;
	end if
end if
return theta;

intersect

这篇博客中介绍了判断线段是否相交的方法,感觉讲的也比较详细。
current a(x1, y1) nexthop b(x2,y2)
source c(x3, y3) destination d(x4, y4)
在这里插入图片描述

if 'the rectangle of ab' and 'the rectangle of cd' have public areas then
	Caculate u = (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
	Caculate v = (d.x-a.x)*(b.y-a.y)-(b.x-a.x)*(d.y-a.y)
	Caculate w = (a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y);
	Caculate z = (b.x-c.x)*(d.y-c.y)-(d.x-c.x)*(b.y-c.y);
	if u*v <= 0 && w*z <= 0 then
		is crossed;
	else 
		is uncrossed;
	end if
else
	is uncrossed;
end if

perimeter_forward
//平面化
if(choose RNG planarization)
	neighborset = rng_planarize();
else
	neighborset = gg_planarize();
end if

//周边转发
if exist last hop M then
	Caculate alpha = θ_M; //计算当前节点与上一跳节点连线ml的夹角
else
	Caculate alpha = θ_D;  //计算当前节点与目的节点连线md的夹角
end if

while(N in neighborset && N is not equivalent to M) //遍历平面化后的邻居列表
	Caculate delta = θ_N;
	//选取逆时针方向的节点
	//且该节点与当前节点的连线与ml或md的夹角是最小的
	delta = delt-alpha;
	if delta < 0.0 then  //两条线的逆时针夹角
		delt = 2*PI + delta;
	end if
	if delt < minangle then
		minangle = delt;
		choose N as the next hop;
	end if
end while

if the line 'from me to the next hop' and the line 'from source and destination' is intersecting each other then
	repeat perimeter_forward with choosing the next hop as the next hop;
end if




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值