Bài toán quy hoạch tuyến tính đa mục tiêu - Tài liệu tham khảo

end;
if i4=n-1 then
begin
f2.grdkq.Cells[0,i5-1]:='d'
+inttostr(i5);
for i:=1 to n do
f2.grdkq.cells[i,i5-1]
:=floattostr(w[i]);
i5:=i5+1;
end;
end;
End;
end;
{-------------------------------------------------}
procedure Tf1.ButtonthoatClick(Sender: TObject);
begin
close;
end;
{---------------------------------------------------};
procedure Tf1.NewInput1Click(Sender: TObject);
var i,j:integer;
begin
redit1.Visible:=false;
redit2.Visible:=false;
{ Show bằng edit new data}
txtn.Text:='';
95
txtm.Text:='';
txtsd.Text:='';
for i:=1 to 10 do
for j:=1 to 10 do
grdab.Cells[i,j]:='';
for i:=1 to 10 do
for j:=1 to 10 do
grddinh.Cells[i,j]:='';
for j:=0 to 10 do
grdb.Cells[1,j]:='';
for i:=0 to 10 do
gridaffine.Cells[i,1]:='';
grdb0.Cells[1,0]:='';
end;
{-------------------------------------------------}
procedure Tf1.OpenInput1Click(Sender: TObject);
var f:textfile;
i,j:integer;
begin
{open file}
If OpenDialog1.execute then
Tenfile:= OpenDialog1.FileName;
assignfile(f,tenfile);
reset(f);
readln(f,n,m,sd);
grdAB.ColCount:=n+1;
grdAB.RowCount:=m+1 ;
96
grdAB.Cells[0,0]:='A';
for i:= 1 to n do
grdAB.Cells[i,0]:=inttostr(i);
for i:= 1 to m do
grdAB.Cells[0,i]:=inttostr(i);
grdb.RowCount:=m;
for i:=0 to m-1 do
grdb.Cells[0,i]:='b'+ inttostr(i+1)+' =';
gridaffine.ColCount:=n;
for i:=0 to n-1 do
gridaffine.Cells[i,0]:='a'+inttostr(i);
grdDinh.ColCount:=n+1;
grdDinh.RowCount:=sd+1;
grdDinh.Cells[0,0]:='d';
for i:= 1 to n do
grdDinh.Cells[i,0]:=inttostr(i);
for i:= 1 to sd do
grdDinh.Cells[0,i]:=inttostr(i);
redit1.Visible:=false;
redit2.Visible:=false;
txtn.Text:=inttostr(n);
txtm.Text:=inttostr(m);
txtsd.Text:=inttostr(sd);
for i:=1 to m do
begin
for j:=1 to n do
read(f,a[i,j]);
97
readln(f,b[i]);
end;
for i:=1 to n do read(f,a0[i]);
readln(f,b0);
for i:=1 to sd do
begin
for j:=1 to n do
read(f,d[i,j]);
readln(f);
end;
closefile(f);
{Hiện ma trận ràng buộc}
for i:=1 to m do
for j:=1 to n do
grdab.Cells[j,i]:=floattostr(a[i,j]);
for i:=0 to m-1 do grdb.Cells[1,i]:=floattostr(b[i+1]);
{Hiện hàm affine}
for i:=0 to n-1 do gridaffine.Cells[i,1]:=floattostr(a0[i+1]);
grdb0.Cells[1,0]:=floattostr(b0);
{Hiện ma trận tập dỉnh}
for i:=1 to sd do
for j:=1 to n do
grddinh.Cells[j,i]:=floattostr(d[i,j]);
{Show data trong Tenfile}
end;
98
procedure Tf1.SaveInput1Click(Sender: TObject);
var f:textfile;
i,j:integer;
begin
{If Tenfile <>'' then save data vao Tenfile
else dung save as }
{If SaveDialog1.Execute then
Tenfile:=SaveDialog1.FileName;
SaveDialog1.FileName:=tenfile;
{Save data vao ten file}
if tenfile='' then
if savedialog1.Execute then
tenfile:=savedialog1.FileName;
assignfile(f,tenfile);
rewrite(f);
n:=strtoint(txtn.Text);
m:=strtoint(txtm.Text);
sd:=strtoint(txtsd.Text);
writeln(f,n,m:6,sd:6);
for i:=1 to m do
for j:=1 to n do
a[i,j]:=strtofloat(grdab.Cells[j,i]);
for i:=0 to m-1 do b[i+1]:=strtofloat(grdb.Cells[1,i]);
for i:=0 to n-1 do
a0[i+1]:=strtofloat(gridaffine.Cells[i,1]);
b0:=strtofloat(grdb0.Cells[1,0]);
for i:=1 to sd do
for j:=1 to n do
d[i,j]:=strtofloat(grddinh.Cells[j,i]);
for i:=1 to m do
99
begin
for j:=1 to n do
write(f,a[i,j]:10:2);
writeln(f,b[i]:10:2);
end;
for i:=1 to n do write(f,a0[i]:10:2);
writeln(f,b0:10:2);
for i:=1 to sd do
begin
for j:=1 to n do
write(f,d[i,j]:10:2);
writeln(f);
end;
closefile(f);
end;
procedure Tf1.Saveas1Click(Sender: TObject);
Var f:textfile;
i,j:integer;
begin
If SaveDialog1.Execute then
Tenfile:=SaveDialog1.FileName;
SaveDialog1.FileName:=tenfile;
assignfile(f,tenfile);
rewrite(f);
n:=strtoint(txtn.Text);
m:=strtoint(txtm.Text);
sd:=strtoint(txtsd.Text);
writeln(f,n,m:6,sd:6);
100
for i:=1 to m do
for j:=1 to n do
a[i,j]:=strtofloat(grdab.Cells[j,i]);
for i:=0 to m-1 do b[i+1]:=strtofloat(grdb.Cells[1,i]);
for i:=0 to n-1 do
a0[i+1]:=strtofloat(gridaffine.Cells[i,1]);
b0:=strtofloat(grdb0.Cells[1,0]);
for i:=1 to sd do
for j:=1 to n do
d[i,j]:=strtofloat(grddinh.Cells[j,i]);
for i:=1 to m do
begin
for j:=1 to n do
write(f,a[i,j]:10:2);
writeln(f,b[i]:10:2);
end;
for i:=1 to n do write(f,a0[i]:10:2);
writeln(f,b0:10:2);
for i:=1 to sd do
begin
for j:=1 to n do
write(f,d[i,j]:10:2);
writeln(f);
end;
closefile(f);
end;
{---------------------------------------------------}
procedure Tf1.Show1Click(Sender: TObject);
begin
101
If OpenDialog2.Execute then
TenKetqua:=Opendialog2.FileName;
{ Show Ket qua}
end;
{------------------------------------------------}
procedure Tf1.Run1Click(Sender: TObject);
var
Ud,Ua:intmt;
vt1,vt2,vt3,w:vt;
j,k,i,i1,i2,i3,i4,i5,bi,tt:integer;
gt:real;
begin
f2.grdkq.Show;
f2.l1.Show;
for i:=1 to m do
for j:=1 to n do
A[i,j]:=strtofloat(grdAB.Cells[j,i]);
for i:= 0 to m-1 do
b[i+1]:=strtofloat(grdb.Cells[1,i]);
for i:= 0 to n-1 do
A0[i+1]:=strtofloat(gridaffine.Cells[i,1]);
b0:=strtofloat(grdb0.Cells[1,0]);
for i:= 1 to sd do
for j:=1 to n do
d[i,j]:=strtofloat(grdDinh.Cells[j,i]);
f2.grdkq.ColCount:=n+1;
f2.grdkq.RowCount:=m+sd;
f2.grdkq.DefaultColWidth:=80;
102
for i:=0 to (m+sd) do
for j:=0 to n do
f2.grdkq.Cells[j,i]:='';
f2.Show;
tinh_tap_U(d,Ua,Ud,j,k);
If j=1 then {điều kiện Ud bằng rỗng}
Begin
f2.l1.Hide;
for i1:=1 to sd do
begin
f2.grdkq.Cells[0,i1-1]:='d '+inttostr(i1);
for i2:=1 to n do
f2.grdkq.cells[i2,i1-1]
:=floattostr(d[i1,i2]);
end;
End;
If k=1 then {điều kiện Ua bằng rỗng}
begin
i5:=1;
if j-1=sd then {điều kiện Ud=U}
begin
f2.grdkq.Hide;
f2.l1.Show;
end
else
begin
f2.l1.Hide;
For i:=1 to sd do
Begin
for i1:=1 to j-1 do
103
if Ud[i1]=i then
begin
tt:=i1; {đề phong phần tử Ud[1]=i}
break;
end
else tt:=i1;
if tt=j-1 then
if i<>Ud[tt] then
begin
f2.grdkq.Cells[0,i5-1]
:='d '+inttostr(i5);
for i2:=1 to n do
f2.grdkq.cells[i2,i5-1]:=floattostr(d[i,i2]);
i5:=i5+1;
end;
End;
End;
end;
If (j<>1) and (k<>1) then {điều kiện Ua & Ud khác rỗng}
Begin
f2.l1.Hide;
i5:=1;
For i:=1 to sd do
Begin
for i1:=1 to j-1 do
if Ud[i1]=i then
begin
tt:=i1;
break ;
end
104

Tài liệu liên quan

Tài liệu mới nhất