p align="left">Используя программу, пользователь может, вводя свои исходные данные, получить решение поставленной задачи. СПИСОК ЛИТЕРАТУРЫ 1. Архангельский А.Я. "DELPHI_5 учебный курс" - М.: "Издательство Нолидж", 2000 г. 2. Терехов Л.Л. "Экономо-математические методы" - М.: "Высшая школа", 1971 г. 3. Кузнецов Ю.Н., Козубов В.И., Волощенко А.Б. "Математическое программирование" М.: "Высшая школа", 1980 г. 4. Федоров А.Г. "Delphi 3.0 для всех" - М.: "КомпьютерПресс", 1998г. 5 Питерцева Г. А. , Потапова А. С. , Толстов В. Н. "Учебное пособие по решению задач нелинейного программирования (Градиентные методы) " -М.: "Ротапринт МАИ", 1979 г. Приложение А (обязательное) Структура программы Приложение Б (обязательное) Текст программы unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, Menus, ExtCtrls, jpeg; type TForm1 = class(TForm) sgIsx: TStringGrid; Label1: TLabel; sgZap: TStringGrid; Label2: TLabel; sgPotr: TStringGrid; Label3: TLabel; Button1: TButton; Label4: TLabel; sgNac: TStringGrid; Label5: TLabel; sgOpt: TStringGrid; Label10: TLabel; Label6: TLabel; MainMenu1: TMainMenu; N1: TMenuItem; N3: TMenuItem; N4: TMenuItem; Image1: TImage; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure N2Click(Sender: TObject); procedure N3Click(Sender: TObject); procedure Image1Click(Sender: TObject); procedure N4Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; C,x,delta:array [1..5,1..5] of real; Potr,beta:array[1..5] of real; Zapas,alfa: array[1..4] of real; z,p:integer; //z-количество пунктов с запасами,p - с потребностями zapol:array [1..5,1..5] of Boolean; zakon:Boolean; // Флаг окончания итераций implementation uses Unit2, Unit3; {$R *.dfm} //распределение ресурсов начального плана происходит методом северо-западного угла Procedure Naxod_Poten; Var i,j:integer; vix:boolean; Begin For i:=1 to z do alfa[i]:=-MaxInt; // т.е все альфы не известны For j:=1 to p do beta[j]:=-MaxInt; // т.е все бэты не известны Repeat alfa[1]:=0; For i:=1 to z do For j:=1 to p do Begin If zapol[i,j] then if (alfa[i]=-MaxInt)and(beta[j]<>-MaxInt) then alfa[i]:=beta[j]-c[i,j] else if (alfa[i]<>-MaxInt)and(beta[j]=-MaxInt) then beta[j]:=c[i,j]+alfa[i]; End; vix:=True; For i:=1 to z do if alfa[i]=-MaxInt then vix:=False; For j:=1 to p do if beta[j]=-MaxInt then vix:=False; Until vix; End; Procedure Naxod_delta; Var i,j:integer; Begin For i:=1 to z do For j:=1 to p do Begin delta[i,j]:=beta[j]-alfa[i]-c[i,j]; End; End; Procedure Naxod_Plan; var i,j,sv_i,sv_j,i_tek,j_tek,i_min,j_min:integer; max,min:real; znaki:array [1..5,1..5] of integer; kol_v_stolbce:array[1..5] of integer; kol_v_stroke: array[1..5] of integer; zapol1:array [1..5,1..5] of Boolean; Procedure Init_cikl; //подпрограмма в процедуре var i,j:integer; Begin For i:=1 to z do For j:=1 to p do znaki[i,j]:=0; // найдем количество заполненых ячеек в строках и столбцах for i:=1 to z do kol_v_stroke[i]:=0; For j:=1 to p do kol_v_stolbce[j]:=0; for i:=1 to z do For j:=1 to p do if zapol1[i,j] then begin kol_v_stroke[i]:=kol_v_stroke[i]+1; kol_v_stolbce[j]:=kol_v_stolbce[j]+1; end; i_tek:=sv_i; j_tek:=sv_j; znaki[i_tek,j_tek]:=1; end; Begin max:=0; For i:=1 to z do For j:=1 to p do if (delta[i,j]>max)and (Not(zapol[i,j])) then begin max:= delta[i,j]; sv_i:=i; sv_j:=j; //Клетка (sv_i,sv_j) - новая заполняемая клетка end; if max=0 then // если не положительных дельта begin zakon:=True; exit end; For i:=1 to z do For j:=1 to p do // переписываем матрицу заполнения zapol1[i,j]:=zapol[i,j]; // Теперь найдем цикл Init_cikl; Repeat // переход по столбцу for i:=1 to z do if (i<>i_tek)and zapol1[i,j_tek] then Begin i_tek:=i; znaki[i_tek,j_tek]:=-1; break; End; if i_tek=sv_i then break; // переход по строке for j:=1 to p do if (j<>j_tek)and zapol1[i_tek,j] then Begin j_tek:=j; znaki[i_tek,j_tek]:=1; break; End; if kol_v_stolbce[j_tek]<2 then // если зашли в тупик begin zapol1[i_tek,j_tek]:=False; // убираем последнюю ячейку Init_cikl; // и начинаем сначала end; if kol_v_stroke[i_tek]<2 then // если зашли в тупик begin zapol1[i_tek,j_tek]:=False; // убираем последнюю ячейку Init_cikl; // и начинаем сначала end; Until False; // По матрице знаков находим минимальный элемент min:=MaxInt; // заведомо большее число for i:=1 to z do for j:=1 to p do if (znaki[i,j]=-1)and(x[i,j]<min) then begin min:=x[i,j]; i_min:=i; j_min:=j; end; // переходим к новому плану zapol[i_min,j_min]:=False; zapol[sv_i,sv_j]:=True; for i:=1 to z do for j:=1 to p do x[i,j]:=x[i,j]+znaki[i,j]*min; End; procedure Updat; var i,j:integer; Begin With Form1 do Begin For i:=1 to z do for j:=1 to p do sgOpt.Cells[j,i]:=FloatToStr(x[i,j]); end; End; procedure TForm1.FormCreate(Sender: TObject); var i,j:integer; begin for i:=1 to 4 do sgIsx.Cells[0,i]:=IntToStr(i); for j:=1 to 5 do sgIsx.Cells[j,0]:=IntToStr(j); sgIsx.Cells[1,1]:='12'; sgIsx.Cells[2,1]:='9'; sgIsx.Cells[3,1]:='10'; sgIsx.Cells[4,1]:='15'; sgIsx.Cells[1,2]:='14'; sgIsx.Cells[2,2]:='8'; sgIsx.Cells[3,2]:='13'; sgIsx.Cells[4,2]:='17'; sgIsx.Cells[1,3]:='18'; sgIsx.Cells[2,3]:='19'; sgIsx.Cells[3,3]:='20'; sgIsx.Cells[4,3]:='14'; sgIsx.Cells[1,4]:='17'; sgIsx.Cells[2,4]:='15'; sgIsx.Cells[3,4]:='18'; sgIsx.Cells[4,4]:='21'; sgZap.Cells[0,1]:='1500'; sgZap.Cells[0,2]:='500'; sgZap.Cells[0,3]:='700'; sgZap.Cells[0,4]:='900'; sgPotr.Cells[1,0]:='1000'; sgPotr.Cells[2,0]:='600'; sgPotr.Cells[3,0]:='800'; sgPotr.Cells[4,0]:='1100'; for i:=1 to 4 do sgNac.Cells[0,i]:=IntToStr(i); for j:=1 to 5 do sgNac.Cells[j,0]:=IntToStr(j); for i:=1 to 4 do sgOpt.Cells[0,i]:=IntToStr(i); for j:=1 to 5 do sgOpt.Cells[j,0]:=IntToStr(j); end; procedure TForm1.Button1Click(Sender: TObject); var i,j,shag:integer; F,sum_zap,sum_potr:real; begin z:=4;p:=4; zakon:=False; For i:=1 to z do Begin for j:=1 to p do C[i,j]:=StrToFloat(sgIsx.Cells[j,i]); Zapas[i]:=StrToFloat(sgZap.Cells[0,i]); end; For j:=1 to p do Potr[j]:=StrToFloat(sgPotr.Cells[j,0]); sum_zap:=0; sum_potr:=0; For i:=1 to z do sum_zap:=sum_zap+zapas[i]; for j:=1 to p do sum_potr:=sum_potr+Potr[j]; if sum_zap<sum_potr then Begin z:=z+1; for j:=1 to p do C[z,j]:=0; zapas[z]:=sum_potr-sum_zap; end; if sum_zap>sum_potr then Begin p:=p+1; for i:=1 to z do C[i,p]:=0; potr[p]:=sum_zap-sum_potr; end; sgNac.RowCount:=z+1; sgOpt.RowCount:=z+1; sgNac.ColCount:=p+1; sgOpt.ColCount:=p+1; For i:=1 to z do for j:=1 to p do Begin x[i,j]:=0; zapol[i,j]:=False; end; // Начальное заполнение - метод северо-западного угла i:=1;j:=1; Repeat if Zapas[i]>Potr[j] then begin x[i,j]:=Potr[j]; Potr[j]:=0; Zapas[i]:=Zapas[i]-x[i,j]; end else begin x[i,j]:=Zapas[i]; Zapas[i]:=0; Potr[j]:=Potr[j]-x[i,j]; end; Zapol[i,j]:=True; if Potr[j]=0 then j:=j+1 // переход к след. клетке else i:=i+1; Until (i>z) or (j>p); For i:=1 to z do For j:=1 to p do sgNac.Cells[j,i]:=FloatToStr(x[i,j]); // Основной цикл shag:=0; REPEAT shag:=shag+1; Naxod_Poten; Naxod_delta; Naxod_Plan; Updat; // найдем значение целевой функции f:=0; For i:=1 to z do For j:=1 to p do f:=f+x[i,j]*c[i,j]; if zakon then break; label10.Caption:=FloatToStr(f); UNTIL False; end; procedure TForm1.N2Click(Sender: TObject); begin close; end; procedure TForm1.N3Click(Sender: TObject); begin form1.hide; form2.show; end; procedure TForm1.Image1Click(Sender: TObject); begin form1.Close; end; procedure TForm1.N4Click(Sender: TObject); begin form3.Show; form3.Memo1.Lines.LoadFromFile('instruct.txt'); end; end. unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, jpeg, ExtCtrls, StdCtrls; type TForm2 = class(TForm) Image1: TImage; Label1: TLabel; Label2: TLabel; Image2: TImage; procedure Image2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation uses Unit1; {$R *.dfm} unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons; type TForm3 = class(TForm) Memo1: TMemo; BitBtn1: TBitBtn; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form3: TForm3; implementation {$R *.dfm} procedure TForm3.BitBtn1Click(Sender: TObject); begin hide;
Страницы: 1, 2, 3
|