Algorithm din Binciken Heuristic hanya ce ta bincike mai hankali a cikin Java shirye-shirye wanda ya dogara da yin amfani da kimanta bayanai(ilimi) don jagorantar tsarin bincike. Heuristics hanya ce ta kusantar warware matsalolin bisa ga rashin sani da kiyasin bayanai game da halin da matsalar ke ciki.
Yadda Algorithm Bincike na Heuristic ke Aiki
Algorithm din Binciken Heuristic yana amfani da ayyukan heuristic don kimanta "kusanci" na jiha zuwa manufa. A yayin kowane binciken bincike, algorithm ɗin yana zaɓar jagorar bincike bisa ƙima mai ƙima na yuwuwar jihohi. Manufar ita ce inganta ƙimar heuristic, wanda ke haifar da kusan mafita ga matsalar.
Fa'idodi da Rashin Amfanin Algorithm Neman Heuristic
Amfani:
- Binciken hankali: Algorithm yana amfani da ƙididdigan ilimi don jagorantar bincike, inganta lokaci da albarkatu.
- Aiwatar da fa'ida: Heuristics ana iya amfani da su ga haɓakawa daban-daban da matsalolin bincike a cikin al'amuran duniya na gaske.
Rashin hasara:
- Rashin daidaituwa mai yuwuwa: Heuristics dogara ga ƙima da yuwuwar bayanan da ba daidai ba, yana haifar da ingantattun mafita.
Misali da Bayani
Misali na gama-gari na Heuristic Search algorithm shine A* algorithm, wanda aka yi amfani dashi don nemo mafi guntuwar hanya akan taswira. Bari mu ga yadda wannan algorithm ke aiki:
import java.util.*;
class Node {
int x, y;
int cost, heuristic;
Node(int x, int y, int cost, int heuristic) {
this.x = x;
this.y = y;
this.cost = cost;
this.heuristic = heuristic;
}
}
public class HeuristicSearchExample {
static int heuristic(int x, int y, int targetX, int targetY) {
return Math.abs(targetX- x) + Math.abs(targetY- y);
}
static void heuristicSearch(int[][] grid, int startX, int startY, int targetX, int targetY) {
PriorityQueue<Node> pq = new PriorityQueue<>((a, b) ->(a.cost + a.heuristic)-(b.cost + b.heuristic));
pq.offer(new Node(startX, startY, 0, heuristic(startX, startY, targetX, targetY)));
while(!pq.isEmpty()) {
Node current = pq.poll();
int x = current.x;
int y = current.y;
if(x == targetX && y == targetY) {
System.out.println("Found target at(" + x + ", " + y + ")");
return;
}
// Explore neighboring nodes and add to the priority queue
// based on total cost and heuristic
// ...
}
}
}
A cikin misalin da ke sama, muna amfani da A* algorithm don nemo hanya mafi guntu akan taswira. Ana bincika nodes maƙwabta bisa ga jimillar kuɗin kurmin na yanzu da ƙiyasin heuristic. Sakamakon shine gano hanya mafi guntu daga wurin farawa zuwa maƙasudin manufa.