Test AStarSearch using a grid with obstacles.

------------------------------------------------------------------------
See also AStarSearch, TransformGridCoordinates, Plot2D, TextS
------------------------------------------------------------------------

Contents

%-------------------------------------------------------------------------------
%   Copyright (c) 2003 Princeton Satellite Systems, Inc. All rights reserved.
%-------------------------------------------------------------------------------

n                          = 6;
d.pathCostEstimateFunction = 'GridPathCost';
d.traverseCostFunction     = 'GridTraverseCost';
d.successorNodesFunction   = 'GridSuccessorNodes';
grid                       = zeros(n,n);
d.myData.n                 = n;

blockedNode                = [4 3 3 4 5 6 2 3 2 1 4;...     % row
                              5 3 2 2 2 2 2 5 5 5 4];       % col
for k = 1:size(blockedNode,2)
  grid(blockedNode(1,k),blockedNode(2,k)) = 1;
end

Put in a one dimensional array

%-------------------------------
for k = 1:n
  d.myData.grid(1,((k-1)*n+1):(k*n)) = grid(k,:);
end
d.n  = length(d.myData.grid);

startNode = TransformGridCoordinates( 4, 1, n );
endNode   = TransformGridCoordinates( 4, 6, n );

path      = AStarSearch( startNode, endNode, d );

[y, x] = TransformGridCoordinates( path, n );

Plot2D( x, y, 'x', 'y', 'A* Search' );
n = n + 1;
set( gca, 'xlim', [0 n], 'ylim', [0 n], 'xtick', 0:n, 'ytick', 0:n )
hold on

[row, col] = TransformGridCoordinates( startNode, n-1 );
TextS(col,row-.15,'  start')
plot(col,row,'*g')
[row, col] = TransformGridCoordinates( endNode, n-1 );
TextS(col,row-.15,'  end')
plot(col,row,'*r')

for k = 1:size(blockedNode,2)
  plot(blockedNode(2,k),blockedNode(1,k),'*k');
end

% PSS internal file version information
%--------------------------------------

% $Id: 909d44f7be0d227a071433845b6f11d191583fa5 $