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

📄 lpmain.pas

📁 线性规划CAI应用程序及原代码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
if nameoffile='' then{如果文件是空的,则将屏幕设置成空的形式}
begin
for i:=1 to varnum do
  stringgrid4.cells[i-1,1]:='0';
for i:=1 to varnum do
  for j:=1 to leashnum do
	 stringgrid1.Cells[i,j]:='0';
for i:=1 to leashnum do
  stringgrid3.cells[0,i]:='0';
for i:=1 to leashnum do
 if objtype='max' then
  stringgrid2.Cells[0,i]:='<='
 else
  stringgrid2.Cells[0,i]:='>=';
end
else{文件不是空的时候}
 begin
  readfromfile;{从文件中读取数据}
  label3.visible:=true;
  label4.visible:=true;
  label4.caption:=nameoffile;
 end;

label1.visible:=true;{将目标函数的类型显示出来}
label1.left:=5;
label1.top:=label4.top+45;
if objtype='max' then
  label1.caption:='Max(f(x))='
else
  label1.caption:='Min(f(x))=';
stringgrid4.visible:=true;
stringgrid4.colcount:=varnum;
stringgrid4.left:=label1.left+label1.width+5;
stringgrid4.top:=label1.top-(roww+1);
for i:=1 to varnum do
 begin
  stringgrid4.cells[i-1,0]:='X'+inttostr(i);
 end;
stringgrid1.visible:=true;
stringgrid2.visible:=true;
stringgrid3.visible:=true;
stringgrid2.cells[0,0]:='等式类型';
stringgrid3.cells[0,0]:='右端项';
stringgrid2.rowcount:=leashnum+1;
stringgrid3.rowcount:=leashnum+1;
if bigques then
begin
     if varnum>8 then
     begin
     stringgrid1.width:=(colw+1)*9+10;
     stringgrid1.height:=(roww+1)*9+20;
     stringgrid1.ScrollBars:=sshorizontal;
     end
     else
     stringgrid1.width:=(colw+1)*(varnum+1)+adjust;
     if leashnum>8 then
         if varnum>8 then
         begin
         stringgrid1.width :=(colw+1)*8+20+20;
         stringgrid1.ScrollBars :=ssboth;
         end
         else
         begin
         stringgrid1.Height :=(roww+1)*10+adjust;
         stringgrid1.Width :=stringgrid1.Width +20+20;
         stringgrid1.ScrollBars :=ssvertical;
         end

     else
         if varnum>8 then
         begin
         stringgrid1.Height :=(roww+1)*(leashnum+1)+20;
         stringgrid1.ScrollBars :=sshorizontal;
         end
         else
         stringgrid1.Height :=(roww+1)*(leashnum+1)+adjust;
end
else
begin
stringgrid1.width:=(colw+1)*(varnum+1)+adjust;
stringgrid1.Height :=(roww+1)*(leashnum+1)+adjust;
end;
stringgrid1.fixedcols:=1;
stringgrid1.FixedRows :=1;

if varnum>8 then
begin
   stringgrid4.height:=2*(roww+1)+20;
   stringgrid4.ScrollBars :=sshorizontal;
   stringgrid4.width:=stringgrid1.Width-colw+1;
end
else
   begin
   stringgrid4.width:=stringgrid1.Width-colw+1;
   stringgrid4.height:=2*(roww+1)+adjust;
   stringgrid4.ScrollBars :=ssnone;
   end;
stringgrid1.left:=stringgrid4.left;
stringgrid1.top:=stringgrid4.top+stringgrid4.height+30;
stringgrid2.top:=stringgrid1.top;
stringgrid2.left:=stringgrid1.left+stringgrid1.width;



if leashnum<9 then
   begin
   if varnum>8 then
      stringgrid2.height:=stringgrid1.height-14
   else
      stringgrid2.height:=stringgrid1.height;
   stringgrid2.Width :=(colw+1)+adjust;
   end
else
   begin
   stringgrid2.Width :=(colw+1)+20;
   stringgrid2.ScrollBars :=ssvertical;
   stringgrid2.height:=stringgrid1.height-14;
   end;
stringgrid3.width:=stringgrid2.Width-8;
stringgrid3.height:=stringgrid2.height;
stringgrid3.ScrollBars :=stringgrid2.ScrollBars;
stringgrid3.top:=stringgrid1.top;
stringgrid3.left:=stringgrid2.left+stringgrid2.width;

for i:=1 to varnum do
  stringgrid1.cells[i,0]:='X'+inttostr(i);
for i:=1 to leashnum do
  stringgrid1.cells[0,i]:='约束条件'+inttostr(i);
tiaojianpos:=100;
originvarnum:=varnum;
originleashnum:=leashnum;
stringgrid1.ColCount :=varnum+1;
stringgrid1.rowcount:=leashnum+1;
 tiaojianfree:=false;
 top_num:=stringgrid1.top+stringgrid1.height+30;
 enter_num:=0;

 for ij:=1 to varnum do{根据变量数的情况,动态生成条件标签}
 begin
	 tiaojianx[ij]:=TLabel.create(main);
	 with tiaojianx[ij] do
	 begin
               left:=tiaojianpos;
               parent:=main;caption:='X';
               if left>(stringgrid3.left) then
               begin
               enter_num:=enter_num+1;
               top_num:=stringgrid1.top+stringgrid1.height+30+40*enter_num;
               tiaojianpos:=100;
               end;
               top:=top_num;
               left:=tiaojianpos;font.size:=14;
	end;
	 tiaojianvar[ij]:=TLabel.create(main);
	 with tiaojianvar[ij] do
		begin parent:=main;top:=tiaojianx[ij].top+15;left:=tiaojianx[ij].left+tiaojianx[ij].width;
		 caption:=inttostr(ij);font.size:=10;font.Style :=[fsbold];
		end;
	tiaojianequal[ij]:=TLabel.create(main);
	with tiaojianequal[ij] do
	  begin parent:=main;caption:='>=0';top:=tiaojianx[ij].top;left:=tiaojianvar[ij].left+tiaojianvar[ij].width;
		font.size:=14;tiaojianequalarr[ij]:=bptiaojianarr[ij];onclick:=label2click;
	  end;
  tiaojianpos:=tiaojianpos+110;
  case tiaojianequalarr[ij] of
	  1:tiaojianequal[ij].caption:='>=0';
	  2:tiaojianequal[ij].caption:='<=0';
	  3:tiaojianequal[ij].caption:='正负不限';
	 end;
 end;
end;

end{if varnum<>0 and leashnum<>0}
else
begin

end;{if varnum<>0 and leashnum<>0}

main.refresh;

end;

procedure Tmain.N17Click(Sender: TObject); {鼠标输入菜单}
begin
if n17.caption='鼠标输入(&M)' then
   begin
   n17.Caption :='键盘输入(&K)';
   speedbutton9.Glyph.LoadFromFile('keyboard.bmp');
   end
else
    begin
    n17.caption:='鼠标输入(&M)';
    speedbutton9.Glyph.LoadFromFile('mouse.bmp');
    end;

n17.checked:=(not n17.checked);{鼠标输入状态的设置}
mouseinput:=n17.checked;
end;

procedure Tmain.StringGrid4MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if mouseinput  and selecell then{如果是鼠标输入状态,则显示输入数据窗口}
 begin

  whichgrid:=4;   {指明选择的是哪一个对象}
  selecell:=false;{重新将其设置}
  calculate.top:=starty+stringgrid4.top+50; {调整窗口显示的位置}
  calculate.left:=startx+stringgrid4.left+6;
  calculate.show;

 end;

end;

procedure Tmain.StringGrid4SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
whichcellx:=acol;
whichcelly:=arow;
selecell:=true;
datachange1:=true;{数据改变的一个必要条件}
datachange:=datachange1 or datachange2;
if datachange then
	n20.enabled:=true
else
	n20.enabled:=false;
n21.enabled:=n20.enabled;
speedbutton3.enabled:=n20.enabled;
end;

procedure Tmain.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
whichcellx:=acol;
whichcelly:=arow;
selecell:=true;
datachange1:=true;
datachange:=datachange1 or datachange2;
if datachange then
	n20.enabled:=true
else
	n20.enabled:=false;
n21.enabled:=n20.enabled;
speedbutton3.enabled:=n20.enabled;
end;

procedure Tmain.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin

if mouseinput  and selecell then
 begin
  whichgrid:=1;{同上}
  selecell:=false;
  calculate.top:=starty+stringgrid1.top+50;
  calculate.left:=startx+stringgrid1.left+6;
  calculate.show;
 end;

end;

procedure Tmain.StringGrid3MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if mouseinput  and selecell then
 begin
  whichgrid:=3;
  selecell:=false;
  calculate.top:=starty+stringgrid3.top+50;
  calculate.left:=startx+stringgrid3.left+6;
  calculate.show;
 end;
end;

procedure Tmain.StringGrid3SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
whichcellx:=acol;
whichcelly:=arow;
selecell:=true;
datachange1:=true;
datachange:=datachange1 or datachange2;
if datachange then
	n20.enabled:=true
else
	n20.enabled:=false;
n21.enabled:=n20.enabled;
speedbutton3.enabled:=n20.enabled;
end;

procedure Tmain.Label2Click(Sender: TObject);{改变X的属性用鼠标}
var i:integer;
begin
     if which_in_form=0 then
        begin
           calculate.hide;
           datachange1:=true;{标志对文件已经修改过了}
           datachange2:=true;
           datachange:=datachange1 or datachange2;
	if datachange then
	n20.enabled:=true
	else
	n20.enabled:=false;
	n21.enabled:=n20.enabled;
	speedbutton3.enabled:=n20.enabled;
           for i:= 1 to varnum do
             begin
                if sender=tiaojianequal[i] then  {用条件数组来记录X属性的当前状态}
                tiaojianequalarr[i]:=tiaojianequalarr[i]+1;
                if tiaojianequalarr[i]=4 then
                tiaojianequalarr[i]:=1;
                case tiaojianequalarr[i] of
                     1:tiaojianequal[i].caption:='>=0';
                     2:tiaojianequal[i].caption:='<=0';
                     3:tiaojianequal[i].caption:='正负不限';
                end;
             end;
        end;

     if which_in_form=1 then
        if studymode=true then
        begin
           calculate.hide;
           //datachange1:=true;{标志对文件已经修改过了}
           //datachange2:=true;
           for i:= 1 to leashnum do
             begin
                if sender=tiaojian2equal[i] then  {用条件数组来记录X属性的当前状态}
                tiaojian2equalarr[i]:=tiaojian2equalarr[i]+1;
                if tiaojian2equalarr[i]=4 then
                tiaojian2equalarr[i]:=1;
                case tiaojian2equalarr[i] of
                     1:tiaojian2equal[i].caption:='>=0';
                     2:tiaojian2equal[i].caption:='<=0';
                     3:tiaojian2equal[i].caption:='正负不限';
                end;
             end;
        end;

end;

procedure Tmain.Label1Click(Sender: TObject);
begin
if Label1.caption='Max(f(x))=' then
  Label1.caption:='Min(f(x))='
else
 Label1.caption:='Max(f(x))=' ;
end;

procedure readfromframe;{从界面上读取用户输入的数据}
var i,j:integer;
begin
  new(c);
  for i:=1 to varnum do
    begin
     if main.stringgrid4.cells[1,1]='' then
       c^[i].num:=0
     else
      c^[i].num:=strtofloat(main.StringGrid4.cells[i-1,1]);
     if (tiaojianequal[i].caption='>=0') or (tiaojianequal[i].caption='>=') then
       c^[i].att:='>='
     else
       if (tiaojianequal[i].caption='<=0') or (tiaojianequal[i].caption='<=') then
        c^[i].att:='<='
       else
        c^[i].att:='<=>';

    end;
   new(a);
   for j:=1 to leashnum do
     for i:=1 to varnum do
      begin
        if main.stringgrid1.cells[i,j]='' then
          a^[j,i]:=0
        else
        a^[j,i]:=strtofloat(main.stringgrid1.cells[i,j]);
      end;

   new(b);
   for i:=1 to leashnum do
    begin	
    if main.stringgrid3.cells[0,i]='' then
     b^[i]:=0
    else
     b^[i]:=strtofloat(main.stringgrid3.cells[0,i]);
    end; 
   new(tiaojian);
   for i:=1 to leashnum do
     tiaojian^[i]:=main.stringgrid2.cells[0,i]+'';
end;

procedure Tmain.Button1Click(Sender: TObject);
var i,ii:integer;nodelete:boolean;{判断是否删除存在的文件}
begin
   if messagedlg('您确认所做的修改吗?',mtconfirmation,[mbyes,mbno],0)=mryes then
     if savedialog1.execute then
        begin
          readfromframe;
          nameoffile:=savedialog1.FileName ;
          if (not (FileExists(nameoffile))) then
             begin
              if pos('.org',nameoffile)=0 then
                nameoffile:=savedialog1.FileName+'.org';
              writeorigin;
              label3.visible:=true;
              label4.visible:=true;
              label4.caption:=nameoffile;
             end
          else {文件存在}
             begin
                nodelete:=true;
                while  (FileExists(nameoffile)) and nodelete do
                  if  messagedlg('您所选择的文件已经存在,确定要删除该文件' + ExtractFileName(Nameoffile)+ '吗'+'?'
                             ,mtwarning,[mbyes,mbno],0) = mrYes  then
                     begin
                      if pos('.org',nameoffile)=0 then
                        nameoffile:=savedialog1.FileName+'.org';
                        writeorigin;
                        label3.visible:=true;
                        label4.visible:=true;
                        label4.caption:=nameoffile;
                        nodelete:=false;
                     end
                    else {不想删除已存在的文件}
                     if  savedialog1.execute then
                         nameoffile:=savedialog1.filename;
                     nodelete:=true;
              end;
     end;
end;

procedure Tmain.N8Click(Sender: TObject);{开始做原始单纯型计算(演示)}
begin
mainchoose:=10;
yanshi:=true;
studymode:=false;
standardornot:=true;
tlBiaoZhunhua;
afteraddvarnum:=m0+varnum;
dchxingform.show;
end;

procedure Tmain.N9Click(Sender: TObject); {原始单纯型练习}
var s:string;
begin
mainchoose:=10;
yanshi:=false;
standardornot:=true;
tlBiaoZhunhua;
studymode:=true;
afteraddvarnum:=m0+varnum;
dchxingform.show;
{mostnew}
{s:=dchxingform.getmstrofobj ;
for i:=1 to leashnum do
 begin
   xvalue[i]:=(dchxingform.cxbGrid2.cells[2,i-1]);
   xorder[i]:=(dchxingform.cxbGrid2.cells[1,i-1]);
 end;                              {mostnew}
end;

procedure Tmain.N10Click(Sender: TObject); {二阶段演示菜单}
begin
{standardornot:=false;}
studymode:=false;
yanshi:=true;
jieduan1:=true;jieduan2:=false;
tlBiaoZhunhua;
backupvarnum:=afteraddvarnum;
new(c01);
new(ccopy);
rgbnum:=0;
for i:=1 to afteraddvarnum do
begin

     if c^[i].att='RGB' then
     begin
        c01^[i].num:=-1;
        rgbnum:=rgbnum+1;
     end
     else c01^[i].num:=0;
     c01^[i].att:=c^[i].att;
     begin
     ccopy^[i].num:=c^[i].num;
     ccopy^[i].att:=c^[i].att;
     end;
     c^[i].num:=c01^[i].num;
     c^[i].att:=c01^[i].att;
end;
mainchoose:=20;
afteraddvarnum:=m0+varnum;
dchxingform.show;
end;

procedure Tmain.N11Click(Sender: TObject);{二阶段练习菜单}
begin
standardornot:=false;
studymode:=true;

yanshi:=true;
jieduan1:=true;
jieduan2:=false;
tlBiaoZhunhua;
backupvarnum:=afteraddvarnum;
new(c01);
new(ccopy);
rgbnum:=0;
for i:=1 to afteraddvarnum do
begin

     if c^[i].att='RGB' then
     begin
        c01^[i].num:=-1;
        rgbnum:=rgbnum+1;
     end
     else c01^[i].num:=0;
     c01^[i].att:=c^[i].att;
     begin
     ccopy^[i].num:=c^[i].num;
     ccopy^[i].att:=c^[i].att;
     end;
     c^[i].num:=c01^[i].num;
     c^[i].att:=c01^[i].att;
end;
mainchoose:=20;
afteraddvarnum:=m0+varnum;
dchxingform.show;


end;

procedure Tmain.showfiledata;{将从文件中读取的数据输出到屏幕上}
var i,ij:integer;

⌨️ 快捷键说明

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