📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, Buttons;
type
TForm1 = class(TForm)
Panel2: TPanel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Panel3: TPanel;
Label5: TLabel;
StringGrid1: TStringGrid;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
RadioGroup1: TRadioGroup;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Panel4: TPanel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Panel1: TPanel;
Label1: TLabel;
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type array2=array[1..99,1..99] of real; //声明一个二维实型的数组类型
type array1=array[1..99] of real; //声明一个一维实型的数组类型
type array10=array[1..99] of integer; //声明一个一维整型的数组类型
var
Form1: TForm1;
i,j,k,l,m,n:integer;
s:real;
a:array2; //a为二维实型的数组类型变量
c:array1; //c为一维实型的数组类型变量
d:array10; //d为一维整型的数组类型变量
implementation
{$R *.dfm}
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
m:=strtoint(edit1.text);
n:=strtoint(edit2.Text);
stringgrid1.RowCount:=m+1; //stringgrid1控件的行数(包括固定行)
stringgrid1.ColCount:=n+1; //stringgrid1控件的列数(包括固定列)
for i:=1 to m do
begin
stringgrid1.Cells[0,i]:='A'+inttostr(i); //在stringgrid1的边框上写上行标(即方案编号)
end;
for j:=1 to n do
begin
stringgrid1.Cells[j,0]:='s'+inttostr(j); //在stringgrid1的边框上写上列标(即状态编号)
end;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
for i:=1 to m do
begin
for j:=1 to n do
a[j,i]:=strtofloat(stringgrid1.cells[j,i]);
//将stringgrid中所输入的矩阵数据映射到二维熟组中
end;
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
if radiobutton1.Checked then //以下是对决策目标为效益最大时的程序
begin
edit3.Text:=' ';
for i:=1 to m do
begin
c[i]:=a[1,i];
for j:=1 to n do
begin
if a[j,i]>c[i] then c[i]:=a[j,i]; //c[i]是第i行中的最大值
end;
edit3.text:=edit3.Text+' '+floattostr(c[i]); //输出每一行中的最大值
end;
k:=1;
d[k]:=1;
s:=c[1];
edit4.Text:='';
for i:=2 to m do
begin
if c[i]=s then
begin
d[k+1]:=i;
k:=k+1;
end;
if c[i]>s then
begin
s:=c[i];
d[1]:=i;
k:=1;
end;
//求出各行最大值中的最大值s 和该行的行标号d[k] 要考虑重复
end;
l:=k;
edit4.Text:=' '+floattostr(s); //输出乐观法所得的最佳益损值
edit5.Text:='';
for k:=1 to l do
begin
edit5.Text:=edit5.text+' '+'方案'+inttostr(d[k]);
end;
//输出最佳方案编号
end;
//至此当决策目标为效益最大时程序结束
//以下是当决策目标为损失最小时的程序
if radiobutton2.Checked then
begin
edit3.Text:=' ';
for i:=1 to m do
begin
c[i]:=a[1,i];
for j:=1 to n do
begin
if a[j,i]<c[i] then c[i]:=a[j,i];
end;
edit3.text:=edit3.Text+' '+floattostr(c[i]);
end;
k:=1;
d[k]:=1;
s:=c[1];
edit4.Text:='';
for i:=2 to m do
begin
if c[i]=s then
begin
d[k+1]:=i;
k:=k+1;
end;
if c[i]<s then
begin
s:=c[i];
d[1]:=i;
k:=1;
end;
end;
l:=k;
edit4.Text:=' '+floattostr(s);
edit5.Text:='';
for k:=1 to l do
begin
edit5.Text:=edit5.text+' '+'方案'+inttostr(d[k]);
end;
//至此当决策目标为损失最小时程序结束
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -