The terrain is generated using MATLAB code from the following link:
Cost function of the terrain is defined as the difference in altitude and it is always positive numbers.
Check the following documents for more explanations:
Bugs fixed on the termination critera
Added more comments.
Added links to download more detailed explanations.