
theorem Th20:
  for G being _finite real-weighted WGraph, src being Vertex of G,
  n being Nat holds DIJK:NextBestEdges(DIJK:CompSeq(src).n) = {} iff dom (
  DIJK:CompSeq(src).n)`1 = G.reachableDFrom(src)
proof
  let G be _finite real-weighted WGraph, src be Vertex of G, n be Nat;
  set DCS = DIJK:CompSeq(src), RFS = G.reachableDFrom(src);
  set Gn = DCS.n, Gn1a = DCS.(n+1);
  set BestEdges = DIJK:NextBestEdges(Gn);
  set SGn = the_Source_of G;
  set TGn = the_Target_of G;
  hereby
    assume
A1: BestEdges = {};
    now
      defpred P[set] means SGn.$1 in dom Gn`1 & not TGn.$1 in dom Gn`1;
      assume
A2:   dom Gn`1 <> RFS;
      consider BE1 being Subset of the_Edges_of G such that
A3:   for x being set holds x in BE1 iff x in the_Edges_of G & P[x]
      from SUBSET_1:sch 1;
      dom Gn`1 c= RFS by Th19;
      then
A4:   dom Gn`1 c< RFS by A2,XBOOLE_0:def 8;
      now
        DCS.0 = DIJK:Init(src) by Def11;
        then dom (DCS.0)`1 = {src};
        then
A5:     src in dom (DCS.0)`1 by TARSKI:def 1;
        assume
A6:     BE1 = {};
        consider v being object such that
A7:     v in RFS and
A8:     not v in dom Gn`1 by A4,XBOOLE_0:6;
        reconsider v as Vertex of G by A7;
        consider W being directed Walk of G such that
A9:     W is_Walk_from src, v by A7,GLIB_002:def 6;
        defpred P[Nat] means $1 is odd & $1 <= len W & not (W.$1 in dom Gn`1);
        W.(len W) = W.last() by GLIB_001:def 7
          .= v by A9,GLIB_001:def 23;
        then
A10:    ex k being Nat st P[k] by A8;
        consider k being Nat such that
A11:    P[k] & for m being Nat st P[m] holds k <= m from NAT_1:sch 5(
        A10);
A12:    dom (DCS.0)`1 c= dom Gn`1 by Th18;
        now
          per cases;
          suppose
            k = 1;
            then W.k = W.first() by GLIB_001:def 6
              .= src by A9,GLIB_001:def 23;
            hence contradiction by A5,A12,A11;
          end;
          suppose
A13:        k <> 1;
            reconsider k9=k as odd Element of NAT by A11,ORDINAL1:def 12;
            1 <= k by A11,ABIAN:12;
            then 1 < k by A13,XXREAL_0:1;
            then 1+1 < k+1 by XREAL_1:8;
            then 2*1 <= k by NAT_1:13;
            then reconsider k2a = k9-2*1 as odd Element of NAT by INT_1:5;
            set e = W.(k2a+1);
A14:        k - 2 < len W - 0 by A11,XREAL_1:15;
            then
A15:        e DJoins W.k2a, W.(k2a+2), G by GLIB_001:122;
            then
A16:        (the_Target_of G).e = W.(k2a+2);
            k2a < k - 0 by XREAL_1:15;
            then
A17:        W.(k2a) in dom Gn`1 by A11,A14;
            e in the_Edges_of G & (the_Source_of G).e = W.k2a by A15;
            hence contradiction by A3,A6,A11,A17,A16;
          end;
        end;
        hence contradiction;
      end;
      then reconsider BE1 as non empty finite set;
      deffunc F(Element of BE1) = (Gn`1).((the_Source_of G).$1) + (
      the_Weight_of G).($1);
      consider e1 being Element of BE1 such that
A18:  for e2 being Element of BE1 holds F(e1) <= F(e2) from PRE_CIRC:sch 5;
A19:  not (TGn).e1 in dom Gn`1 by A3;
A20:  e1 in the_Edges_of G by A3;
      then (TGn).e1 in the_Vertices_of G by FUNCT_2:5;
      then
A21:  (TGn).e1 in the_Vertices_of G \ dom Gn`1 by A19,XBOOLE_0:def 5;
A22:  now
        let y be set;
        assume
A23:    y DSJoins dom Gn`1, the_Vertices_of G \ dom Gn`1,G;
        then (TGn).y in the_Vertices_of G \ dom Gn`1;
        then
A24:    not (TGn).y in dom Gn`1 by XBOOLE_0:def 5;
        y in the_Edges_of G & (SGn).y in dom Gn`1 by A23;
        then y in BE1 by A3,A24;
        hence
        (Gn`1).((the_Source_of G).e1) + (the_Weight_of G).e1 <= (Gn`1).((
        the_Source_of G).y) + (the_Weight_of G).y by A18;
      end;
      (SGn).e1 in dom Gn`1 by A3;
      then e1 DSJoins dom Gn`1, the_Vertices_of G \ dom Gn`1, G by A20,A21;
      hence contradiction by A1,A22,Def7;
    end;
    hence dom (DCS.n)`1 = RFS;
  end;
  assume
A25: dom (DCS.n)`1 = RFS;
A26: Gn1a = DIJK:Step(Gn) by Def11;
  now
    assume BestEdges <> {};
    then
A27: card dom Gn1a`1 = card RFS + 1 by A26,A25,Th15;
    Segm card dom Gn1a`1 c= Segm card RFS by Th19,CARD_1:11;
    then card RFS + 1 <= card RFS + 0 by A27,NAT_1:39;
    hence contradiction by XREAL_1:6;
  end;
  hence thesis;
end;
