📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
BitBtn1: TBitBtn;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var edit,edt1,edt2:array of array of TEdit;
// edit 紧前事件号数、紧后事件号数和工序时间数组
// edit1 期望完成时间TE(K)和期望完成时间TE(K)+松弛时间SE(k),关键线路数组
// edit2 事件参数数组
var N,M:integer;
//N 行数
//M 列数
var hangshu,sjhangshu,hangshu1:InTEger;
//hangshu 工序行数
//sjhangshu 事件行数
var C:array[1..99] of array[1..99] of real;
var CC,qwsj,TE,TL,SE:array[1..99] of real;
var hm,cp,qsjh,hsjh,FL:array[1..99] of Integer;
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var i,j:inTEger;
begin
label3.Caption:='紧前事件 紧后事件 工序时间';
label4.Caption:='期望时间 关键线路';
label5.Caption:=' 事件名称 最早时间 最迟时间 松弛时间 关键事件';
label6.Caption:='人工输入内容:';
//创建人工输入表
if edit<>nil then
for i:=0 to hangshu-1 do
for j:=0 to 2 do
edit[i,j].Free;
hangshu:=StrToInt(Edit1.TExt);
SETLength(edit,hangshu);
for i:=low(edit) to high(edit) do
SETLength(edit[i],3);
for i:=low(edit) to high(edit) do
for j:=0 to 2 do
begin
edit[i,j]:=TEdit.CreaTE(SElf);
with edit[i,j] do
begin
Width:=58;
Parent:=Panel1;
left:=10+j*Width;
top:=60+i*HEIGHT;
end;
end;
//创建期望时间表
if edt1<>nil then
for i:=0 to hangshu1-1 do
for j:=0 to 1 do
edt1[i,j].Free;
hangshu1:=StrToInt(Edit1.TExt);
SETLength(edt1,hangshu1);
for i:=0 to hangshu1-1 do
SETLength(edt1[i],2);
for i:=0 to hangshu1-1 do
for j:=0 to 1 do
begin
edt1[i,j]:=TEdit.CreaTE(SElf);
with edt1[i,j] do
begin
Parent:=Panel3;
Width:=65;
left:=20+j*Width;
top:=60+i*Height;
end;
end;
//创建事件输出表
if edt2<>nil then
for i:=0 to sjhangshu-1 do
for j:=0 to 4 do
edt2[i,j].Free;
sjhangshu:=StrToInt(Edit2.TExt);
SETLength(edt2,sjhangshu);
for i:=low(edt2) to high(edt2) do
SETLength(edt2[i],5);
for i:=low(edt2) to high(edt2) do
for j:=0 to 4 do
begin
edt2[i,j]:=TEdit.CreaTE(SElf);
with edt2[i,j] do
begin
Width:=58;
Parent:=Panel4;
left:=10+j*Width;
top:=60+i*HEIGHT;
end;
end;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
close;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var i,j,k,kf,kp,y,C1,c2:inTEger;
var TX,SX,TN:real;
label 1;
label 2;
label 3;
label 4;
label 5;
begin
//全部初始化
N:=StrToInt(Edit1.TExt);
M:=StrToInt(Edit2.TExt);
for i:=1 to N do
begin
qwsj[i]:=0;
//qwsj[i]记录期望时间
fL[i]:=0;
TE[i]:=0;
cp[i]:=0;
end ;
//取输入的值
for i:=0 to N-1 do
begin
qsjh[I+1]:=strtoint(edit[i,0].TExt);
//取紧前作业号
hsjh[I+1]:=strtoint(edit[i,1].TExt);
//取紧后作业号
if hsjh[I+1]<=qsjh[I+1] then break;
CC[I+1]:=strtofloat(edit[i,2].TExt);
//取工序时间
if C[qsjh[I+1],hsjh[I+1]]<0 then break;
//取工序期望时间 这里只考虑单时估计
qwsj[i+1]:=CC[I+1];
end ;
// 计算事件最早开始时间TE[i]
j:=2;
TE[1]:=0;
while j<m+1 do
begin
TX:=0;
k:=1; //从第1行开始找
while k<n+1 do
begin
if hsjh[K]<>j then goto 1;
TE[j]:=TE[qsjh[K]]+CC[k];
if TE[j]<=tx then goto 1 ;
tx:=TE[j];
1: k:=k+1;
end;
TE[j]:=tx; //找到j点的最大值为最早开工时间
j:=j+1;
end;
//计算事件最迟开工时间TL[i]
tL[m]:=te[m];
for y:=2 to m do
begin
i:=m-y+1;
tn:=te[m];
kf:=1;
while kf<n+1 do
begin
k:=n-kf+1;
c1:=qsjh[k];
if c1<>i then goto 2;//146
c2:=hsjh[k];
tL[i]:=tl[c2]-qwsj[k];
if tl[i]>tn then goto 2;//146
tn:=tL[i]; //找到事件最迟开工时间最大的
2: kf:=kf+1; //146
end;
tL[i]:=tn; //找到事件最迟开工时间
end;
//计算松弛时间 SE[j]
for j:=1 to m do
SE[j]:=TL[j]-TE[j];
//找关键工序线路FL[k]
k:=1;
while k<n+1 do
begin
I:=qsjh[k];
j:=hsjh[k];
if abs(tl[i]-te[i]-se[i])> 0.0001 then goto 3;
if abs(tL[j]-te[j]-se[j])> 0.0001 then goto 3;
if abs(te[j]-te[i]-tL[j]+tL[i])> 0.0001 then goto 3;//184
if abs(tL[j]-tL[i]-qwsj[k])> 0.0001 then goto 3;//184
fL[k]:=1;
3: k:=k+1;
end;
{// 找关键事件
k:=1 ;
while k<n+1 do
begin
// I:=qsjh[k];
// j:=hsjh[k];
if fL[k]=0 then goto 4;//204
cp[qsjh[k]]:=1;
cp[hsjh[k]]:=1;
4: k:=k+1;
end; }
// 找关键事件
for j:=1 to m do
if SE[j]=0 then cp[j]:=1;
//输出最早开工时间,最迟开工时间,和关键事件
for i:=0 to m-1 do
hm[i]:=I+1;
for i:=0 to m-1 do
begin
edt2[i,0].TExt:=IntToStr(hm[i]);
edt2[i,1].TExt:=FormatFloat('0.####',TE[i+1]);
edt2[i,2].TExt:=FormatFloat('0.####',TL[i+1]);
edt2[i,3].TExt:=FormatFloat('0.####',SE[i+1]);
edt2[i,4].TExt:=FormatFloat('0.####',cp[i+1]);
end;
for i:=0 to n-1 do
begin
edt1[i,0].TExt:=FormatFloat('0.####',qwsj[i+1]);
edt1[i,1].TExt:=FormatFloat('0.####',FL[i+1]);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -