www.pudn.com > Improved-AStar-on-3D-Terrain.rar > min_fn.m, change:2013-02-19,size:1176b


%Function to return the Node with minimum fn 
function i_min = min_fn(OPEN,OPEN_COUNT,xTarget,yTarget) %此时 OPEN(j,2) ,OPEN(j,3)与 OPEN(j,4) OPEN(j,5)不一样了 
 temp_array=[]; 
 k=1; 
 flag=0; 
 goal_index=0; 
 for j=1:OPEN_COUNT 
 %OPEN LIST FORMAT 
 %IS ON LIST 1/0 |X val |Y val |Parent X val |Parent Y val |g(n) |h(n)| f(n)| 
     if (OPEN(j,1)==1)%如果节点在Open表 
         temp_array(k,:)=[OPEN(j,:) j];   %目的是将open中的节点放入临时表temp_array 
         if (OPEN(j,2)==xTarget && OPEN(j,3)==yTarget)%如果直接找到目标点 
             flag=1; 
             goal_index=j;%Store the index of the goal node 
         end; 
         k=k+1; 
     end; 
 end;%Get all nodes that are on the list open 
  
 if flag == 1 % one of the successors is the goal node so send this node 
     i_min=goal_index; 
 end 
  
 %Send the index of the smallest node 
 if size(temp_array ~= 0) 
     [min_fn,temp_min]=min(temp_array(:,8));%Index of the smallest node in temp array 
     %搜索f(n)最小值,返回最小值及其序号 
     i_min=temp_array(temp_min,9);%Index of the smallest node in the OPEN array 
 else 
     i_min=-1;%The temp_array is empty i.e No more paths are available. 
 end;