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

📄 lpdchxing.pas

📁 线性规划CAI应用程序及原代码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
                   zhulie:=i;
                   end;
           end;
       end;
       if zhulie<>0 then
          if biaonum=1 then
          begin
               if studymode then
                  if trim(czgrid1.Cells[zhulie-1,1])<>('('+bpc_zarr[zhulie]+')') then
                  begin
                  showmessage('主列选择错误!');
                  for i:=1 to afteraddvarnum do
                      czgrid1.Cells[i-1,1]:=bpc_zarr[i];
                  end;
          czgrid1.cells[zhulie-1,1]:='('+bpc_zarr[zhulie]+')';
          end
          else
          begin
               if studymode then
                  if trim(czgrid2.Cells[zhulie-1,1])<>('('+czgrid2.cells[zhulie-1,1]+')') then
                  begin
                  showmessage('主列选择错误!');
                  for i:=1 to afteraddvarnum do
                      czgrid2.Cells[i-1,1]:=bpc_zarr[i];
                  end;

          czgrid2.cells[zhulie-1,1]:='('+czgrid2.cells[zhulie-1,1]+')';
          end
       else{zhulie=0}
          begin
          rgvarexit:=false;
          for i:=1 to leashnum do
              begin
              if cxbgrid2.cells[0,i]='-M' then
              rgvarexit:=true;
              end;
          if  rgvarexit   then
              begin
              jisuan_over:=true;
                 if studymode then
                     begin
                     czgrid1.Options :=czgrid1.Options -[goediting];
                     bdagrid1.Options :=bdagrid1.Options -[goediting];
                     czgrid2.Options :=czgrid2.Options -[goediting];
                     bdagrid2.Options :=bdagrid2.Options -[goediting];
                     cxbgrid2.Options :=cxbgrid2.Options -[goediting];
                     agrid2.Options :=bdagrid2.Options -[goediting];
                     objedit2.Enabled :=false;
                     objedit1.Enabled :=false;
                     czgrid1.Refresh;
                     bdagrid1.Refresh ;
                     czgrid2.Refresh ;
                     bdagrid2.Refresh ;
                     cxbgrid2.Refresh ;
                     agrid2.Refresh ;
                     end;

              showmessage('该问题为无可行解');
              button3.Enabled :=false;
              end
          else
             if (mainchoose=20)and (jieduan1=true) then
                 begin
                 rgvarexitjieduan:=false;
          	 	  for i:=1 to leashnum do
                    begin
              		if c01^[basevar[i]].num=-1 then rgvarexitjieduan:=true;
                    end;
                 if rgvarexitjieduan then
                 begin
                     showmessage('该问题无解!');
                     button1.Enabled :=false;
                     button6.Enabled :=false;
                     button2.Enabled :=false;
                     button3.enabled:=false;
                     button5.Enabled :=false;
                     if (not (mainchoose=20))and(filenum>1) then
                     button1.Enabled :=true;
                 end
                 else
                 begin
                 jieduan1:=false;
                 jieduan2:=true;
                 showmessage('第一阶段完成');
                 freshscreen1;
                 end;
                 end
             else
                 begin
                 bestanswer:=true;
                 jisuan_over:=true;
                 if studymode then
                     begin
                     czgrid1.Options :=czgrid1.Options -[goediting];
                     bdagrid1.Options :=bdagrid1.Options -[goediting];
                     czgrid2.Options :=czgrid2.Options -[goediting];
                     bdagrid2.Options :=bdagrid2.Options -[goediting];
                     cxbgrid2.Options :=cxbgrid2.Options -[goediting];
                     agrid2.Options :=bdagrid2.Options -[goediting];
                     objedit2.Enabled :=false;
                     objedit1.Enabled :=false;
                     czgrid1.Refresh;
                     bdagrid1.Refresh ;
                     czgrid2.Refresh ;
                     bdagrid2.Refresh ;
                     cxbgrid2.Refresh ;
                     agrid2.Refresh ;
                     end;

                 showmessage('达到最优解');
                 button6.Enabled :=true;
                 button2.Enabled :=true;
	              button3.enabled:=false;
                 if biaonum=1 then
                 begin
                     for i:=1 to afteraddvarnum do    {填充A}
                         for j:=1 to afterleashnum do
                         begin
                         agrid2.cells[i-1,j-1]:=agrid1.Cells [i-1,j-1];{floattostr(a1^[j,i]);}{floattostr(a^[j,i]);}
                         end;
                     for i:=1 to afteraddvarnum do{填充CZGRID1}
                          begin
                          czgrid2.cells[i-1,0]:=czgrid1.Cells [i-1,0];{savez[i];}{floattostr(z[i]);    }
                          czgrid2.cells[i-1,1]:=czgrid1.Cells [i-1,1];{savec_z[i];}{floattostr(c_z[i]);}
                          end;
                     for i:=1 to afterleashnum do
                         begin
                         cxbgrid2.cells[0,i-1]:=cxbgrid1.Cells [0,i];{floattostr(cb[i]);}
                         cxbgrid2.cells[1,i-1]:=cxbgrid1.Cells [1,i];{'X'+floattostr(basevar[i]);}
                         cxbgrid2.cells[2,i-1]:=cxbgrid1.Cells [2,i];{floattostr(b1^[i]);}
                         end;
                     objedit2.text:=objedit1.text;{saveobj;}

                 end;
                 judgemultianswer;
                 end;

//          statusbar1.panels[0].text:='';
          statusbar1.panels[1].text:='';
          if not multi then
          getresult:=true;
                saveresult;
          if ((jieduan2=true)and(mainchoose=20))or(multi=true) then
              button5.Enabled :=true
          else
              button5.Enabled :=false;
          if not multi then
          begin
          bestanswer:=true;
          end;
          if jisuan_over then
          begin
          button5.Enabled :=false;
          if mainchoose=20 then
          afteraddvarnum:=bpafteraddvarnum;
          end;
          end;

       step:=step+1;
       usef8:=true;
end;

procedure Tdchxingform.calcu_A_sijiao(hang,lie:integer);

begin
     repeat
       repeat
           if totalcontrol2<>hang then
           begin
               	if a^[hang,lie]<>0 then
                           begin
                           	a1^[totalcontrol2,totalcontrol]:=a^[totalcontrol2,totalcontrol]-a^[hang,totalcontrol]*a^[totalcontrol2,lie]/a^[hang,lie];
                              if abs(a1^[totalcontrol2,totalcontrol])<0.000000000000001 then a1^[totalcontrol2,totalcontrol]:=0;
                              if studymode then
                                     if  agrid2.Cells [totalcontrol-1,totalcontrol2-1]<>floattostr(a1^[totalcontrol2,totalcontrol]) then
                                     showmessage('A['+inttostr(totalcontrol2)+']['+inttostr(totalcontrol)+']计算错误!');
                            	agrid2.cells[totalcontrol-1,totalcontrol2-1]:=floattostr(a1^[totalcontrol2,totalcontrol]);
                              statusbar1.panels[1].text:='Aij=Aij-A(i)j*Ai(j)/A(i)(j)';
                           end
           end{if j<>hang}
           else
           begin
           if  a^[zhuhang,zhulie]<>0 then
               a1^[zhuhang,totalcontrol]:=a^[zhuhang,totalcontrol]/a^[zhuhang,zhulie];
                           if abs(a1^[totalcontrol2,totalcontrol])<0.000000000000001 then a1^[totalcontrol2,totalcontrol]:=0;
                                if studymode then
                                     if  agrid2.Cells [totalcontrol-1,zhuhang-1]<>floattostr(a1^[zhuhang,totalcontrol]) then
                                     showmessage('A['+inttostr(zhuhang)+']['+inttostr(totalcontrol)+']计算错误!');
               agrid2.cells[totalcontrol-1,zhuhang-1]:=floattostr(a1^[zhuhang,totalcontrol]);
               statusbar1.panels[1].text:='A(i)j=A(i)j/A(i)(j)';
           end;
           totalcontrol:=totalcontrol+1;
           if totalcontrol=afteraddvarnum+1 then
           usef8:=false;
           if usef8=false then
           usef7:=false;
       until usef7=false;
       if totalcontrol=afteraddvarnum+1  then
           begin
           totalcontrol2:=totalcontrol2+1;
           totalcontrol:=1;
           end;
     until (usef7=false) or (totalcontrol2=afterleashnum+1);
     if totalcontrol2=afterleashnum+1 then
        begin
        step:=step+1;
        totalcontrol:=1;
        totalcontrol2:=1;
        usef8:=true;
        end;
end;

procedure Tdchxingform.calcu_b_sijiao(hang,lie:integer);
var i:integer;
begin
      repeat
         if totalcontrol2<>hang then
             begin
     		if a^[hang,lie]<>0 then
                        begin
                           b1^[totalcontrol2]:=b^[totalcontrol2]-b^[hang]*a^[totalcontrol2,lie]/a^[hang,lie];
                           if studymode then
                                 if cxbgrid2.Cells [2,totalcontrol2-1]<>floattostr(b1^[totalcontrol2]) then
                                 showmessage('第'+inttostr(totalcontrol2)+'个B计算错误!');
                           cxbgrid2.cells[2,totalcontrol2-1]:=floattostr(b1^[totalcontrol2]);
                           statusbar1.panels[1].text:='Bi=Bi-B(i)*Ai(j)/A(i)(j)';
                        end;
             end
         else
             begin
                if a^[zhuhang,zhulie]<>0 then
                b1^[zhuhang]:=b^[zhuhang]/a^[zhuhang,zhulie];
                if studymode then
                      if cxbgrid2.Cells [2,zhuhang-1]<>floattostr(b1^[zhuhang]) then
                                 showmessage('第'+inttostr(zhuhang)+'个B计算错误!');
                cxbgrid2.Cells[2,zhuhang-1]:=floattostr(b1^[zhuhang]);
                statusbar1.panels[1].text:='B(i)=B(i)/A(i)(j)';
             end;
             totalcontrol2:=totalcontrol2+1;
             if totalcontrol2=afterleashnum+1 then
             usef8:=false;
             if usef8=false then
             usef7:=false;
      until usef7=false;
      if totalcontrol2=afterleashnum+1 then
      begin
      step:=step+1;
      totalcontrol2:=1;
      usef8:=true;
      end;

end;

procedure Tdchxingform.save_table1;
begin
   if not nowrite then
   if not (mainchoose=20) then
   button1.enabled:=true;
   nameoffileofown:='temp'+floattostr(filenum)+'.tem';
   try
       writeoriginofown;{将上面一张表写入自己定义的文件格式}
       filenum:=filenum+1;
       bp_filenum:=filenum;
   except
       nowrite:=true;
   end;
end;

procedure Tdchxingform.freshscreen;{当一张表算完后的屏幕刷新}
var i,j:integer;
begin
   for i:=1 to afteraddvarnum do {将a1的值赋给a}
       for j:=1 to afterleashnum do
           a^[j,i]:=a1^[j,i];
   for i:= 1 to afterleashnum do  {将b1的值赋给b}
         b^[i]:=b1^[i];

   if biaonum>1 then
   begin
   for i:=1 to afteraddvarnum do      {将屏幕上下面的表赋给上面的表}
       for j:=1 to afterleashnum do
           begin
              agrid1.cells[i-1,j-1]:=agrid2.cells[i-1,j-1];{floattostr(a^[j,i]);}
              agrid2.cells[i-1,j-1]:='';

           end;
   for i:=1 to afterleashnum do
       begin
            cxbgrid1.cells[2,i]:=cxbgrid2.Cells[2,i-1];
            cxbgrid2.cells[2,i-1]:='';
       end;

   for i:=1 to afterleashnum do
       for j:=0 to 1 do
           begin
           cxbgrid1.cells[j,i]:=cxbgrid2.cells[j,i-1];
           cxbgrid2.cells[j,i-1]:='';
           end;
   for i:=0 to afteraddvarnum-1 do
       begin
           czgrid1.cells[i,0]:=czgrid2.cells[i,0];{floattostr(z[i+1])}
           czgrid1.cells[i,1]:=czgrid2.cells[i,1];{floattostr(c_z[i+1])}
           czgrid2.cells[i,0]:='';
           czgrid2.cells[i,1]:='';
       end;
   for i:=0 to afterleashnum-1 do
       begin
         bdagrid1.Cells [0,i+1]:=bdagrid2.Cells[0,i];
         bdagrid2.Cells [0,i]:='';
       end;
     objedit1.text:=objedit2.text;
     objedit2.text:='';
     label3.caption:='('+inttostr(filenum-1)+')';
     label5.caption:='('+inttostr(filenum)+')';
   end;

   save_table1;

   step:=1;

end;

procedure Tdchxingform.choosezhuhang;{选择主行}
var i:integer;
    rgvarexit:boolean;{判断是否存在人工变量}
begin
     minbda:=bigm;
     statusbar1.panels[1].text:='出变量=Min[Bi/Ai(j)|Ai(j)>0](i=1,2,...,m)';
     repeat
         begin
          if biaonum=1 then
          begin
                if a^[totalcontrol2,zhulie]<>0  then
                  begin
                    bda[totalcontrol2]:=b^[totalcontrol2]/a^[totalcontrol2,zhulie];
                    if studymode then
                         if  bdagrid1.Cells[0,totalcontrol2]<>floattostr(bda[totalcontrol2]) then
                             showmessage('B['+inttostr(totalcontrol2)+']/A['+inttostr(totalcontrol2)+']['+inttostr(zhulie)+']计算错误!');
                    bdagrid1.cells[0,totalcontrol2]:=floattostr(bda[totalcontrol2]);
                  end
                else
         	  begin
               		bda[totalcontrol2]:=bigm;
                        if studymode then
                             if  bdagrid1.Cells[0,totalcontrol2]<>'----' then
                                 showmessage('B['+inttostr(totalcontrol2)+']/A['+inttostr(totalcontrol2)+']['+inttostr(zhulie)+']计算错误!');
               		bdagrid1.cells[0,totalcontrol2]:='----';
               	end;
           end
           else
           begin
                if a1^[totalcontrol2,zhulie]<>0 then
               		begin
                          bda[totalcontrol2]:=b1^[totalcontrol2]/a1^[totalcontrol2,zhulie];
                          if studymode then
                             if  bdagrid2.Cells[0,totalcontrol2-1]<>floattostr(bda[totalcontrol2]) then
                             showmessage('B['+inttostr(totalcontrol2)+']/A['+inttostr(totalcontrol2)+inttostr(zhulie)+']计算错误!');

                      

⌨️ 快捷键说明

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