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

📄 step.pas

📁 运筹学算法与编程实践附书源码
💻 PAS
字号:
unit Step;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    CheckBox2: TCheckBox;
    BitBtn1: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn2: TBitBtn;
    Panel2: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

var matrix,matrixout,edt,edit:array of array of TEdit;
var CC:array[1..99,1..99]of real;

var lieshu2,T,N,hangshu3,hangshu,hangshu1,hangshu2:InTEger;
{$R *.dfm}

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
 CheckBox1.Checked:=true;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  CheckBox2.Checked:=False;
 showmessage('不能选有向图');
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  N:=StrToInt(Edit1.Text);
  if N<2 then  showmessage('节点的数目不能小于2');
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var  i,j:inTEger;
begin
  n:=StrToInt(Edit1.Text);
  label2.Left:=110;
  label2.Top:=85+N*35;
  label3.Left:=110;
  label3.Top:=125+N*35;
  label4.Left:=110;
  label4.Top:=165+N*35;
  label4.Caption:='距 离:';
  label3.Caption:='终止点:';
  label2.Caption:='起始点:';

//创建节点名称输入编辑框
  if edit<>nil then
    for i:=0 to hangshu1-1 do
      for j:=0 to 0 do
        edit[i,j].Free;
  hangshu1:=StrToInt(Edit1.TExt);
  SETLength(edit,hangshu1);
  for i:=low(edit) to high(edit) do
    SETLength(edit[i],1);
  for i:=low(edit) to high(edit) do
     for j:=0 to 0 do
       begin
         edit[i,j]:=TEdit.CreaTE(SElf);
         with edit[i,j] do
           begin
              Parent:=Panel2;
              Width:=45;
              Height:=35;
              left:=190+j*45;
              top:=65+i*35;
              text:=IntToStr(i+1);
           end;
       end;
//创建相邻节点自动生成编辑框
  if edt<>nil then
     for j:=0 to hangshu2-1 do
        edt[0,j].Free;
  hangshu2:=StrToInt(Edit1.TExt);
  SETLength(edt,hangshu2);
  for J:=low(edt) to high(edt) do
    SETLength(edt[J],hangshu2);
    for j:=low(edt) to high(edt) do
       begin
         edt[0,j]:=TEdit.CreaTE(SElf);
         with edt[0,j] do
           begin
              Parent:=Panel2;
              Width:=50;
              Height:=35;
              left:=235+j*50;
              top:=30;
              text:=IntToStr(j+1);
           end;
       end;
//创建相邻矩阵输入框
  if matrix<>nil then
    for i:=0 to hangshu3-1 do
      for j:=0 to hangshu3-1 do
        matrix[i,j].Free;
  hangshu3:=StrToInt(Edit1.TExt);
  SETLength(matrix,hangshu3);
  for i:=low(matrix) to high(matrix) do
    SETLength(matrix[i],hangshu3);
  for i:=low(matrix) to high(matrix) do
     for j:=0 to hangshu3-1 do
       begin
         matrix[i,j]:=TEdit.CreaTE(SElf);
         with matrix[i,j] do
           begin
              Parent:=Panel2;
              Width:=50;
              Height:=35;
              left:=235+j*50;
              top:=65+i*35;

           end;
       end;
//创建最小支撑树边的长度、节点名称输出编辑框
  if matrixout<>nil then
    for i:=0 to 2 do
      for j:=0 to lieshu2-1 do
        matrixout[i,j].Free;
  lieshu2:=StrToInt(Edit1.TExt)-1;
  SETLength(matrixout,3);
  for i:=low(matrixout) to high(matrixout) do           
    SETLength(matrixout[i],lieshu2);
  for i:=low(matrixout) to high(matrixout) do
     for j:=0 to lieshu2-1 do
       begin
         matrixout[i,j]:=TEdit.CreaTE(SElf);
         with matrixout[i,j] do
           begin
              Parent:=Panel2;
              Width:=69;
              Height:=35;
              left:=190+j*69;
              top:=115+lieshu2*35+i*40;
           end;
       end;

end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var JJ,L,K1,k,i,j:integer;
var P:real;
var JK,IK,IT,J0,D:array[1..99]of real;
label 1;
label 2;
label 3;
label 4;
begin
  for i:=0 to n-1 do
    for j:=0 to n-1 do
      CC[i+1,j+1]:=StrToFloat(matrix[i,j].Text );
  for j:=1 to n-1 do
    IT[j]:=1;
  for k:=1 to n-1 do
    begin
      P:=108;
      K1:=k-1;
      j:=2;
      while j<N+1 do
        begin
          if k=1 then goto 1;
          for L:=1 to K1 do
            if j=round(J0[L]) then goto 2;
1:        if CC[1,j]-P>=0 then goto 2;
          P:=CC[1,j];
          J0[K]:=j;
2:        j:=j+1;
        end;
      J:=round(J0[K]-1);
      IK[K]:=IT[j];
      JK[K]:=J0[K];
      D[K]:=P;
      if K=N-1 then goto 4;
      J:=2;
      while j<N+1 do
        begin
          for L:=1 to K do
            if j=round(J0[L]) then goto 3;
          JJ:=round(J0[K]);
          if CC[JJ,J]-CC[1,J]>=0 then goto 3;
          CC[1,J]:=CC[JJ,J];
          IT[J-1]:=J0[K];
3:        J:=J+1;
        end;
    end;
4: for i:=0 to N-2 do
     begin
       matrixout[0,I].Text:=intToStr(round(IK[I+1]));
       matrixout[1,I].Text:=intToStr(round(JK[I+1]));
       matrixout[2,I].Text:=intToStr(round(D[I+1]));
     end;
end;

end.

⌨️ 快捷键说明

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