Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Курсовые по ОАУ / Первая частная задача синтеза оптимальной структуры .doc
Скачиваний:
69
Добавлен:
15.06.2014
Размер:
965.63 Кб
Скачать

Список использованных источников

  1. Управление машиностроительным предприятием: Учебник для машиностр. спец. вузов/ С.В.Смирнов, С.Н.Ефимушкин, А.А.Колобов и др.; Под ред. С.Г.Пуртова, С.В.Смирнова. – М.:Высш.шк., 1989.

  2. Системное проектирование взаимодействия человека с техническими средствами. В 7 книгах, книга7.В.М. Гасов, А.В. Меньков, Л.А.Соломонов М.:Высш.шк., 1991

  3. Никульшин Б.В., Иванчиков А.А., Сивиренцева О.Н. Лабораторный практикум по курсу «Основы автоматизированного управления» для студентов специальности «Автоматизированные системы обработки информации». – Мн.:БГУИР, 1999.

Приложение 1. Блок-схема

Help Приложение 2 Текст программы

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Grids, StdCtrls, Menus, ComCtrls, Buttons, ExtCtrls;

type

TForm1 = class(TForm)

Label1: TLabel;

Edit1: TEdit;

Button1: TButton;

Button2: TButton;

MainMenu1: TMainMenu;

d1: TMenuItem;

N1: TMenuItem;

N2: TMenuItem;

N4: TMenuItem;

N6: TMenuItem;

N7: TMenuItem;

N8: TMenuItem;

N9: TMenuItem;

N10: TMenuItem;

N11: TMenuItem;

Help1: TMenuItem;

BitBtn1: TBitBtn;

SaveDialog1: TSaveDialog;

OpenDialog1: TOpenDialog;

N13: TMenuItem;

N14: TMenuItem;

GroupBox1: TGroupBox;

StringGrid1: TStringGrid;

Label3: TLabel;

StringGrid2: TStringGrid;

Label4: TLabel;

GroupBox2: TGroupBox;

Panel1: TPanel;

StringGrid3: TStringGrid;

Label5: TLabel;

StringGrid4: TStringGrid;

Label2: TLabel;

Button3: TButton;

Button4: TButton;

Edit2: TEdit;

Label6: TLabel;

Label7: TLabel;

N3: TMenuItem;

N15: TMenuItem;

N5: TMenuItem;

N16: TMenuItem;

Button5: TButton;

Panel2: TPanel;

Memo1: TMemo;

BitBtn2: TBitBtn;

BitBtn3: TBitBtn;

procedure Button1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure N13Click(Sender: TObject);

procedure BitBtn1Click(Sender: TObject);

procedure N7Click(Sender: TObject);

procedure N1Click(Sender: TObject);

procedure N14Click(Sender: TObject);

procedure BitBtn3Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure N4Click(Sender: TObject);

procedure N2Click(Sender: TObject);

procedure BitBtn2Click(Sender: TObject);

procedure Button5Click(Sender: TObject);

procedure N9Click(Sender: TObject);

procedure N10Click(Sender: TObject);

procedure N5Click(Sender: TObject);

procedure N16Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

Type

TMass=record

Mass1:array [1..1000,1..1000] of extended;

Mass2:array [1..1000] of extended;

end;

var

St1:file of TMass;

St2:TextFile;

filenameZ,filenameT:string;

const

Nmax=1000; // Максммальная размерность массива

Type

Mas1=array[1..Nmax,1..Nmax] of extended; // Объявление типа двумерного массива

Mas2=array[1..Nmax] of extended; // Объявление типа одномерного массива

Mas3=array[1..Nmax,1..Nmax] of extended; // Объявление типа двумерного массива

Mas4=array[1..Nmax] of extended; // Объявление типа двумерного массива

var

Form1: TForm1;

A:Mas1; // Объявление двумерного массива

B:Mas2; // Объявление одномерного массива

X:Mas3; // Объявление двумерного массива

Y:Mas4;

Y1:Mas4;

N,Q,i,j:integer;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

N:=StrToInt(Edit1.Text); // Размрность массива

Q:=StrToInt(Edit2.Text);

{Задание числа строк и столбцов в таблицах}

StringGrid1.ColCount:=N+1;

StringGrid1.RowCount:=Q+1;

StringGrid2.ColCount:=N+1;

StringGrid3.ColCount:=N+1;

StringGrid3.RowCount:=Q+1;

StringGrid4.ColCount:=N+1;

StringGrid4.RowCount:=3;

{Заполнение верхнего и левого столбцов поясняющими подписями}

for i:=1 to N do

begin

StringGrid1.Cells[i,0]:=' Узел'+IntToStr(i);

StringGrid2.Cells[i,0]:=' Узел'+IntToStr(i);

StringGrid3.Cells[i,0]:=' j='+IntToStr(i);

StringGrid4.Cells[i,0]:=' Задача'+IntToStr(i);

StringGrid4.Cells[0,1]:=' Узлы АС';

StringGrid4.Cells[0,2]:=' Затраты';

end;

for i:=1 to Q do

begin

StringGrid1.Cells[0,i]:=' Задача'+IntToStr(i);

StringGrid3.Cells[0,i]:=' i='+IntToStr(i);

end;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

Panel1.Visible:=False;

Panel2.Visible:=False;

StringGrid4.Visible:=False;

N:=4; // Размрность массива

Q:=4;

Edit1.Text:=FloatToStr(N);

Edit2.Text:=FloatToStr(Q);

{Задание числа строк и столбцов в таблицах}

StringGrid1.ColCount:=N+1;

StringGrid1.RowCount:=Q+1;

StringGrid2.ColCount:=N+1;

StringGrid3.ColCount:=N+1;

StringGrid3.RowCount:=Q+1;

StringGrid4.ColCount:=N+1;

StringGrid4.RowCount:=3;

{Ввод в левую верхнюю ячейку таблицы названия масива}

StringGrid1.Cells[0,0]:=' Массив А:';

StringGrid2.Cells[0,0]:=' Вектор В:';

StringGrid3.Cells[0,0]:=' Массив X:';

StringGrid4.Cells[0,0]:=' Задачи АС';

StringGrid4.Cells[0,1]:=' Узлы АС';

StringGrid4.Cells[0,2]:=' Затраты';

{Заполнение верхнего и левого столбцов поясняющими подписями}

for i:=1 to N do

begin

StringGrid1.Cells[i,0]:=' Узел'+IntToStr(i);

StringGrid2.Cells[i,0]:=' Узел'+IntToStr(i);

StringGrid3.Cells[i,0]:=' j='+IntToStr(i);

StringGrid4.Cells[i,0]:=' Задача'+IntToStr(i);

StringGrid4.Cells[0,1]:='Узлы АС';

StringGrid4.Cells[0,2]:=' Затраты';

end;

for i:=1 to Q do

begin

StringGrid1.Cells[0,i]:=' Задача'+IntToStr(i);

StringGrid3.Cells[0,i]:=' i='+IntToStr(i);

end;

end;

procedure TForm1.Button2Click(Sender: TObject);

label

bay;

var

s,p,p1,f,m1,m2,m3,l:extended;

k,t,w:integer;

begin

{Заполнение массива А элементами из таблицы StringGrid1}

for i:=1 to N do

for j:=1 to Q do

A[i,j]:=StrToFloat(StringGrid1.Cells[j,i]);

{Заполнение массива В элементами из таблицы StringGrid2}

for j:=1 to N do

B[j]:=StrToFloat(StringGrid2.Cells[j,1]);

Panel1.Visible:=True;

f:=0;

m2:=0;

m3:=0;

for i:=1 to N do

begin

w:=0;

s:=0;

for j:=1 to Q do

begin

if A[i,j]>B[j]

then begin

s:=s+1;

X[i,j]:=0;

StringGrid3.Cells[j,i]:=FloatToStrf(X[i,j],fffixed,4,0);

if s=N

then begin

ShowMessage('Решение отсутствует. Необходимо изменить допустимую загрузку в узлах.');

goto bay;

end;

end

else if A[i,j]<=B[j]

then begin

l:=B[j]-A[i,j];

B[j]:=l;

X[i,j]:=1;

w:=w+1;

StringGrid3.Cells[j,i]:=FloatToStrf(X[i,j],fffixed,4,0);

k:=i;

t:=j;

p:=A[k,t];

if w=1

then begin

m1:=p;

StringGrid4.Cells[i,1]:=FloatToStrf(j,fffixed,4,0);

StringGrid4.Cells[i,2]:=FloatToStrf(p,fffixed,4,0);

end

else if w>1

then begin

if m1>p

then begin

p1:=A[k,t];

m2:=p1+m1;

StringGrid4.Cells[i,1]:=FloatToStrf(j,fffixed,4,0);

StringGrid4.Cells[i,2]:=FloatToStrf(p1,fffixed,4,0);

end;

end;

end;

end;

end;

bay:

end;

procedure TForm1.N5Click(Sender: TObject);

begin

StringGrid4.Visible:=True;

end;

procedure TForm1.N16Click(Sender: TObject);

var

m:extended;

begin

m:=0;

for j:=1 to N do

begin

Y[j]:=StrToFloat(StringGrid4.Cells[j,2]);

m:=m+Y[j];

end;

Label2.Caption:=

'Значение критерия эффективности:'

+ FloatToStr(m);

end;

procedure TForm1.Button4Click(Sender: TObject);

var

m:extended;

begin

m:=0;

for j:=1 to N do

begin

Y[j]:=StrToFloat(StringGrid4.Cells[j,2]);

m:=m+Y[j];

end;

Label2.Caption:=

'Значение критерия эффективности:'

+ FloatToStr(m);

end;

procedure TForm1.N13Click(Sender: TObject);

begin

AboutBox.Top:=Trunc(Form1.Top + Form1.Height/2

- AboutBox.Height/2);

AboutBox.Top:=Trunc(Form1.Left + Form1.Width/2

- AboutBox.Width/2);

AboutBox.ShowModal;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

close;

end;

procedure TForm1.N7Click(Sender: TObject);

begin

close;

end;

procedure TForm1.N1Click(Sender: TObject);

begin

for i:=1 to N do

begin

for j:=1 to Q do

begin

StringGrid1.Cells[j,i]:=' ';

StringGrid3.Cells[j,i]:=' ';

end;

end;

for j:=1 to N do

begin

StringGrid2.Cells[j,1]:=' ';

StringGrid4.Cells[j,1]:=' ';

StringGrid4.Cells[j,2]:=' ';

Label2.Caption:='';

end;

StringGrid4.Visible:=False;

end;

procedure TForm1.N14Click(Sender: TObject);

begin

WinHelp(self.handle,PChar(Application.GetNamePath + 'Help.hlp'),

HELP_FORCEFILE,0);

end;

procedure TForm1.BitBtn3Click(Sender: TObject);

begin

Panel1.Visible:=False;

end;

procedure TForm1.Button3Click(Sender: TObject);

begin

StringGrid4.Visible:=True;

end;

procedure TForm1.N4Click(Sender: TObject);

var

i,j : integer;

nTmp : integer;

fDest : TextFile;

fDst : file;

N,Q:integer;

begin

if(SaveDialog1.Execute)then

begin

N:=StrToInt(Edit1.Text);

Q:=StrToInt(Edit2.Text);

{$I-}

AssignFile(fDst, SaveDialog1.FileName);

Rewrite(fDst);

BlockWrite(fDst,N,sizeof(integer));

BlockWrite(fDst,Q,sizeof(integer));

for j:=1 to Q do

for i:=1 to N do

begin

nTmp := StrToInt(StringGrid1.Cells[j,i]);

BlockWrite(fDst,nTmp,sizeof(integer));

end;

for i:=1 to N do

begin

nTmp := StrToInt(StringGrid2.Cells[i,1]);

BlockWrite(fDst,nTmp,sizeof(integer));

end;

CloseFile(fDst);

{$I+}

end;

end;

procedure TForm1.N2Click(Sender: TObject);

var

fSrc : file;

i,j : integer;

nTmp : integer;

N,Q:integer;

begin

{$I-}

if(OpenDialog1.Execute)then

begin

AssignFile(fSrc, OpenDialog1.FileName);

Reset(fSrc);

BlockRead(fSrc,N,sizeOf(integer));

Edit1.Text := IntToStr(N);

BlockRead(fSrc,Q,sizeof(integer));

Edit2.Text := IntToStr(Q);

StringGrid1.RowCount := Q+1;

StringGrid1.ColCount := N+1;

StringGrid2.ColCount := N+1;

for j:=1 to Q do

for i:=1 to N do

begin

BlockRead(fSrc,nTmp,sizeOf(integer));

StringGrid1.Cells[j,i] := IntToStr(nTmp);

end;

for i:=1 to N do

begin

BlockRead(fSrc,nTmp,sizeof(integer));

StringGrid2.Cells[i,1] := IntToStr(nTmp);

end;

CloseFile(fSrc);

{$I+}

end;

for i := 1 to Q do

begin

StringGrid1.Cells[0,i] :=' Задача' +IntToStr(i);

end;

for i := 1 to N do

begin

StringGrid1.Cells[i,0] :=' Узел' +IntToStr(i);

end;

for i := 1 to N do

begin

StringGrid2.Cells[i,0] :=' Узел' + IntToStr(i);

end;

for i:=1 to N do

begin

StringGrid3.Cells[i,0]:=' j='+IntToStr(i);

StringGrid4.Cells[i,0]:=' Задача'+IntToStr(i);

end;

for i:=1 to Q do

begin

StringGrid3.Cells[0,i]:=' i='+IntToStr(i);

end;

end;

procedure TForm1.BitBtn2Click(Sender: TObject);

begin

Panel2.Visible:=False;

Memo1.Clear;

end;

procedure TForm1.Button5Click(Sender: TObject);

var

m,k:extended;

begin

Panel2.Visible:=True;

for j:=1 to N do

begin

Y1[j]:=StrToFloat(StringGrid4.Cells[j,1]);

Y[j]:=StrToFloat(StringGrid4.Cells[j,2]);

m:=Y1[j];

k:=Y[j];

Memo1.Lines.Add('Задача'+IntToStr(j)+

' решается на узле'+FloatToStrf(m,fffixed,4,0)+

' с затратами' + FloatToStrf(k,fffixed,4,0));

end;

end;

procedure TForm1.N9Click(Sender: TObject);

begin

N:=StrToInt(Edit1.Text);

Q:=StrToInt(Edit2.Text);

StringGrid1.ColCount:=N+1;

StringGrid1.RowCount:=Q+1;

StringGrid2.ColCount:=N+1;

StringGrid3.ColCount:=N+1;

StringGrid3.RowCount:=Q+1;

StringGrid4.ColCount:=N+1;

StringGrid4.RowCount:=3;

for i:=1 to N do

begin

StringGrid1.Cells[i,0]:=' Узел'+IntToStr(i);

StringGrid2.Cells[i,0]:=' Узел'+IntToStr(i);

StringGrid3.Cells[i,0]:=' j='+IntToStr(i);

StringGrid4.Cells[i,0]:=' Задача'+IntToStr(i);

StringGrid4.Cells[0,1]:=' Узлы АС';

StringGrid4.Cells[0,2]:=' Затраты';

end;

for i:=1 to Q do

begin

StringGrid1.Cells[0,i]:=' Задача'+IntToStr(i);

StringGrid3.Cells[0,i]:=' i='+IntToStr(i);

end;

end;

procedure TForm1.N10Click(Sender: TObject);

label

bay;

var

s,p,p1,f,m1,m2,m3,l:extended;

k,t,w:integer;

begin

for i:=1 to N do

for j:=1 to Q do

A[i,j]:=StrToFloat(StringGrid1.Cells[j,i]);

for j:=1 to N do

B[j]:=StrToFloat(StringGrid2.Cells[j,1]);

Panel1.Visible:=True;

f:=0;

m2:=0;

m3:=0;

for i:=1 to N do

begin

w:=0;

s:=0;

for j:=1 to Q do

begin

if A[i,j]>B[j]

then begin

s:=s+1;

X[i,j]:=0;

StringGrid3.Cells[j,i]:=FloatToStrf(X[i,j],fffixed,4,0);

if s=N

then begin

ShowMessage('Решение отсутствует. Необходимо изменить допустимую загрузку в узлах.');

goto bay;

end;

end

else if A[i,j]<=B[j]

then begin

l:=B[j]-A[i,j];

B[j]:=l;

X[i,j]:=1;

w:=w+1;

StringGrid3.Cells[j,i]:=FloatToStrf(X[i,j],fffixed,4,0);

k:=i;

t:=j;

p:=A[k,t];

if w=1

then begin

m1:=p;

StringGrid4.Cells[i,1]:=FloatToStrf(j,fffixed,4,0);

StringGrid4.Cells[i,2]:=FloatToStrf(p,fffixed,4,0);

end

else if w>1

then begin

if m1>p

then begin

p1:=A[k,t];

m2:=p1+m1;

StringGrid4.Cells[i,1]:=FloatToStrf(j,fffixed,4,0);

StringGrid4.Cells[i,2]:=FloatToStrf(p1,fffixed,4,0);

end;

end;

end;

end;

end;

bay:

end;

end.

unit Unit2;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,

Buttons, ExtCtrls,Unit1;

type

TAboutBox = class(TForm)

Panel1: TPanel;

BitBtn1: TBitBtn;

Label1: TLabel;

Image1: TImage;

Label2: TLabel;

Label3: TLabel;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

Label8: TLabel;

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

AboutBox: TAboutBox;

implementation

{$R *.dfm}

procedure TAboutBox.BitBtn1Click(Sender: TObject);

begin

ModalResult:=mrOk

end;

end.