
theorem Th18:
  for G being _finite natural-weighted WGraph, EL being
FF:ELabeling of G, source,sink being set st EL has_valid_flow_from source,sink
& not ex P being Path of G st P is_Walk_from source,sink & P is_augmenting_wrt
  EL holds EL has_maximum_flow_from source,sink
proof
  let G be _finite natural-weighted WGraph, EL be FF:ELabeling of G, source,
  sink be set;
  assume that
A1: EL has_valid_flow_from source,sink and
A2: not ex P being Path of G st P is_Walk_from source,sink & P
  is_augmenting_wrt EL;
  reconsider src = source as Vertex of G by A1;
  set CS = AP:CompSeq(EL,src), Gn = AP:FindAugPath(EL,src);
  set Gn1 = CS.(CS.Lifespan()+1);
  reconsider V = dom Gn as Subset of the_Vertices_of G;
  set E1 = G.edgesDBetween(V, the_Vertices_of G \ V);
  set A1 = EL|E1, B1 = (the_Weight_of G)|E1;
  set e = the Element of AP:NextBestEdges(Gn);
  AP:CompSeq(EL,src) is halting by Th6;
  then
A3: Gn1 = Gn by GLIB_000:def 56;
A4: Gn1 = AP:Step(Gn) by Def12;
A5: now
    assume
A6: AP:NextBestEdges(Gn) <> {};
    now
      per cases by A6,Def9;
      suppose
A7:     e is_forward_edge_wrt Gn;
        then (the_Source_of G).e in V;
        then
A8:     Gn = Gn+*((the_Target_of G).e .--> e) by A4,A3,A6,Def10;
        not (the_Target_of G).e in V by A7;
        hence contradiction by A8,Lm2;
      end;
      suppose
        e is_backward_edge_wrt Gn;
        then
A9:     not (the_Source_of G).e in V;
        then Gn = Gn+*((the_Source_of G).e .--> e) by A4,A3,A6,Def10;
        hence contradiction by A9,Lm2;
      end;
    end;
    hence contradiction;
  end;
A10: now
    let x be set;
    assume
A11: x in E1;
    then
A12: A1.x = EL.x by FUNCT_1:49;
A13: x DSJoins V, the_Vertices_of G \ V, G by A11,GLIB_000:def 31;
    then (the_Target_of G).x in the_Vertices_of G \ V;
    then
A14: not (the_Target_of G).x in V by XBOOLE_0:def 5;
A15: B1.x = (the_Weight_of G).x by A11,FUNCT_1:49;
A16: (the_Source_of G).x in V by A13;
A17: now
      assume A1.x < B1.x;
      then x is_forward_edge_wrt Gn by A11,A12,A15,A16,A14;
      hence contradiction by A5,Def9;
    end;
    A1.x <= B1.x by A1,A11,A12,A15;
    hence A1.x = B1.x by A17,XXREAL_0:1;
  end;
  set E2 = G.edgesDBetween(the_Vertices_of G \ V, V);
  set A2 = EL|E2, B2 = EmptyBag E2;
  now
    let x be set;
    assume
A18: x in E2;
    then
A19: x DSJoins the_Vertices_of G \ V, V, G by GLIB_000:def 31;
    then
A20: (the_Target_of G).x in V;
    (the_Source_of G).x in the_Vertices_of G \ V by A19;
    then
A21: not (the_Source_of G).x in V by XBOOLE_0:def 5;
A22: A2.x = EL.x by A18,FUNCT_1:49;
A23: now
      assume 0 < A2.x;
      then x is_backward_edge_wrt Gn by A18,A22,A20,A21;
      hence contradiction by A5,Def9;
    end;
    B2 = E2 --> 0 by PBOOLE:def 3;
    then B2.x = 0 by A18,FUNCOP_1:7;
    hence A2.x = B2.x by A23;
  end;
  then Sum (EL | E2) = Sum B2 by GLIB_004:6;
  then
A24: Sum (EL | E2) = 0 by UPROOTS:11;
A25: not sink in dom Gn by A2,Th9;
  then EL.flow(source,sink) = Sum(EL|E1)-Sum(EL|E2) by A1,Th10,Th11;
  then EL.flow(source,sink) = Sum ((the_Weight_of G)|E1) by A10,A24,GLIB_004:6;
  then
  for X be FF:ELabeling of G st X has_valid_flow_from source,sink holds X
  .flow(source,sink) <= EL.flow(source,sink) by A25,Th10,Th12;
  hence thesis by A1;
end;
