Chapter 1 Maximum stream (being modified)

Source: Internet
Author: User
I. Summary 1. Definition

Definition 1: stream network

Definition 2: residual capacity

Definition 3: Augmented path

A network stream G = (V, E) and a stream F are known. The augmented path P is the residual network G. | a simple path from S to T in F

The maximum number of network streams that can be transmitted along each edge of P in an augmented path is the residual capacity of P, which is defined below:

C | f (p) = min {c | f (u, v): (u, v) on p}

Definition 4: Cut, net stream, capacity, minimum cut

Differences between the net stream and the capacity:

The net stream passing through (S, T) is composed of two-way positive network streams. While adding a positive network stream from S to T, it is subtracted from the positive network stream from t to S.

The capacity of cut (S, T) is calculated only by the connections from S to T. The side from t to S is not included in the calculation of C (S, T.

2. Nature

3. Theorem

Theorem 1:

Theorem 2:

Theorem 3:

Theorem 4:

Theorem 5:

Theorem 6:

For any stream F in a network stream g, its value is the capacity of any cut on the Interface of G.

Theorem 7:

 

Ii. Code version 1: Maximum stream. The graph is implemented using a matrix and the augmented path is obtained using Bellman-Ford. 1. mat_flow.h
# Include <iostream> using namespace STD; # define Nmax 210 class mat_flow {public: int N; // number of points. Where 0 is the source point and 1 is the collection point int map [Nmax] [Nmax]; // network fee int net [Nmax] [Nmax]; // The remaining network int path [Nmax]; // augmented path, path [v] = u description (u, v) int ecost [Nmax] On the augmented path; // the shortest path from the source point to each point mat_flow (INT num): n (Num) {memset (MAP, 0, sizeof (MAP);} void addsingleedge (INT start, int end, int value = 1) {map [start] [end] = value;} void makegraph (INT m); bool bellman_ford (); int max_flow () ;}; void mat_flow: makegraph (INT m) {int start, end, value; while (M --) {CIN> Star T> end> value; addsingleedge (START, end, value) ;}} bool mat_flow: bellman_ford () {int I, j; memset (path,-1, sizeof (PATH); fill (ecost, ecost + Nmax, int_max); ecost [0] = 0; bool flag = true; while (FLAG) {flag = false; for (I = 0; I <= N; I ++) {If (ecost [I] = int_max) continue; For (j = 0; j <= N; j ++) {If (net [I] [J]> 0 & ecost [I] + 1 <ecost [J]) {flag = true; ecost [J] = ecost [I] + 1; path [J] = I ;}}} return ecost [N]! = Int_max;} int mat_flow: max_flow () {int I, j; // in the initial stage, the remaining network is for (I = 0; I <= N; I ++) {for (j = 0; j <= N; j ++) net [I] [J] = map [I] [J];} int maxflow = 0; // while there exists a path P from S to T int the residual network G1 // find an augmented path from the remaining network, the augmented path exists in the path while (bellman_ford () {// do c | f (p) <-min {c | f (u, v) :( u, v) is in p} // calculate the net stream int v = N, CFP = int_max, U; while (V! = 0) {// path stores the augmented path. path [v] = u indicates that (u, v) is in the augmented path u = path [v]; CFP = min (CFP, net [u] [v]); V = u;} // update maxflow + = CFP; // update the remaining network // For each edge (u, v) in PV = N; while (V! = 0) {u = path [v]; // F [U, V] <-f [U, V] + cfpnet [u] [v]-= CFP; net [v] [u] + = CFP; // F [V, u] <-f [U, V] V = u ;}} return maxflow ;}
2. Main. cpp
#include "Mat_flow.h"/*5 100 1 160 2 131 3 121 2 102 1 43 2 92 4 143 5 204 3 74 5 4*/int main(){int n, m;while(cin>>n>>m){Mat_Flow *G = new Mat_Flow(n);G->MakeGraph(m);cout<<G->max_flow()<<endl;delete G;}return 0;}
3. Test Data

Introduction to algorithms p405 figure 26-5

4. Running result

Version 2: matrix + hlpp (height label pre-flow propulsion algorithm) 1. "mat_hlpp_flow.h"

Http://my.csdn.net/my/code/detail/50632

2. Main. cpp
#include "Mat_HLPP_Flow.h"/*5 100 1 160 2 131 3 121 2 102 1 43 2 92 4 143 5 204 3 74 5 4*/int main(){int n, m;while(cin>>n>>m){Mat_HLPP_Flow *G = new Mat_HLPP_Flow(n);G->MakeGraph(m);cout<<G->high_label_preflow_push()<<endl;delete G;}return 0;}
3. test data and results

Same as above

 

Iii. Exercise 26.1 Network Flow

26.1-1

Definition 1: If (u, v) does not belong to E, C (u, v) = 0 properties 1: f (u, v) <= C (u, v) ====> if (u, v) does not belong to e, f (u, v) = 0. Same as reverse side

26.1-2
Property 2, anti-Symmetry
26.1-3
To be resolved
26.1-4

26.1-5

(1)f(X,Y)=-f(V-X,Y)X:t   Y:v3,v4(2)f(X,Y)!=-f(V-X,Y)X:v3,v4  Y:v1,v2

26.1-6
It must meet the "anti-symmetry" and "stream conservation" and may violate the "Capacity Limit"
26.1-7

According to the 26.1-6 knowledge, AF1 + (1-A) F2 satisfies the "anti-symmetry" and "flow conservation ". Because F1 and F2 meet the "Capacity Limit", AF1 + (1-A) F2 meets the "Capacity Limit", so AF1 + (1-A) F2 is also a stream

26.1-8
To be resolved
26.1-9

Convert a map to a directed graph: (1) Each corner is used as a vertex (2) If a corner has a path to another corner, the edge of the directed graph is formed. (3) Each route forms two sides, forward and reverse. The capacity is 1 to calculate the maximum stream of the directed graph. If the maximum stream is greater than or equal to 2, "yes"

 

26.2ford-Fulkerson Method
26.2-1 Net stream: 19 Capacity: 3126.2-2 Figure 26.2-3 The minimum cut of the maximum stream is 23. The second and third offset 26.2-4c | f (u, v) + c | f (v, u) = C (u, v)-f (u, v) + C (v, u)-f (v, U) = C (u, v) + C (v, u) 26.2-5 26.2-6 is originally the biggest stream problem, to convert? Not done after 22.2-7

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.