Смекни!
smekni.com

Анализ на чувствительность двойственных оценок (стр. 6 из 6)

for i:=2 to nm-1 do

begin

m1[i-1,1]:=m1[i-1,1]+mas[i,j];

if (m1[i-1,1]=1) and (m1[i-1,2]=0) then m1[i-1,2]:=j;

end;

for j:=1 to m do

for i:=1 to n do

if (m1[i,1]=1) and (j=m1[i,2]) then

begin

bz[1,j]:=i;

end;

for j:=1 to m do

bz[2,j]:=ma[trunc(bz[1,j]),1];

for i:=1 to n do ma[i,2]:=0;

for i:=1 to n do

begin

for j:=1 to m do

ma[i,2]:=ma[i,2]+(mas[i+1,j]*bz[2,j]);

ma[i,2]:=ma[i,2]-ma[i,1];

end;

min:=ma[1,2];

l:=0;

o:=0;

for i:=2 to n do

if min>ma[i,2] then begin min:=ma[i,2]; k:=i+1 end;

min2:=0;

for j:=1 to m do

if mas[k,j]>0 then begin l:=1; min2:=mas[1,j]/mas[k,j]; o:=j end;

if min2=0 then begin b:=1;ShowMessage('Решенийнет'); Form1.Free end

else begin

for j:=1 to m do

if mas[k,j]>0 then

if min2>(mas[1,j]/mas[k,j]) then

begin

min2:=mas[1,j]/mas[k,j];

o:=j;

end;

end;

if (mas[k,o]<>0) then razr:=mas[k,o];

for j:=1 to m do

for i:=1 to n+1 do

begin

if j>o then mas2[i,j]:=mas[i,j];

if j=o then mas2[i,j]:=mas[i,j]/razr;

if j<o then mas2[i,j]:=((mas[i,j]*mas[k,o])-(mas[i,o]*mas[k,j]))/razr;

end;

for j:=1 to m do

mas2[1,j]:=abs(mas2[1,j]);

// ShowMessage(currtostr(razr)+' '+inttostr(k)+' '+inttostr(o));

end;

procedure TForm1.tabrez;

var i,j:integer;

l1:currency;

begin

Form1.StringGrid4.Visible:=True;

Form1.StringGrid3.Visible:=True;

Form1.Label2.Visible:=True;

for j:=1 to mm-2 do

for i:=3 to nm-1 do

Form1.StringGrid3.Cells[i,j]:=currtostr(mas[i-2,j]);

// for i:=1 to n do

// Form1.StringGrid3.Cells[i+3,m+1]:=inttostr(ma[i]);

for j:=1 to m do

Form1.StringGrid3.Cells[1,j]:='P'+inttostr(trunc(bz[1,j]));

for j:=1 to m do

Form1.StringGrid3.Cells[2,j]:=currtostr(bz[2,j]);

l1:=0;

for j:=1 to m do

l1:=l1+mas[1,j]*bz[2,j];

Form1.StringGrid3.Cells[3,m+1]:=currtostr(l1);

for i:=1 to n do

Form1.StringGrid3.Cells[i+3,m+1]:=currtostr(ma[i,2]);

end;

procedure TForm1.tab1;

var i,j:integer;

begin

Form1.StringGrid1.ColCount:=2*n+2;

Form1.StringGrid1.RowCount:=m;

Form1.StringGrid2.ColCount:=2*n+2;

Form1.StringGrid2.RowCount:=1;

Form1.StringGrid1.Width:=((2*n)+2)*36+5;

Form1.StringGrid1.Height:=(32*m);

Form1.StringGrid2.Width:=((2*n)+2)*36+5;

Form1.StringGrid2.Height:=(32*1);

for i:= 0 to n*2 do

begin

if (i mod 2 =1) then

begin

Form1.StringGrid2.Cells[i,j]:='X'+inttostr((i div 2)+1);

end;

if (i mod 2 =0) then Form1.StringGrid2.Cells[i,j]:='0';

Form1.StringGrid2.DefaultColWidth:=35;

Form1.StringGrid2.DefaultRowHeight:=30;

end;

Form1.StringGrid2.Cells[2*n,j]:='->';

Form1.StringGrid2.Cells[2*n+1,j]:='min';

for j:= 0 to m do

begin

for i:= 0 to n*2 do

begin

if (i mod 2 =1) then Form1.StringGrid1.Cells[i,j]:='X'+inttostr((i div 2)+1);

if (i mod 2 =0) then Form1.StringGrid1.Cells[i,j]:='0';

Form1.StringGrid1.DefaultColWidth:=35;

Form1.StringGrid1.DefaultRowHeight:=30;

end;

Form1.StringGrid1.Cells[2*n,j]:='=';

Form1.StringGrid1.Cells[2*n+1,j]:='0';

end;

Form1.StringGrid2.Top:=(32*m)+15;

Form1.StringGrid3.Top:=(32*m)+65;

Form1.StringGrid3.Width:=((2*n)+2)*36+5;

form1.StringGrid3.Height:=(32*m);

Form1.Label1.Top:=32*m;

Form1.Label2.Top:=32*m+50;

Form1.Label1.Visible:=True;

Form1.StringGrid1.Visible:=True;

Form1.StringGrid2.Visible:=True;

end;

procedure TForm1.FormCreate(Sender: TObject);

var i,j:integer;

begin

end;

procedure TForm1.N2Click(Sender: TObject);

begin

ns:=InputBox('Число переменных','Введите чесло переменных','4');

n:=strtoint(ns);

Form1.tab1;

end;

procedure TForm1.N3Click(Sender: TObject);

begin

ms:=InputBox('Числофункций','Введитечеслофункций','3');

m:=strtoint(ms);

Form1.tab1;

end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,

ARow: Integer; var CanSelect: Boolean);

begin

if ((ACol mod 2 =0)and(ACol<(2*n))) or (ACol=(2*n+1)) then

begin

Form1.StringGrid1.Cells[ACol,ARow]:=InputBox('Число','Введитечесло

при X'+inttostr((AColdiv 2)+1)+' для функции '+inttostr(ARow+1),'0');

if ((ACol mod 2 =0)and(ACol<(2*n)))then mas[(ACol div

2)+2,ARow+1]:=strtoint(Form1.StringGrid1.Cells[ACol,ARow]);

// if (ACol=(2*n+1)) then

mas[1,ARow+1]:=strtoint(Form1.StringGrid1.Cells[ACol,ARow]);

end;

end;

procedure TForm1.StringGrid2SelectCell(Sender: TObject; ACol,

ARow: Integer; var CanSelect: Boolean);

begin

if ((ACol mod 2 =0)and(ACol<(2*n))) {or (ACol=(2*n+1))} then

begin

Form1.StringGrid2.Cells[ACol,ARow]:=InputBox('Число','Введитечесло

при Х'+inttostr((AColdiv 2)+1)+' для целевой функции ','0');

// if ((ACol mod 2 =0)and(ACol<(2*n)))then ma[(ACol div

2)+2,1]:=strtoint(Form1.StringGrid2.Cells[ACol,0]);

end;

end;

procedure TForm1.N4Click(Sender: TObject);

var i,j,l:integer;

label 10;

begin

mm:=m+2;

nm:=n+4;

Form1.StringGrid3.RowCount:=mm;

Form1.StringGrid3.ColCount:=nm;

Form1.StringGrid3.FixedCols:=1;

Form1.StringGrid3.FixedRows:=1;

Form1.StringGrid3.DefaultRowHeight:=30;

Form1.StringGrid3.DefaultColWidth:=35;

Form1.StringGrid4.DefaultRowHeight:=30;

Form1.StringGrid4.DefaultColWidth:=35;

Form1.StringGrid4.Width:=m*36+5;

Form1.StringGrid4.Height:=32*2;

Form1.StringGrid4.ColCount:=m;

Form1.StringGrid4.RowCount:=2;

Form1.StringGrid4.FixedRows:=1;

for i:=0 to m-1 do

begin

Form1.StringGrid4.Cells[i,0]:='Y'+inttostr(i+1);

Form1.StringGrid4.Cells[i,1]:='0';

end;

Form1.StringGrid4.Left:=Form1.StringGrid1.Width+10;

Form1.StringGrid3.Width:=nm*36+5;

Form1.StringGrid3.Height:=32*mm;

Form1.StringGrid3.Cells[0,0]:='i';

Form1.StringGrid3.Cells[1,0]:='Бз';

Form1.StringGrid3.Cells[2,0]:='СБз';

Form1.StringGrid3.Cells[0,m+1]:='m+1';

// заполнение таблицы решения

for i:=3 to nm-1 do

Form1.StringGrid3.Cells[i,0]:='P'+inttostr(i-3);

for j:=1 to mm-2 do

Form1.StringGrid3.Cells[0,j]:=inttostr(j)+'.)';

for i:=1 to n do

for j:=0 to m do

mas[i+1,j+1]:=strtoint(Form1.StringGrid1.Cells[(i-1)*2,j]);

for j:=1 to m do

mas[1,j]:=strtoint(Form1.StringGrid1.Cells[2*n+1,j-1]);

for i:=1 to n do

ma[i,1]:=strtoint(Form1.StringGrid2.Cells[(i-1)*2,0]);

b:=0;

l:=0;

while b=0 do

begin

l:=l+1;

if l=100 then begin ShowMessage('Решенийнет'); goto 10 end;

Form1.vich;

Form1.tabrez;

for i:=1 to n+1 do

for j:=1 to m do

mas[i,j]:=mas2[i,j];

for i:=1 to n do

if ma[i,2]>0 then b:=1 else b:=0;

end;

l:=1;

for i:=n-m+4 to n+3 do

begin

y[l]:=strtocurr(Form1.StringGrid3.Cells[i,m+1]);

l:=l+1;

end;

Form1.Label2.Caption:='Решение : У=( '+currtostr(y[1]);

for j:=2 to m do

Form1.Label2.Caption:=Form1.Label2.Caption+' ; '+currtostr(y[j]);

Form1.Label2.Caption:=Form1.Label2.Caption+' )';

10:// ShowMessage('Далее');

// Form1.tabrez;

end;

procedure TForm1.N11Click(Sender: TObject);

begin

m:=3;

n:=6;

Form1.tab1;

Form1.StringGrid1.Cells[0,0]:='1';

Form1.StringGrid1.Cells[2,0]:='1';

Form1.StringGrid1.Cells[4,0]:='1';

Form1.StringGrid1.Cells[6,0]:='1';

Form1.StringGrid1.Cells[0,1]:='3';

Form1.StringGrid1.Cells[4,1]:='2';

Form1.StringGrid1.Cells[8,1]:='1';

Form1.StringGrid1.Cells[0,2]:='1';

Form1.StringGrid1.Cells[2,2]:='4';

Form1.StringGrid1.Cells[10,2]:='1';

Form1.StringGrid1.Cells[13,0]:='430';

Form1.StringGrid1.Cells[13,1]:='460';

Form1.StringGrid1.Cells[13,2]:='420';

Form1.StringGrid2.Cells[0,0]:='3';

Form1.StringGrid2.Cells[2,0]:='2';

Form1.StringGrid2.Cells[4,0]:='5';

end;

procedure TForm1.Button1Click(Sender: TObject);

var i:integer;

begin

end;

procedure TForm1.StringGrid4SelectCell(Sender: TObject; ACol,

ARow: Integer; var CanSelect: Boolean);

var i:integer;

begin

Form1.StringGrid4.Cells[ACol,ARow]:=InputBox('Число','Введитечесло

при Y'+inttostr(ACol+1),'0');

Form1.Label3.Visible:=true;

Form1.Label3.Top:=Form1.StringGrid3.Top+Form1.StringGrid3.Height;

Form1.Label3.Caption:='Ответ :

Y='+currtostr(y[1]*strtocurr(Form1.StringGrid4.Cells[0,1]))+'y1';

for i:=1 to m-1 do

Form1.Label3.Caption:=Form1.Label3.Caption+'+'+currtostr(y[i+1]*strtocu

rr(Form1.StringGrid4.Cells[i,1]))+'y'+inttostr(i+1);

end;

end.


Приложение Б (обязательное)

Макеты экранных форм

Рисунок Б.1 – Исходные данные

Рисунок Б.2 – Результаты программы