Heuristic function

Here we can the linear distance between the vertex with the end point, i.e. the Euclidean distance, to estimate the approximate length of this path with the apex end (Note: with a straight line path length is the distance between the two concepts). We call this distance denoted h (i) (i indicates that the number of vertices), a professional, it is called heuristic function (heuristic function). Because the formula for calculating the Euclidean distance, square root calculation involves time-consuming, so we usually by another more simple distance formula, that is, from Manhattan (Manhattan distance). Is the Manhattan distance between two points in the horizontal and vertical coordinates and distance. The calculation process involves only addition and subtraction, the sign bit inverted, it is more efficient than the Euclidean distance.

int hManhattan (Vertex v1, Vertex v2) {// Vertex of vertices, defined behind

  return Math.abs(v1.x - v2.x) + Math.abs(v1.y - v2.y);

}

The original length of the path simply by g (i) between the apex and origin, to determine who should the queue, there is now the path length to estimate the apex end, we sum both by f (i) = g ( i) + h (i), which determines the vertex of the first queue. Comprehensive two parts, we can avoid just said "deviation." Where f (i) it is called professional valuation function (evaluation function).

Guess you like

Origin www.cnblogs.com/yuanjiangw/p/12038321.html