Поиск максимальных потоков в сетях

Дипломная работа - Математика и статистика

Другие дипломы по предмету Математика и статистика

p> ch:=ch+F[s1-1,i-1];

for j:=1 to pp do

begin

if C[i-1,j-1]<>0 then

output[i-1,j-1].Text := FloatToStr(F[i-1,j-1])

else

output[i-1,j-1].Text := ;

end;

end;

max.Text := FloatToStr(ch);

end;

//----------------------------------------------------

procedure TForm1.Button2Click(Sender: TObject);

const p1=10;

var InG,InV,OutG,OutV :array[1..p1] of TStaticText;

i,pp,j: byte;

input,output:array[1..p1,1..p1] of TEdit;

begin

SSS.Text:=;

TTT.Text:=;

max.Text:=;

pp:=StrToInt(Col.Text);

SetLength(F,pp);

for i:=1 to pp do

begin

SetLength(F[i-1],pp);

for j:=1 to pp do

F[i-1,j-1] := 0;

end;

for i:=1 to p1 do

begin

InG[i] := FindComponent(Format(ST%d,[i])) as TStaticText;

InV[i] := FindComponent(Format(VST%d,[i])) as TStaticText;

OutG[i] := FindComponent(Format(OST%d,[i])) as TStaticText;

OutV[i] := FindComponent(Format(OVST%d,[i])) as TStaticText;

if i<=pp then

begin

InG[i].Visible:=true;

InV[i].Visible:=true;

OutG[i].Visible:=true;

OutV[i].Visible:=true;

end

else

begin

InG[i].Visible:=false;

InV[i].Visible:=false;

OutG[i].Visible:=false;

OutV[i].Visible:=false;

end;

for j:=1 to p1 do

begin

input[i,j] := FindComponent(Format(In%d%d,[i,j])) as TEdit;

output[i,j] := FindComponent(Format(E%d%d,[i,j])) as TEdit;

if (i<=pp) and (j<=pp) then

begin

input[i,j].Visible:=true;

output[i,j].Visible:=true;

input[i,j].Text:=;

output[i,j].Text:=;

end

else

begin

input[i,j].Visible:=false;

output[i,j].Visible:=false;

end;

end;

end;

 

end;

 

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

var

i, cavb : 0..255;

begin

if AlphaBlend=False then

begin

AlphaBlendValue:=255;

AlphaBlend:=True;

end;

cavb:=AlphaBlendValue;

 

for i := cavb downto 0 do

begin

AlphaBlendValue := i;

Application.ProcessMessages;

end

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

Form1.Height:=600;

Form1.Width:=800;

end;

 

procedure TForm1.Button3Click(Sender: TObject);

var i,j: integer;

del:double;

C: array of array of double;

N,S: array of ibool;

a:ibool;

pp,s1,t1,x: byte;

input,output:array of array of TEdit;

begin

p1.Text :=;

p2.Text :=;

p3.Text :=;

p4.Text :=;

pp:=StrToInt(col.Text);

SetLength(input,pp);

SetLength(output,pp);

SetLength(C,pp);

SetLength(P,pp);

SetLength(N,pp);

SetLength(S,pp);

for i:=0 to pp-1 do

begin

SetLength(input[i],pp);

SetLength(output[i],pp);

SetLength(C[i],pp);

end;

for i:=1 to pp do

for j:=1 to pp do

begin

input[i-1,j-1]:=FindComponent(Format(In%d%d,[i,j])) as TEdit;

output[i-1,j-1]:=FindComponent(Format(E%d%d,[i,j])) as TEdit;

if input[i-1,j-1].Text<> then C[i-1,j-1]:=StrToFloat(input[i-1,j-1].Text)

else C[i-1,j-1]:=0;

end;

s1 := StrToInt(SSS.Text[2]);

if (s1=1) and (length(SSS.Text)=3) then

s1:=10;

t1 := StrToInt(TTT.Text[2]);

if (t1=1) and (length(TTT.Text)=3) then

t1:=10;

 

for i:=1 to pp do

begin

S[i-1] := 0;

N[i-1] := 0;

with P[i-1] do

begin

//s := null;

//n := nil;

delta := 0;

end;

end;

S[s1-1]:=1;

with P[s1-1] do

begin

s:=plus;

n:=s1;

end;

repeat

a:=0; {признак расширения S}

for i:=1 to pp do

begin

if (S[i-1]=1) and (N[i-1]=0) then

begin

for j:=1 to pp do

begin

if C[i-1,j-1]<>0 then

begin

if (S[j-1]=0) and (F[i-1,j-1] < C[i-1,j-1]) then

begin

S[j-1] := 1;

with P[j-1] do

begin

s := plus;

n := i;

if i=s1 then delta := C[i-1,j-1] - F[i-1,j-1]

else delta := min(P[i-1].delta,C[i-1,j-1] - F[i-1,j-1]);

end;

a := 1;

end;

end;

if C[j-1,i-1]<>0 then

begin

if (S[j-1]=0) and (F[j-1,i-1]>0) then

begin

S[j-1] := 1;

with P[j-1] do

begin

s := minus;

n := i;

if i=s1 then delta := F[j-1,i-1]

else delta := min(P[i-1].delta,F[j-1,i-1]);

end;

a:=1;

end;

end;

end;

N[i-1] := 1;

end;

end;

if S[t1-1]<>0 then

begin

x:=t1;

del:=P[t1-1].delta;

while x<>s1 do

begin

if P[x-1].s=plus then

F[P[x-1].n-1,x-1]:=F[P[x-1].n-1,x-1]+del

else

F[x-1,P[x-1].n-1]:=F[x-1,P[x-1].n-1]-del;

x:=P[x-1].n

end;

Break;

end;

until a=0;

for i:=1 to pp do

begin

for j:=1 to pp do

begin

if C[i-1,j-1]<>0 then

output[i-1,j-1].Text := FloatToStr(F[i-1,j-1])

else

output[i-1,j-1].Text := ;

end;

end;

end;

 

procedure TForm1.Button4Click(Sender: TObject);

var s1,ver: byte; // Вершина

begin

p4.Font.Name := MS Sans Serif;

ver := StrToInt(p1.Text[2]);

if (ver=1) and (length(p1.Text)=3) then

ver:=10;

s1 := StrToInt(SSS.Text[2]);

if (s1=1) and (length(SSS.Text)=3) then

s1:=10;

if P[ver-1].s=plus then p3.Text := +

else p3.Text := -;

p2.Text := x + IntToStr(P[ver-1].n);

if ver<>s1 then

p4.Text := FloatToStr(P[ver-1].delta)

else

begin

p4.Font.Name :=Symbol;

p4.Text := Ґ;

end;

end;

 

procedure TForm1.Button5Click(Sender: TObject);

var pp,i,j : integer;

output:array of array of TEdit;

begin

pp:=StrToInt(Col.Text);

SetLength(F,pp);

SetLength(output,pp);

for i:=1 to pp do

begin

SetLength(output[i-1],pp);

SetLength(F[i-1],pp);

for j:=1 to pp do

begin

F[i-1,j-1] := 0;

output[i-1,j-1]:=FindComponent(Format(E%d%d,[i,j])) as TEdit;

output[i-1,j-1].Text := ;

end;

end;

end;

 

end.