最大流(二)――SAP算法 - 滩涂曳尾 - ITeye技术网站



求最大流有一种经典的算法,就是每次找增广路时用BFS找,保证找到的增广路是弧数最少的(即边权都为1时的最短路径),也就是所谓的Edmonds-Karp算法。可以证明的是在使用最短路增广时增广过程不超过|V|*|E|次,每次BFS的时间都是O(|E|),所以Edmonds-Karp的时间复杂度就是O(|V|*|E|^2)。
 
如果能让每次寻找增广路时的时间复杂度降下来,那么就能提高算法效率了,使用距离标号d(有时候称为"高度h")的最短增广路算法就是这样的。所谓距离标号 ,就是某个点到汇点的最少的弧的数量(即边权值为1时某个点到汇点的最短路径长度) 。设点i的标号为d[i],那么如果将满足d[i]=d[j]+1的弧(i,j)叫做允许弧 ,且增广时只走允许弧,那么就可以达到"怎么走都是最短路"的效果 。每个点的初始标号可以在一开始用一次从汇点沿所有反向边的BFS求出,实践中可以初始设全部点的距离标号为0,问题就是如何在增广过程中维护这个距离标号。

 

 

Sam评注:
(1).
    外国大牛的文章http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=maxFlowRevisited#1 中有这样一句话非常重要:"We can distance function exactly if each i in V, d[i] equals the length of the shortest path from i to t(sink) in the residual network."
    上面这句话意思是说:只有当d[i]恰好等于i到汇点t的最短路径(边权都为1)时,才称d为"距离函数"。而每次用SAP寻找增广路径初始,d[i] (i∈V)都被初始化为0。因此一开始,只有汇点的距离函数d[t]=0满足这个条件;对其他顶点,d[i]只能称为"i的距离函数值的下界/估计",因为它<真正的d[i]。于是,外国大牛又冒出这样一句话:
"It is also easy to prove that if d(s)≥|V|, then the residual network contains no path from the source to the sink."
(2).
    寻找一条最短(边最少)增广路径中用到的"递归机制",实际上保证了最短路径的层次图是从汇点向源点扩展的。而每次用SAP寻找一条增广路径开始时,d[t]=0已经是真正的最短路径,因此如果有最短增广路径,完成SAP搜索后d[i]=真正的最短路径。


Read full article from 最大流(二)――SAP算法 - 滩涂曳尾 - ITeye技术网站


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts