"Intelligent" Enumeration: Consider an optimization
problem. If the solution can be constructed step by step, we might
enumerate all possible complete solutions by
constructing a partial solution tree. Due to
the huge size of the search tree, some techniques should be employed to
prune it.
Improvement: Let's start from an
initial complete solution, and try to improve it step by
step.
若无法将问题分解,就从质量不太好的完整解出发,逐步优化
三、例题
EX1.Calculating the greatest common divisor (gcd)
求最小公约数
The greatest common divisor of two integers a and b, when at least
one of them is not zero, is the largest positive integer that divides
the numbers without a remainder.
INPUT: two n-bits numbers a, and b (a >= b)
OUTPUT: gcd(a; b)
function Euclid(a; b) if b = 0 then return a; end if return Euclid(b; a mod b);
EX2.traveling salesman problem (TSP)
周游城市的最短距离
INPUT: n cities V = {1; 2;...; n}, and a distance matrix D, where dij (1 <= i; j <= n) denotes the distance between city i and j.
OUTPUT: the shortest tour that visits each city exactly once and returns to the origin city.
function GenericImprovement(G;D) //通用,逐步迭代完整解 Let s be an initial tour; //初始解的选择很重要 while TRUE do Select a new tour s′ from the neighbourhood of s; //扰动越小越好 if s′ is shorter than s then s = s′; end if if stopping(s) then //s满足退出条件 return s; end if end while
Trial 3: Intelligent" enumeration
strategy
完整的解可以表示为n条边的排列。将边缘按照一定顺序排列,一个完整的解可以被表示为:X
= [x1, x2,..., xm]。 例如:a -> b -> c -> d -> e -> a
可以被表示为 X = [1, 0, 0, 1, 1, 0, 0, 1, 0, 1]。
所有的环游都可以写成这种形式,我们就能枚举出所有的解。
map2tree
子节点:表示一个完整的解
内部解:表示一个部分解,是一个已知item的子集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
function GenericBacktrack(P0) //枚举所有的解 Let A = fP0g. //Start with the original problem P0. Here, A denotes the active subproblems that are unexplored. best_so_far = 1; //当前知道的最短路程 while A ̸= NULL do //当还有节点要扩展时 Choose and remove a subproblem P from A; Expand P into smaller subproblems P1, P2,..., Pk; for i = 1 to k do if Pi corresponds to a complete solution then Update best_so_far if the corresponding objective function value is better; //对应一个完整解 else Insert Pi into A; //对应一个部分解 end if end for end while return best_so_far;
function IntelligentBacktrack(P0) Let A = fP0g. // Start with the original problem P0. Here A denotes the active subproblems that are unexplored. best_so_far = infinite; while A ̸= NULL do Choose a subproblem P in A with lower bound less than best_so_far; Remove P from A; Expand P into smaller subproblems P1, P2, ..., Pk, for i = 1 to k do if Pi corresponds to a complete solution then Update best so far; else if lowerbound(Pi) <= best so far then Insert Pi into A; end if end if end for end while return best_so_far;