unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure EdKeyPress(Sender: TObject; var Key: Char); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure Button1Click(Sender: TObject); procedure ButDalClick(Sender: TObject); procedure S4itivanie; procedure Na4alo; function Itteracia:boolean; private { Private declarations } public { Public declarations } end; var Form1: TForm1; ed: array [1..10,1..13] of TEdit; dann: array [1..10,1..13] of real; kolvo:byte; Pn: array[1..12] of byte; P: array [0..22,0..12] of real; n: integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Caption:='Введите колличество изделий (не более 10)'; end; procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not(key in ['1','2','3','4','5','6','7','8','9','0',#8]) then key:=#0; end; procedure TForm1.Button1Click(Sender: TObject); var i,y:byte; lb:TLabel; begin kolvo:=StrToInt(Edit1.Text); if (kolvo>10) or (kolvo<1) then exit; Edit1.Free; Form1.Caption:='Заполните таблицу начальных данных'; for i:=1 to kolvo do for y:=1 to kolvo+3 do begin ed[i,y]:=TEdit.Create(form1); ed[i,y].Left:=20+i*45; ed[i,y].Top:=10+y*20; ed[i,y].Width:=45; ed[i,y].Height:=20; ed[i,y].Color:=clBtnFace; ed[i,y].Enabled:=false; ed[i,y].Text:='----------'; ed[i,y].OnKeyPress:=form1.EdKeyPress; ed[i,y].Parent:=form1; end; lb:=TLabel.Create(form1); lb.Parent:=form1; lb.Left:=10; lb.Top:=10; lb.Caption:='Изделия :'; lb:=TLabel.Create(form1); lb.Parent:=form1; lb.Left:=5; lb.Top:=35; lb.Caption:='Прибыль'; lb:=TLabel.Create(form1); lb.Parent:=form1; lb.Left:=5; lb.Top:=55; lb.Caption:='Штамповка'; lb:=TLabel.Create(form1); lb.Parent:=form1; lb.Left:=5; lb.Top:=75; lb.Caption:='Отделка'; for i:=1 to kolvo do begin lb:=TLabel.Create(form1); lb.Parent:=form1; lb.Left:=30+i*45; lb.Top:=10; lb.Caption:='№ '+IntToStr(i); lb:=TLabel.Create(form1); lb.Parent:=form1; lb.Left:=5; lb.Top:=15+(i+3)*20; lb.Caption:='Сборка '+IntToStr(i); end; for i:=1 to kolvo do for y:=1 to 3 do begin ed[i,y].Color:=clWindow; ed[i,y].Enabled:=true; ed[i,y].Text:='0'; end; for i:=1 to kolvo do begin ed[i,i+3].Color:=clWindow; ed[i,i+3].Enabled:=true; ed[i,i+3].Text:='0'; end; Button1.OnClick:=form1.ButDalClick; end; procedure TForm1.EdKeyPress(Sender: TObject; var Key: Char); begin if not(key in ['1','2','3','4','5','6','7','8','9','0',#8,',','-']) then key:=#0; end; procedure TForm1.ButDalClick(Sender: TObject); var temp:string; i:integer; x: array[0..12] of integer; begin S4itivanie; Na4alo; while not Itteracia do begin end; temp:=''; for i:=1 to kolvo+2 do x[i]:=0; for i:=1 to kolvo+2 do x[Pn[i]]:=Trunc(p[0,i]); for i:=1 to kolvo do temp:=temp+'Изделий №'+inttostr(i)+' : '+IntToStr(x[i])+' шт.'+#13#10; showmessage(temp); end; procedure TForm1.S4itivanie; var i,j:integer; begin for j:=1 to kolvo do for i:=1 to kolvo+3 do begin if ed[j,i].Text='----------' then dann[j,i]:=0 else dann[j,i]:=strtofloat(ed[j,i].Text); end; end; procedure TForm1.Na4alo; var i,j:integer; begin n:=1; for j:=0 to kolvo*2+2 do for i:=0 to kolvo+2 do p[j,i]:=0;; for j:=1 to kolvo do begin p[j,0]:=dann[j,1]; for i:=1 to kolvo+2 do p[j,i]:=dann[j,i+1]; for i:=1 to kolvo+2 do if dann[j,i+1]<>0 then p[j,i]:=100/dann[j,i+1] else p[j,i]:=0; end; for i:=1 to kolvo+2 do begin p[0,i]:=100; p[kolvo+i,i]:=1; end; end; function TForm1.Itteracia:boolean; var i,j,e,s,ki,kj:integer; max,min4,delit:real; d:array [0..12] of real; begin inc(n); result:=false; ki:=kolvo+2; kj:=2*kolvo+2; // первый этап max:=0; for j:=1 to kj do if p[j,0]>=max then begin max:=p[j,0]; e:=j; end; if max=0 then begin result:=true; exit; end; // второй этап min4:=-1; for i:=1 to ki do if p[e,i]>0 then begin min4:=(p[0,i]/p[e,i]); s:=i; end; for i:=ki downto 1 do begin if p[e,i]>0 then begin if min4>=(p[0,i]/p[e,i]) then begin min4:=(p[0,i]/p[e,i]); s:=i; end; end; end; if min4<0 then begin result:=true; showmessage('2'); exit; end; // третий этап delit:=p[e,s]; for j:=0 to kj do p[j,s]:=p[j,s]/delit; for i:=0 to ki do if i<>s then d[i]:=p[e,i]; for i:=0 to ki do begin if i<>s then for j:=0 to kj do begin p[j,i]:=p[j,i]-p[j,s]*d[i]; end; end; Pn[s]:=e; end; end.