(THIS BLOG WAS ORIGINALLY WRTITTEN IN CHINESE WITH LINK: http://www.cnblogs.com/waytofall/p/3732920.html)

Foreword: Floyd-Warshall is a classical dynamical programming algorithm for deriving shortest paths between each pair of nodes on a graph. It has n iterations (n for the number of nodes). During each iteration k,  the shortest paths for each pair of nodes with intermediate nodes numbered no more than k are derived. Since inductively, we can assume that before iteration k, the shortest paths for each pair of nodes with intermediate nodes numbered no more than k-1 are derived, the way to derive the paths with intermediate nodes numbered no more than k can be derived as:

In order to derive all the intermediate nodes on a shortest path, the algorithm maintains a predecessor matrix Π, with its element  πij denoting the node before j in the shortest path from i to j. The matrix is defined as follows:

​For more detailed specification, please refer to Introduction to Algorithms.

My problem:  for two nodes i, j of graph, there is a maximal k, such that during the kth iteration, the shortest paths dynamically programmed by the algorithm was combined by shortest paths i ~ kk ~ j, whose intermediate nodes are numbered less than k. And for the shortest paths i ~ kk ~ j, we can also have such a iteration. Therefore, the path can be visualised as follows:

​In the tree displayed above, each parent is separated by the "middle node" k, which is the maximal number of iteration that combines two paths. The shortest paths derived from the predecessor matrix are easily proved correct, but the problem is, whether the paths derived by such methods are identical to the paths displayed by the figure above? In another word, whether the paths derived demonstrate the hierarchical path construction process of Floyd-Warshall? The answer is yes. And I'm gonna prove it.

Lemma 1: If, during the kth iteration, the shortest path from i to j was derived by combining paths i ~ k, k ~ j, and we have m = πij(kand m ≠ k; then the shortest path constructed by the algorithm from i to m also are derived from combining i ~ k,  k ~ m.

Proof: Since πkj(k-1) = πij(k)= m, that is, in the path from k to j with intermediate nodes numbered no more than k, the predecessor of j is m, so we have:

                               dkj(k-1) = dkm(k-1) wmj 

wmj is the weight for edge(m, j).

Since there is an edge from m to j, from the Triangle Inequality, we have:

dij(k-1) ≤ dim(k-1) wmj                                                                          (1)

which is:

dim(k-1)  ≥  dij(k-1) wmj                                                                         (2)

From the condition of the lemma, we have:

                                dij(k-1) dik(k-1) dkj(k-1)                                                                      (3)

Subtract wmj from both sides, we have:

                                dij(k-1)  - wmj  dik(k-1) dkj(k-1)  wmj =  dik(k-1) dkm(k-1)                 (4)

Which can be transformed to:

dij(k-1)  - wmj  dik(k-1) dkm(k-1)                                                          (5)


Combining (2) and (5), we have:

                                dim(k-1)dik(k-1) dkm(k-1)                                                                   (6)

Done.

Then we are going to prove our conclusion.

Proof:  We use mathematical induction. Before the first iteration, the paths derived from the Π(0) matrix certainly meet the property.

Then, supposing that path derived from Π(k-1) meet the property, then in the kth iteration:

(1). If the shortest path from i to j does not contain node k, we have  dij(k) = dij(k-1),πij(k) = πij(k-1) = m. Applying the shortest path construction function, we can have a nodes sequence:

πij(k) = m

πim(k) = n

...

πio(k) = p

πip(k) = i

For any  πix(k) (x belongs to {m,n,...,p,i}), πix(k) ix(k-1). So we have:

πij(k) = πij(k-1) = m

πim(k) = πim(k-1) = n

...

πio(k) = πio(k-1) = p

πip(k) = πip(k-1) = i

That is, the shortest paths derived from Π(k) is identical to the shortest paths derived from Π(k-1). Since Π(k) has the propery, the path also has the property.

(2). If the shortest path from i to j contains node k, we have:

           dij(k) = dik(k-1) dkj(k-1),πij(k) = πkj(k-1)= m

and:

πij(k) = πkj(k-1) = m

πim(k) = πkm(k-1) = n

...

πio(k) = πko(k-1) = p

πip(k) = πkp(k-1) = k

That is, we enumerate the predecessor of j until we get to k. Now, all the intermediate nodes of the path from i to k are identical to the path derived from Π(k-1), so the subpath meet the property. The same for path from k to j, so the shortest paths from i to j derived from Π(k) meet the property.

Done.

最新文章

  1. jquery的ajax和jsonp的写法
  2. PHP对自己I/O流访问的封装(转)
  3. String的两种生成方式
  4. http报头正文开头会有一个整数的问题
  5. 三、python高级特性(切片、迭代、列表生成器、生成器)
  6. log4Net配置详解
  7. oracle 12g sqlplus安装
  8. linux_常用命令_(ls, lsof,nslookup)_查看文件按照时间排序
  9. ios图片剪切
  10. MyEclipse下打开ftl文件
  11. 究竟谁在绑架中国的4G政策?
  12. csrf漏洞实战演练
  13. Emacs中的代码折叠控制
  14. 迁移 Emacs 的自定义设置
  15. 发布python模块
  16. 免费的 Vue.js 入门与进阶视频教程
  17. 解决mysql从windows迁移到centos出现乱码问题
  18. WordPaster-HDwik5.0整合教程
  19. day07_雷神_面向对象进阶
  20. Sqlite 快速批量插入数据 测试

热门文章

  1. stack组件03
  2. 【集成学习】lightgbm调参案例
  3. hessian 协议 版本 兼容
  4. SQL批量插入出现 类型转换错误
  5. ios逆向工程-动态分析
  6. 一个简洁、好用的Pytorch训练模板
  7. hadoop常见错误汇总及解决办法一
  8. Jquery 点击父类全选子类 , 子类选父类
  9. gradle asciidoc 使用
  10. Python--线性代数篇