end;
procedure TForm1. Button2Click (Sender: TObject);
begin
Form1. Close;
end;
procedure TForm1. Button1Click (Sender: TObject);
var i,j,fcost: integer;
begin
Label10. Visible: =false;
Label11. Visible: =true;
Label12. Visible: =true;
Edit6. Visible: =true;
Label13. Visible: =true; Label14. Visible: =false;
Label15. Visible: =true;
Label17. Visible: =true; Button5. Visible: =true;
Edit7. Visible: =true;
Panel3. Visible: =true;
Image1. Visible: =true;
d11: =strtofloat (Edit3. text);
d22: =strtofloat (Edit4. text);
d33: =strtofloat (Edit5. text);
GroupBox3. Visible: =false;
Label1. Visible: =true;
Edit1. Visible: =true;
n: =strtoint (VertexCount. text);
ll: =strtoint (Edit2. text);
for i: =1 to n do
for j: =1 to n do begin
c [j, i]: =StrToInt (CapOfEdge. Cells [i,j]);
end;
for i: =1 to n do
for j: =1 to n do begin
qh [j, i]: =StrToInt (StringGrid3. Cells [i,j]);
end;
for i: =1 to n do
for j: =1 to n do begin
lh [j, i]: =StrToInt (StringGrid1. Cells [i,j]);
end;
for i: =1 to ll do
hij [i]: =StrToFloat (StringGrid4. Cells [i-1,0]);
for i: =1 to ll do
hi [i]: =StrToInt (StringGrid5. Cells [i-1,0]);
maxpotok1 (1,n);
// ср. поток
for i: =1 to mi-1 do
ten: =ten+potokvr [i] ;
ten1: =trunc (ten/ (mi-1));
// ср. выгода
for i: =1 to mi-1 do
loop: =loop+Fi [i] ;
loop: =loop/ (mi-1);
// матрица всех потоков
j1: =0; j2: =0;
for i: =1 to t do
begin
j: =1; j2: =j2+1; j3: =1;
while j<=n do
begin
bpp: =0;
for h1: =0 to mi do
bpp: =bpp+tt [i+n*h1,j] ;
yij [j2,j3]: =bpp/ (mi-1);
j3: =j3+1; j: =j+1;
end; end;
// усредненная матрица всех потоков
for i: =1 to n do
for j: =1 to n do
begin
y1i [i,j]: =round (yij [i,j]);
end;
i: =1; bred1: =0;
begin
for j: =1 to n do
bred1: =bred1+y1i [i,j] ;
if bred1>ten1 then begin
j: =1;
while j<=n do
begin
if (yij [i,j] -trunc (yij [i,j]) >=0.5) and (yij [i,j] -trunc (yij [i,j]) <1)
then begin y1i [i,j]: =y1i [i,j] -1; break; end
else j: =j+1; end;
end;
if bred1<ten1 then begin j: =1;
while j<=n do
begin
if (yij [i,j] -trunc (yij [i,j]) >=0.5) and (yij [i,j] -trunc (yij [i,j]) <1)
then begin y1i [i,j]: =y1i [i,j] +1; break; end
else j: =j+1
end; end;
for j: =1 to n do
y1i [j, i]: =-1*y1i [i,j] ;
end;
i: =n; bred1: =0;
begin
for j: =1 to n do
bred1: =bred1+y1i [i,j] ;
bred1: =-1*bred1;
if bred1>ten1 then begin
j: =1;
while j<=n do
begin
if (yij [i,j] -trunc (yij [i,j]) >=0.5) and (yij [i,j] -trunc (yij [i,j]) <1)
then begin y1i [i,j]: =y1i [i,j] +1; break; end
else j: =j+1;
end; end;
if bred1<ten1 then begin j: =1;
while j<=n do
begin
if (yij [i,j] -trunc (yij [i,j]) >=0.5) and (yij [i,j] -trunc (yij [i,j]) <1)
then begin y1i [i,j]: =y1i [i,j] -1; break; end
else j: =j+1
end; end;
for j: =1 to n do
y1i [j, i]: =-1*y1i [i,j] ;
end;
kon: =0;
while kon<=n-1 do
begin
bred2: =0;
i: =2+kon;
for j: =1 to n do
bred2: =bred2+y1i [i,j] ;
begin
if bred2>0 then begin j: =2+kon;
while j<=n-1 do
begin
if (yij [i,j] -trunc (yij [i,j]) >=0.5) and (yij [i,j] -trunc (yij [i,j]) <1)
then begin y1i [i,j]: =y1i [i,j] -1; break; end
else j: =j+1
end; end;
if bred2<0 then begin j: =2+kon;
while j<=n-1 do
begin
if (yij [i,j] -trunc (yij [i,j]) >=0.5) and (yij [i,j] -trunc (yij [i,j]) <1)
then begin y1i [i,j]: =y1i [i,j] +1; break; end
else j: =j+1
end; end;
for j: =2+kon to n-1 do
y1i [j, i]: =-1*y1i [i,j] ;
end;
kon: =kon+1;
end;
// поиск узких мест в сети дорог
for i: =1 to n do
for j: =1 to n do
c1 [i,j]: =y1i [i,j] -c [i,j] ;
for i: =1 to n do
for j: =1 to n do
CapOfEdge. Cells [j, i]: =floattostr (y1i [i,j]);
for i: =1 to n do
for j: =1 to n do
StringGrid3. Cells [j, i]: =Floattostr (c1 [i,j]);
edit1. text: =floattostr (loop);
edit6. text: =floattostr (ten1);
edit7. text: =floattostr (maxpotok);
loop: =0; ten1: =0;
end;
procedure TForm1. VertexCountChange (Sender: TObject);
var i,j: integer;
begin
z: =1; mi: =1;
t: =0; ss: =0;
kk: =0; k3: =1;
kol: =0; kol1: =0;
ko: =0; sum: =0;
l5: =0; l5: =0;
pp: =1; o: =1;
op: =1;
// hij [1]: =0.2; hij [2]: =0.3; hij [3]: =0.5; d33: =0.25;
// hi [1]: =4; hi [2]: =5; hi [3]: =3; d11: =0.25; d22: =0.5;
l6: =0;
if VertexCount. Text<>'' then begin
CapOfEdge. ColCount: =StrToInt (VertexCount. Text) +1;
CapOfEdge. RowCount: =StrToInt (VertexCount. Text) +1;
StringGrid3. ColCount: =StrToInt (VertexCount. Text) +1;
StringGrid3. RowCount: =StrToInt (VertexCount. Text) +1;
StringGrid1. ColCount: =StrToInt (VertexCount. Text) +1;
StringGrid1. RowCount: =StrToInt (VertexCount. Text) +1;
n: =StrToInt (VertexCount. Text);
for i: =1 to n do begin
CapOfEdge. Cells [0, i]: ='x'+IntToStr (i);
CapOfEdge. Cells [i,0]: ='x'+IntToStr (i);
end;
for i: =1 to n do
for j: =1 to n do begin
CapOfEdge. Cells [i,j]: ='0';
end;
for i: =1 to n do begin
StringGrid3. Cells [0, i]: ='x'+IntToStr (i);
StringGrid3. Cells [i,0]: ='x'+IntToStr (i);
end;
for i: =1 to n do
for j: =1 to n do begin
StringGrid3. Cells [i,j]: ='0';
end;
for i: =1 to n do begin
StringGrid1. Cells [0, i]: ='x'+IntToStr (i);
StringGrid1. Cells [i,0]: ='x'+IntToStr (i);
end;
for i: =1 to n do
for j: =1 to n do begin
StringGrid1. Cells [i,j]: ='0';
end;
end;
end;
procedure TForm1. Button3Click (Sender: TObject);
var f: textfile; i,j,n: integer; s: string;
Begin
opendialog1. filter: ='текстовые файлы|*. txt|';
if opendialog1. execute and fileexists (opendialog1. filename)
then begin
assignfile (f,opendialog1. filename);
reset (f);
readln (f,n);
for i: =1 to n do
for j: =1 to n do begin readln (f,s);
stringgrid3. cells [j-1, i-1]: =s;
end;
for i: =1 to n do
for j: =1 to n do begin readln (f,s);
stringgrid1. cells [j-1, i-1]: =s;
end;
for i: =1 to n do
for j: =1 to n do begin readln (f,s);
Capofedge. cells [j-1, i-1]: =s;
end;
for i: =1 to n do begin readln (f,s);
stringgrid4. cells [i-1,0]: =s;
end;
for i: =1 to n do begin readln (f,s);
stringgrid5. cells [i-1,0]: =s;
end;
readln (f,s); edit3. Text: =s;
readln (f,s); edit4. Text: =s;
readln (f,s); edit5. Text: =s;
closefile (f);
end;
end;
procedure TForm1. Button4Click (Sender: TObject);
var f: textfile; i,j,n: integer;
Begin
savedialog1. filter: ='текстовые файлы|*. txt|';
n: =strtoint (VertexCount. text) +1;
ll: =strtoint (Edit2. text);
if savedialog1. execute then begin
assignfile (f,savedialog1. filename);
rewrite (f);
writeln (f,n);
for i: =1 to n do
for j: =1 to n do
writeln (f,stringgrid3. cells [j-1, i-1]);
for i: =1 to n do
for j: =1 to n do
writeln (f,stringgrid1. cells [j-1, i-1]);
for i: =1 to n do
for j: =1 to n do
writeln (f,Capofedge. cells [j-1, i-1]);
for i: =1 to n do
writeln (f,stringgrid4. cells [i-1,0]);
for i: =1 to n do
writeln (f,stringgrid5. cells [i-1,0]);
writeln (f,edit3. text);
writeln (f,edit4. text);
writeln (f,edit5. text);
closefile (f);
end;
end;
procedure TForm1. Edit2Change (Sender: TObject);
begin
ll: =StrToInt (Edit2. Text);
StringGrid4. ColCount: =StrToInt (Edit2. Text);
StringGrid5. ColCount: =StrToInt (Edit2. Text);
end;
procedure TForm1. Button5Click (Sender: TObject);
begin
StringGrid3. Visible: =false;
Label11. Visible: =false;
GroupBox4. Visible: =false;
for i: =1 to n do
for j: =1 to n do
if c1 [i,j] <0 then c2 [i,j]: =c [i,j] + (-1) *c1 [i,j] ;
for i: =1 to n do
for j: =1 to n do
CapOfEdge. Cells [j, i]: =floattostr (c2 [i,j]);
for i: =1 to n do
for j: =1 to n do
end;