h' (n) = min over all i that are successors n of { c(n,i) + h(i) }.
The following problem requires signficant programming:
Specifically, you are to implement routines that solve planning problems that take place in an N by M grid of cells, with initial and goal cells specified by integer pairs: (iinit, jinit) and (igoal, jgoal). The actions available are moving left (decrementing i), right (incrementing i). down (decrementing j), and up (incrementing j). Moves are possible only if the destination cell is within the grid and not an obstacle cell. Each move has a cost of 1.
In all cases, the cost-to-reach is the number of moves and the heuristic estimate of the cost-to-go you should use is the "straight-line" Manhattan distance, that is, the sum of the absolute differences in both dimensions (which is admissible because it is the cost associated with the relaxed problem involving no obstacles). For example,
h(xinit) = | iinit - igoal | + | jinit - jgoal |
(iinit,jinit)=(50,55);
(igoal,jgoal)=(75,70);
obs=zeros(100,100); % initialize to "no obstacles"
for i=1:100,
for j=1:100,
if i<50, % rear of bugtrap
d=abs(i-51)+abs(j-50);
if d==50, obs(i,j)=1; end;
else % front of bugtrap
if j>50, % upper lobe
d=abs(i-50)+abs(j-75);
if d==24, obs(i,j)=1; end;
end;
if j<50, % lower lobe
d=abs(i-50)+abs(j-25);
if d==24, obs(i,j)=1; end;
end;
end;
end;
end;
For each of the three routines, report the number of cells in closed, the number of cells on fringe, and the length of the path found. There is no need to draw/report the path.