互联网IP合全局路由优化的原则-Dijkstra算法证明

周末继续写东西的一半填补了,为了达到完美的一天。
我们知道一个事实,IP地址太多。统一管理是不可能的了,无论从控制平面从数据/管理层表示,飞机是如此。

所以。IP协议被设计为可伸缩。供IP路由术语,跳路由进行计算。当然,支持“源路由”,源路由就是说数据在出发前就已经把路线规划好了,逐跳路由是IP路由的标准形式。也就是说。IP数据包是在路上即时规划路线的。
       我比較喜欢IP路由是由于这也是我旅行的方式,我喜欢旅行,可是我不喜欢事先订酒店。事先规划路线。导航等,我的方式是在路上看路牌前行。到了暂时停下的地方之后背着行囊找住处,然后走到哪算哪,这是一种说走就走且没有目的地的游荡...当然,IP数据包是有目的地的。

逐跳全局最优化

IP路由是在每一台路由器上逐跳路由的。那么就产生了一个问题。偌大一个互联网,该怎么相信这么多逐跳路由拼接起来的一条完整的路径确实是最优化的呢?答案显然是确定的。问题是怎么证明它。


路由算法

书上讲,路由算法基本分为距离矢量算法和链路状态算法,各自的协议代表作就是RIP和OSPF(我就是靠着这两个找到的第一份工作),确实是这样,可是从这些算法的正确性的证明过程中,你就会发现,确实是“逐跳的最优化路由真的就是全局的最优化路由”。

本文中我只给出基于链路状态路由协议的Dijkstra算法的证明,由于全网每台设备的链路状态数据库都是同样的。所以它是非常好理解的。


Dijkstra算法正确性证明

首先要给出Dijkstra算法正确性的证明。才干进行兴许的。毕竟。Dijkstra算法本身不过指导了step by step的操作步骤,并没没能证明这么折腾一圈得到的最短路径树中的每一条路径确实是最短的。

而要想证明逐跳全局最优化原则。须要这个事实。
       以下的示意图给出了Dijkstra算法正确性的简单证明,具体完备的数学证明能够參照这个思路:



逐跳全局最优化的问题

以下的示意图点名了逐跳全局最优化的问题所在:



逐跳全局最优化的证明

以下的示意图给出了逐跳全局最优化的简单证明。证明方式多种多样。我这里给出的不过当中一种:



附:Dijkstra算法的贪心模型

假设我们在地上倒上一杯水,观察水摊开渗透的痕迹,就会理解Dijkstra算法。它确实是不证自明的。

大自然是懒惰的,总是用最省力的方式行事。水分子在落地那个点開始,在崎岖不平的地上由于重力(暂时不考虑其他分子力)沿着一定的路径到达一系列点,这些路径一定是最短路径。我们可以粗略地级视为权重路径,这不是和Dijkstra做同样的算法模型?

版权声明:本文博主原创文章,博客,未经同意不得转载。

Inputs: [AorV] Either A or V where A is a NxN adjacency matrix, where A(I,J) is nonzero if and only if an edge connects point I to point J NOTE: Works for both symmetric and asymmetric A V is a Nx2 (or Nx3) matrix of x,y,(z) coordinates [xyCorE] Either xy or C or E (or E3) where xy is a Nx2 (or Nx3) matrix of x,y,(z) coordinates (equivalent to V) NOTE: only valid with A as the first input C is a NxN cost (perhaps distance) matrix, where C(I,J) contains the value of the cost to move from point I to point J NOTE: only valid with A as the first input E is a Px2 matrix containing a list of edge connections NOTE: only valid with V as the first input E3 is a Px3 matrix containing a list of edge connections in the first two columns and edge weights in the third column NOTE: only valid with V as the first input [SID] (optional) 1xL vector of starting points. If unspecified, the algorithm will calculate the minimal path from all N points to the finish point(s) (automatically sets SID = 1:N) [FID] (optional) 1xM vector of finish points. If unspecified, the algorithm will calculate the minimal path from the starting point(s) to all N points (automatically sets FID = 1:N) Outputs: [costs] is an LxM matrix of minimum cost values for the minimal paths [paths] is an LxM cell containing the shortest path arrays [showWaitbar] (optional) a scalar logical that initializes a waitbar if nonzero Note: If the inputs are [A,xy] or [V,E], the cost is assumed to be (and is calculated as) the point to point Euclidean distance If the inputs are [A,C] or [V,E3], the cost is obtained from either the C matrix or from the edge weights in the 3rd column of E3 Example: % Calculate the (all pairs) shortest distances and paths using [A,C] inputs n = 7; A = zeros(n); xy = 10*rand(n,2) tri = delaunay(xy(:,1),xy(:,2)); I = tri(:); J = tri(:,[2 3 1]); J = J(:); IJ = I + n*(J-1); A(IJ) = 1 a = (1:n); b = a(ones(n,1),:); C = round(reshape(sqrt(sum((xy(b,:) - xy(b',:)).^2,2)),n,n)) [costs,paths] = dijkstra(A,C) Example: % Calculate the shortest distance and path from point 3 to 5 n = 15; A = zeros(n); xy = 10*rand(n,2) tri = delaunay(xy(:,1),xy(:,2)); I = tri(:); J = tri(:,[2 3 1]); J = J(:); IJ = I + n*(J-1); A(IJ) = 1 [cost,path] = dijkstra(A,xy,3,5) gplot(A,xy,'b.:'); hold on; plot(xy(path,1),xy(path,2),'ro-','LineWidth',2) for k = 1:n, text(xy(k,1),xy(k,2),[' ' num2str(k)],'Color','k'); end Example: % Calculate the shortest distances and paths from the 3rd point to all the rest n = 7; V = 10*rand(n,2) I = delaunay(V(:,1),V(:,2)); J = I(:,[2 3 1]); E = [I(:) J(:)] [costs,paths] = dijkstra(V,E,3) Example: % Calculate the shortest distance and path from points [1 3 4] to [2 3 5 7] n = 7; V = 10*rand(n,2) I = delaunay(V(:,1),V(:,2)); J = I(:,[2 3 1]); E = [I(:) J(:)] [costs,paths] = dijkstra(V,E,[1 3 4],[2 3 5 7]) Revision Notes: (3/13/15) Previously, this code ignored edges that have a cost of zero, potentially producing an incorrect result when such a condition exists. I have solved this issue by using NaNs in the table rather than a sparse matrix of zeros.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值