📄 sgnt_purning.m
字号:
function [node_new] = sgnt_purning(node)
%*******************************************************
% Purning a SGNT named node
%*******************************************************
% VWP Purning VWP(Vertically Well Placed) d(n,np)<=d(n,ng)
[nr,nc]= size(node);
m = nc - 4;
for i=2:1:nr % -------------------------- 1 end
if node(i,m+2) > 0 & node(node(i,m+2),m+2) > 0 % -------- 2 end
parent_pt= node(i,m+2);
grandparent_pt= node(parent_pt,m+2);
wn = node(i,1:m);
wp = node(parent_pt,1:m);
wg = node(grandparent_pt,1:m);
%dnp=sqrt((wn-wp)*(wn-wp)'/m);
%dng=sqrt((wn-wg)*(wn-wg)'/m);
dnp=sum((wn - wp).^2);
dng=sum((wn - wg).^2);
if dnp > dng % --------------------------- 3 end
% update np
temp = node(parent_pt,m+1);
node(parent_pt,m+1)= node(parent_pt,m+1)- node(i,m+1);
if node(parent_pt,m+1) <= 0 node(parent_pt,m+1) = 1; end
node(parent_pt,1:m)= (node(parent_pt,1:m).*temp - node(i,1:m)*node(i,m+1))/node(parent_pt,m+1);
% connect(n,ng)
node(i,m+2) = grandparent_pt; % 1
node(i,m+4) = node(grandparent_pt, m+3);
node(grandparent_pt, m+3) = i;
if node(parent_pt,m+3) == i % node i is a first sibling (the most left sibling)
node(parent_pt,m+3) = node(i,m+4);
else % node i isn't a first sibling
jj = node(parent_pt,m+3);
while (jj > 0 & node(jj,m+4)~=i )
jj = node(jj,m+4);
end
if jj > 0
node(jj,m+4)= node(i,m+4);
end
end
end % --------------------------- 3 end
end % -------- 2 end
end % -------------------------- 1 end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% merge
for i=1:1:nr
if node(i,m+3)>0 & node(node(i,m+3),m+4)==0
temp = sum((node(i,1:m+1) - node(node(i,m+3),1:m+1)).^2);
if temp == 0
node(node(i,m+3),m+2) = node(i,m+2);
node(node(i,m+3),m+4) = node(i,m+4);
if node(node(i,m+2),m+3) == i % i is a first child of its father
node(node(i,m+2),m+3) = node(i,m+3);
else
parent_pt= node(i,m+2);
jj = node(parent_pt,m+3);
while (jj > 0 & node(jj,m+4)~=i )
jj = node(jj,m+4);
end
if jj > 0
node(jj,m+4)= node(i,m+3);
end
end
node(i,:) = 0;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HWP Purning HWP(Horizontally Well Placed) d(n,np)<=d(n,ns)
[nr,nc]= size(node);
for i=2:1:nr % -----------1 end
if node(i,m+2)>0 %---------------- 2 end
% -----------------find all siblings of node(i)
sibling(1)= node(node(i,m+2),m+3);
temp = 1;
while (node(sibling(temp),m+4) > 0)
sibling(temp) = node(sibling(temp),m+4);
end
%----------------- calculating d(n,np)
w = node(i,1:m);
wp = node(node(i,m+2),1:m);
%dp=sqrt((w-wp)*(w-wp)'/m);
dp=sum((w-wp).^2);
%----------------- calculating d(n,ns)
for j=1:1:length(sibling) %------------- 3 end
update = 0;
if sibling(j) ~= i & update == 0 %------------- 4 end
ws = node(sibling(j),1:m);
% ds=sqrt((w-ws)*(w-ws)'/m);
ds=sum((w-ws).^2);
if dp > ds % update ns %-- 5 end
% -------------------------- find dead node
dead = 0;
jj = 1;
while (dead == 0 & jj < nr)
jj = jj + 1;
if node(jj,m+2) == 0 dead= jj; end
end
%--------------- copy node(sibling(j)) into a new node
if dead == 0
nr = nr+1;
dead = nr;
end
node(dead,:)= node(sibling(j),:);
node(dead,m+1)= 1;
node(dead,m+2)= sibling(j);
node(dead,m+3)= 0;
node(dead,m+4)= i;
% ----------------------------- connect(n,ns)
if i == sibling(1) % node i is the first child of its father
node(node(i,m+2),m+3) = node(i,m+4);
else
for jj = 1:1:length(sibling)
if sibling(jj) == i temp = sibling(jj-1); end
end
node(temp,m+4) = node(i,m+4);
end
node(i,m+2) = sibling(j);
node(i,m+4) = node(sibling(j),m+3);
node(sibling(j),m+3)= dead;
% ------------------------ update w and number of node(sibling,:)
temp = sibling(j);
node(temp,1:m)= (node(temp,1:m).*node(temp,m+1)+node(i,1:m).*node(i,m+1))...
/(node(temp,m+1)+ node(i,m+1));
node(temp,m+1)= node(temp,m+1)+ node(i,m+1);
%-------------------------------------------------
update = 1;
end %------------- 5 end
end %------------- 4 end
end %------------- 3 end
end %------------- 2 end
clear sibling
end %------------- 1 end
node_new = node;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -