function UPRMatric = BFS_LocalPolytree( UPRMatric,MaxNode )
Dim = size( UPRMatric,2 );
Queue = zeros( 1,Dim );
Front = 1; End = 2;
Queue(1) = MaxNode;
VisitedNodes = zeros( 1,Dim );
% h3 = view(biograph( UPRMatric ))
while Front ~= End
CurrentNode = Queue( Front );
VisitedNodes( CurrentNode ) = 1;
Front = QueueMove( Front,Dim );
for p = 1:Dim
if p ~= CurrentNode && UPRMatric( p,CurrentNode ) ~= 0 && UPRMatric( CurrentNode,p ) ~= 0 && VisitedNodes( p ) == 0
UPRMatric( p,CurrentNode ) = 0;
if VisitedNodes( p ) == 0
Queue( End ) = p;
End = QueueMove( End,Dim );
end
end
if p ~= CurrentNode && UPRMatric( CurrentNode,p ) ~= 0 && VisitedNodes( p ) == 0
if VisitedNodes( p ) == 0
Queue( End ) = p;
End = QueueMove( End,Dim );
end
end
end
end
end
function Next = QueueMove( Current,Dim )
Next = mod( Current,Dim+1 )+1;
end