Basics backtracking

Backtracking is a search method selected from the preferred, depth first search (traverse is simple terms) in accordance with optimal selection conditions. When searching for a certain step to find the original choice is not optimal or not reach the target, it is a step back to re-select, this dead end on the return walk technique called backtracking, and meet the conditions of a state backtracking point called " backtrack point ."

1. Algorithm thought 

 Backtracking is from the initial state, the depth-first search to give way, according to the constraint condition generated child node, the search problem solutions. When they find the current node does not satisfy the conditions for solving it back to try another path. Backtracking is a "proceeds to enter, can not enter the change, the change can not be back" search method.

2. Elements algorithm 

(1) solution space:

  • Organization Solutions: Solution backtracking organization can regulate a n-tuple of {x1, x2, x3, ......, xn}, for example, a three items 0-1 knapsack problem, the solution is organized in the form: { x1, x2, x3}.
  • Significant constraint: defining a range of solution components. For example, three items 0-1 knapsack problem, organization solution is {x1, x2, x3}. Component of its solution ranges from very simple xi, xi is a 1 or a 0 indicates whether the item into the backpack.
  • Solution space: As the name suggests, is space consists of all possible solutions. as the picture shows:

Figure assumption that each point is that we are likely to be the solution, these solutions will understand the composition of space, we are now to the constraints of the problem, find the optimal solution in the solution space.

  • Solution space, the higher the search efficiency.

(2) the solution space organizational structure:

A solution space usually consists of many possible solutions, we can not clueless, blind search efficiency is very low. We may be expressed in a certain form of organization out, and then go find the optimal solution: This organization is the solution space tree:

Solution space tree just solution space image representation, facilitate the understanding of the search process when the image of problem-solving, rather than generate a real tree

(3) search solution space:

Implicit constraint refers to the problem of the availability of feasible solution or optimal solution constraints made.

如果不满足隐约束,就说明得不到问题的可行解或者是最优解。那就没有必要再沿着该结点的分治继续进行搜索了,相当于把这个分支都剪掉了。因此隐函数也成为剪枝函数,实质上不是剪掉该分支,而是不再搜索该分支。

例如:3个物品的0-1背包问题,如果前2个物品放入后背包超重了,那么就没有必要再考虑第三个物品是否要放入背包了。相当于是剪枝了:

3.剪枝函数 

 隐函数:也称剪枝函数,包括约束函数和限界函数。

对于能否得到问题的可行解的约束称为约束函数,对于能否获得最优解的约束称为限界函数。有了剪枝函数,我们就可以“剪掉”得不到的可行解或者是最优解的分支,避免无效搜索,提高搜索效率。剪枝函数设计的好,搜索效率就高

解空间的大小和剪枝函数的好坏都直接影响搜索效率。

在搜索解空间时,下面几个术语需要说明:

  • 扩展结点:一个正在生成孩子的结点。
  • 活结点:一个自身已生成,但孩子还没有全部生成的结点。
  • 死结点:一个所有孩子都已经生成的结点。
  • 子孙:结点E的子树上所有结点都是E的子孙。
  • 祖宗:从结点E到树根路径上的所有结点都是E的祖宗。
发布了57 篇原创文章 · 获赞 9 · 访问量 3613

Guess you like

Origin blog.csdn.net/Jayphone17/article/details/102910824