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

📄 lmdfxmain.pas

📁 线性规划CAI应用程序及原代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit lmdfxmain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, Grids;

type
  Tmainlmd = class(TForm)
    StatusBar1: TStatusBar;
    cxbGrid1: TStringGrid;
    xiGrid1: TStringGrid;
    czGrid1: TStringGrid;
    bdaGrid1: TStringGrid;
    agrid1: TStringGrid;
    objlabel1: TLabel;
    objedit1: TEdit;
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Button2: TButton;
    Label2: TLabel;
    Edit3: TEdit;
    Label3: TLabel;
    Button3: TButton;
    Button4: TButton;
    Label4: TLabel;
    Label5: TLabel;
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure readdataofgrid2;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure czGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
          var CanSelect: Boolean);
    procedure calculateb;
    procedure calculatec;
    procedure calculatea;
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  mainlmd: Tmainlmd;
 ranx,rany:integer;
implementation

{$R *.DFM}
uses lpmain,lpdchxing;
function judgeifisbasevar(i:integer):boolean;
var j:integer;
begin
  judgeifisbasevar:=false;
  for j:=1 to varnum do
     if i=basevar[j] then
        judgeifisbasevar:=true;
end;
procedure Tmainlmd.calculatea;
var i:integer;
begin
  i:=i;{狗屁}
end;
procedure Tmainlmd.calculatec;
var i:integer;
    cvalue,maxvalue,minvalue:real;
    k:integer;{k为最优解时的基变量在单纯型表中的行号}
begin
if judgeifisbasevar(ranx) then{真表示是基变量}
 begin
  minvalue:=0;
  maxvalue:=0;
  for i:=1 to afterleashnum do{find k}
     begin
       if cxbgrid1.cells[1,i-1]='X'+inttostr(ranx) then
          k:=i;
     end;
  for i:=1 to afterleashnum do
    begin
     if strtofloat(agrid1.cells[i-1,k-1])<>0 then
        cvalue:=strtofloat(czgrid1.cells[i-1,1])/strtofloat(agrid1.cells[i-1,k-1])
     else
        cvalue:=1000000;
     if cvalue<minvalue then
          minvalue:=cvalue;
     if cvalue>maxvalue then
         maxvalue:=cvalue;
    end;{end of for }
 if not studymode then
  begin
  if cvalue=1000000 then
    edit3.text:='M'
  else
  edit3.text:=floattostr(minvalue);
  if cvalue=-1000000 then
    edit2.text:='-M'
  else
    edit2.text:=floattostr(maxvalue);
  end
 else{if not studymode=true then}
  begin
   if (edit3.text='') or (edit2.text='') then
     showmessage('请输入答案')
   else
      if (edit3.text=copy(floattostr(minvalue),1,5)) and (edit2.text=copy(floattostr(maxvalue),1,5)) then
              showmessage('您的回答正确,恭喜!')
      else
              showmessage('请您再仔细想一下吧。');

  end;

   end {end of if }
else{当前的不是基变量}
  begin
   if not studymode then
    begin
    edit3.text:='-M';
    edit2.text:=floattostr((-1)*strtofloat(czgrid1.Cells[ranx-1,1]));
    end
   else
    begin
     if (edit3.text='') or (edit2.text='') then
        showmessage('请输入答案')
     else
      if (edit3.text=copy(floattostr(minvalue),1,5)) and (edit2.text=copy(floattostr(maxvalue),1,5)) then
              showmessage('您的回答正确,恭喜!')
      else
              showmessage('请您再仔细想一下吧。');


    end;
  end;


end;
procedure Tmainlmd.calculateb;
var i:integer;bvalue,maxvalue,minvalue:real;
begin
  minvalue:=0;
  maxvalue:=0;
  for i:=1 to afterleashnum do
    begin
     bvalue:=(-1)*strtofloat(cxbgrid1.cells[2,i])/strtofloat(agrid1.cells[ranx+varnum-1,i-1]);
     if bvalue<minvalue then
          minvalue:=bvalue;
     if bvalue>maxvalue then
         maxvalue:=bvalue;
    end;
  if studymode then
   begin
      if (edit3.text=copy(floattostr(minvalue),1,5)) and (edit2.text=copy(floattostr(maxvalue),1,5)) then
              showmessage('您的回答正确,恭喜!')
      else
              showmessage('请您再仔细想一下吧。');

   end
  else{不是学习模式}
   begin
    edit3.text:=floattostr(minvalue);
    edit2.text:=floattostr(maxvalue);
   end;
end;
procedure Tmainlmd.Button2Click(Sender: TObject);
begin
if pos('q',edit1.text)<>0 then
    begin
     if studymode then
      begin
      if edit2.text<>'' then
        begin
            if abs((strtofloat(edit2.text)-strtofloat(czgrid1.cells[ranx+varnum-1,0])))<min then
              showmessage('您的回答正确,恭喜!')
            else
              showmessage('请您再仔细想一下吧。');
        end
      else
        showmessage('请输入答案')
      end
     else{不是学习模式}
      begin
        edit2.Text :=floattostr(strtofloat(czgrid1.cells[ranx+varnum-1,0]))
      end;
    end;
if pos('b',edit1.text)<>0 then
    begin
      calculateb;
    end;
if pos('C',edit1.text)<>0 then
    begin
      calculatec;
    end;
if pos('a',edit1.text)<>0 then
    begin
      calculatea;
    end;
end;
procedure Tmainlmd.readdataofgrid2;
var i,j:integer;
    str1,str2,str3:string;
    ext1:extended;
begin
{ assignfile(fofown,nameoffileofown);
 reset(fofown);
 if not fileexists(nameoffileofown) then
   showmessage('读文件时发生错误')
 else
  begin
    read(fofown,str1);{ext1}
{    for i:=1 to afteraddvarnum do
     begin
        str1:=copy(str1,(pos(',',str1)+1),(length(str1)-pos(',',str1)));
     end;
   readln(fofown);
     For j:=1 to afterleashnum do
        begin
          For i:=1 to afteraddvarnum do
            begin
             read(fofown,ext1);
             agrid1.cells[i-1,j-1]:=floattostr(ext1);
            end;

          readln(fofown);
        End;
     readln(fofown);
   try
    For i:=1 to afterleashnum do
      begin
       read(fofown,ext1);
       bdagrid1.cells[0,i]:=floattostr(ext1);
      end;
    finally
    end;
   bdagrid1.cells[0,0]:='Bj/Aij';
    readln(fofown);
   for i:=1 to afterleashnum do
     begin
      read(fofown,str1);
      cxbgrid1.cells[0,i]:=copy(str1,1,(pos('X',str1)-1));

      cxbgrid1.cells[1,i]:=copy(str1,pos('X',str1),2);

      cxbgrid1.cells[2,i]:=copy(str1,(pos('X',str1)+2),(length(str1)-pos('X',str1)-1));
      readln(fofown);
     end;
   cxbgrid1.cells[0,0]:='Cb';
   cxbgrid1.cells[1,0]:='Xb';
   cxbgrid1.cells[2,0]:='B';
   readln(fofown);
   read(fofown,str1);
   objedit1.text:=str1;
   readln(fofown);
   for i:=1 to afteraddvarnum do
     begin
        read(fofown,str1);
        czgrid1.cells[i-1,0]:=copy(str1,1,(pos(',',str1)-1));

        czgrid1.cells[i-1,1]:=copy(str1,(pos(',',str1)+1),10);
        readln(fofown);
     end;
   readln(fofown);

   for i:=1 to afteraddvarnum do
     begin
        xigrid1.cells[i-1,0]:='X'+inttostr(i);
        xigrid1.cells[i-1,1]:=floattostr(c^[i].num);
     end;
   for i:=1 to afterleashnum do
     begin
       readln(fofown,str1);
       bdagrid1.cells[0,i]:=str1;
     end;
  end;
  system.close(fofown);

}
     agrid1.RowCount :=dchxingform.agrid1.RowCount;
     cxbgrid1.rowcount:=dchxingform.cxbgrid1.RowCount ;
     xigrid1.RowCount :=dchxingform.xigrid1.Rowcount;
     czgrid1.RowCount :=dchxingform.czgrid1.RowCount ;
     bdagrid1.RowCount :=dchxingform.bdaGrid1.RowCount ;

     agrid1.colCount :=dchxingform.agrid1.colCount;
     cxbgrid1.colcount:=dchxingform.cxbgrid1.colCount ;
     xigrid1.colCount :=dchxingform.xigrid1.colcount;
     czgrid1.colCount :=dchxingform.czgrid1.colCount ;
     bdagrid1.colCount :=dchxingform.bdaGrid1.colCount ;

     agrid1.width :=dchxingform.agrid1.width;
     cxbgrid1.width:=dchxingform.cxbgrid1.width ;
     xigrid1.width :=dchxingform.xigrid1.width;
     czgrid1.Width  :=dchxingform.czgrid1.width;
     bdagrid1.width :=dchxingform.bdaGrid1.width ;

     agrid1.Height  :=dchxingform.agrid1.height;
     cxbgrid1.height:=dchxingform.cxbgrid1.height ;

⌨️ 快捷键说明

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