Use heuristic search in Java to solve problems faster

Source: Internet
Author: User
Tags garbage collection requires

Understand a popular artificial intelligence search algorithm Java implementation

To solve the problem by searching the feasible solution space is a basic technique called state space search in artificial intelligence. Heuristic search is a form of state space search that utilizes knowledge about a problem to find solutions more efficiently. Heuristic search has won numerous honors in various fields. In this article, we'll introduce you to the heuristic search area and show you how to implement a * with the Java programming language, the most widely used heuristic search algorithm. Heuristic search algorithm has put forward higher requirements for computing resources and memory. We will also show how to avoid expensive garbage collection and how to leverage an alternative High-performance Java Collection Framework (JCF) to improve Java implementation. All of the code in this article can be obtained from the download section.

Heuristic Search

Many problems in computer science can be represented by a graphical data structure in which paths in the graph represent potential solutions. Finding the optimal solution requires finding a shortest path. For example, take an autonomous video game role. Each action made by a character corresponds to an edge in the graph, and the goal of the role is to find the shortest path and play against the opponent's role.

Depth-first search and breadth-first search algorithms are popular graphics traversal algorithms. But they are considered not heuristic algorithms and are often severely constrained by the scale of the problems they can solve. Furthermore, it is not guaranteed that depth-first search can find the optimal solution (or any solution in some cases), and that breadth-first search can only find the optimal solution in exceptional cases. Heuristic search, by contrast, is a kind of suggestive search that uses knowledge about a problem to encode in a heuristic way to solve the problem more efficiently. Heuristic search can solve many problems that cannot be solved by non heuristic algorithm.

Video game routing is a popular area of heuristic search, and it can solve more complex problems. The winner of the "DARPA City Challenge", an unmanned car race held in 2007, used heuristic search to plan flat, direct, and accessible routes. Heuristic search has also been applied successfully in natural language processing, which is used in the parsing of text and stack decoding in speech recognition. It is also used in the field of robotics and bioinformatics. Compared with traditional dynamic programming methods, using heuristic search can solve multiple sequence alignment (multiple Sequence alignment, MSA) faster with less memory, which is an in-depth study of the problem of informatics.

Heuristic Search via Java

The Java programming language is not a popular choice for heuristic search because it requires a high amount of memory and computing resources. C + + is usually the preferred language for performance reasons. We will prove that Java is an appropriate programming language for heuristic search. We begin by showing that the textbook implementation of a * is really slow and runs out of available memory when addressing the popular benchmark problem set. We address these performance issues by revisiting some of the key implementation details and leveraging alternative JCF.

Much of this work is an extension of the work published in an academic paper co-authored by the author of this article. Although the original focus is on C + + programming, here we show many of the same concepts that apply to Java.

Breadth First Search

Familiarity with breadth-first search (a simpler algorithm that shares many of the same concepts and terminology) will help you understand the details of implementing heuristic search. We will use a proxy-centric view of breadth-first search. In a proxy-centric view, the agent is said to be in some state and can get a set of applicable actions from that state. An application action converts an agent from its current state to a new successor State. This view is available for many types of problems.

The goal of breadth-first search is to design a series of actions to boot the agent from its initial state to a target state. Starting from the initial state, breadth-first Search first accesses the newly generated state. All applicable operations can be applied in each access state, generate a new state, and the state is added to the list of unread states (also known as the front of the search). The process of accessing the State and generating all subsequent states is called extending the state.

You can consider the search process as generating a tree: the root node of the tree represents the initial state, and the child nodes are connected by the edges, which represent the actions that are used to build them. Figure 1 shows a diagram of the search tree. The white circle represents the node of the search frontier. A gray circle represents a node that has been expanded.

Figure 1. Breadth-First search order on binary tree

Each node in the search tree represents a state, but two distinct nodes can represent the same state. For example, a node in a search tree with a different depth can have the same state as another node in the higher layer of the tree. These repeating nodes represent two different ways to achieve the same state in a search problem. There may be a problem with the repeating node, so all the visited nodes must be remembered.

Listing 1 shows the pseudo code for breadth-first search:

Listing 1. Pseudo code for breadth-first search


breadth-first-search (initial)
loop do:
     if EMPTY (open) Then Return failure
     node←shallowest (open)
     closed←add (closed, node) for each
     action in ACTIONS (node)
          Successor←apply (Action, node)
          if successor in closed then continue
          if GOAL (successor) then return SOLUTION (nod e)
          Open←insert (open, successor)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.