⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 很好运筹学的DEOPHI原代码.包括动态规划,原始单纯形法,对策论,决策论等
💻 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;
    StringGrid2: TStringGrid;
    Label4: 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,b:array2;  //a,b为二维实型的数组类型变量
  c,d:array1;  //c,d为一维实型的数组类型变量
  e:array10;  //e为一维整型的数组类型变量

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控件的列数(包括固定列)
  stringgrid2.RowCount:=m+1;  //stringgrid2控件的行数(包括固定行)
  stringgrid2.ColCount:=n+1;  //stringgrid2控件的列数(包括固定列)
  for i:=1 to m do
  begin
    stringgrid1.Cells[0,i]:='A'+inttostr(i);  //在stringgrid1的边框上写上行标(即方案编号)
    stringgrid2.Cells[0,i]:='A'+inttostr(i);  //在stringgrid2的边框上写上行标(即方案编号)
  end;
  for j:=1 to n do
  begin
    stringgrid1.Cells[j,0]:='s'+inttostr(j);  //在stringgrid1的边框上写上列标(即状态编号)
    stringgrid2.Cells[j,0]:='s'+inttostr(j);  //在stringgrid2的边框上写上列标(即状态编号)
  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]);
               //将stringgrid1中所输入的矩阵数据即益损矩阵映射到二维数组中
    end;
end;

procedure TForm1.BitBtn4Click(Sender: TObject);
begin
  if radiobutton1.Checked then      //当决策目标为效益最大时
  begin
    for j:=1 to n do
    begin
      c[j]:=a[j,1];
      for i:=1 to m do
        if a[j,i]>c[j] then c[j]:=a[j,i];  //c[j]是第j列中的最大值
    end;
    for j:=1 to n do
      for i:=1 to m do
        b[j,i]:=c[j]-a[j,i];  //b[j,i]是a[j,i]的后悔值
  end;

  if radiobutton2.Checked then          //当决策目标为损失最小时
  begin
    for j:=1 to n do
    begin
      c[j]:=a[j,1];
      for i:=1 to m do
        if a[j,i]<c[j] then c[j]:=a[j,i];  //c[j]是第j列中的最小值
    end;
    for j:=1 to n do
      for i:=1 to m do
        b[j,i]:=a[j,i]-c[j];  //b[j,i]是a[j,i]的后悔值
  end;
  for j:=1 to n do
    for i:=1 to m do
  stringgrid2.Cells[j,i]:=floattostr(b[j,i]);  //stringgrid2中所显示的是原益损矩阵a的后悔值矩阵
  stringgrid2.Refresh;  //刷新stringgrid2中的值

  //以下是当决策目标为效益最大时的程序。
  edit3.Text:='  ';
  for i:=1 to m do
  begin
    d[i]:=b[1,i];
    for j:=1 to n do
      if b[j,i]>d[i] then d[i]:=b[j,i];  //d[i]是b矩阵中第i行的最大值即最大机会损失值。
    edit3.text:=edit3.Text+' '+floattostr(d[i]);  //输出后悔矩阵中各行的最大机会损失值
  end;

  k:=1;
  e[k]:=1;
  s:=d[1];
  edit4.Text:='';
  for i:=2 to m do
  begin
    if d[i]=s then
    begin
      e[k+1]:=i;
      k:=k+1;
    end;

    if d[i]<s then
    begin
      s:=d[i];
      e[1]:=i;
      k:=1;
    end;
  end;
    //求出各行最大值中的最小值s 及其对应的行号e[k]
  l:=k;
  edit4.Text:='   '+floattostr(s);  //输出最小机会损失值

  edit5.Text:='';
  for k:=1 to l do
    edit5.Text:=edit5.text+'  '+'方案'+inttostr(e[k]);  //输出最佳方案号
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -