Здравствуйте.Нужно чтобы программа считала симплекс таблицу с вещественными числами.Т.е.(0,8 0,9 0,5 и тд)Я в виду своего слабоумия не могу понять как это сделать..Пишет ошибку "is not a valid integer value" . Программа не моя,и код соответственно тоже.Прошу помощи,уровень отчаянья 10 из 10.
Код:
private
{ Private declarations }
public
{ Public declarations }
end;
Matr = array [1..20, 1..20] of real;
Vect = array [1..20] of real;
Vect_i = array [1..10] of integer;
var
Form1: TForm1;
m, n: integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); //Ввод первоначальных данных для настройки интерфейса
Var s: string [5];
t, i, j: integer;
begin
s:= InputBox ('Ввод', 'Введите количество ограничений:', '');
t:= StrToInt (s);
m:= t;
StringGrid1.RowCount:= t;
StringGrid1.Height:= 23*t+7;
s:= InputBox ('Ввод', 'Введите количество переменных:', '');
t:= StrToInt (s)*2 +2;
n:= StrToInt (s)+m+1;
StringGrid1.ColCount:= t;
StringGrid1.Width:= StringGrid1.DefaultColWidth*t+7;
StringGrid2.ColCount:= t-2;
StringGrid2.Width:= StringGrid2.DefaultColWidth*(t-2)+7;
StringGrid3.ColCount:= t-2;
StringGrid3.Width:= StringGrid3.DefaultColWidth*(t-2)+7;
For i:=0 to StringGrid1.RowCount-1 do
StringGrid1.Cells [StringGrid1.ColCount-2, i]:= '<=';
j:=1;
While j<StringGrid1.ColCount-2 do
Begin
For i:=0 to StringGrid1.RowCount-1 do
StringGrid1.Cells [j, i]:= 'x'+IntToStr((j+1) div 2);
j:= j+2;
End;
j:=1;
While j<StringGrid2.ColCount do
Begin
StringGrid2.Cells [j, 0]:= 'x'+IntToStr((j+1) div 2);
j:= j+2;
End;
j:=0;
While j<StringGrid3.ColCount do
Begin
StringGrid3.Cells [j, 0]:= 'x'+IntToStr((j+2) div 2)+'=';
j:= j+2;
End;
end;
procedure TForm1.Button1Click(Sender: TObject); //Собственно, реализация самого алгоритма (плюс считывание данных из оконных форм)
Var a: matr;
b, q, x: vect;
c: vect_i;
i, j, k, minb, minq: integer;
s: real;
f, d: boolean;
begin
j:=0; k:=1;
While j<StringGrid1.ColCount-2 do
Begin
For i:=0 to StringGrid1.RowCount-1 do
a[i+1, k]:= StrToInt (StringGrid1.Cells [j, i]);
j:= j+2; inc (k);
End;
For i:=1 to m do
For j:=k to n-1 do
If i=j-k+1 then a[i, j]:= 1 else a[i, j]:= 0;
For i:=0 to StringGrid1.RowCount-1 do
a[i+1, n]:= StrToInt (StringGrid1.Cells [StringGrid1.ColCount-1, i]);
j:=0; k:=1;
While j<StringGrid2.ColCount do
Begin
x[k]:=StrToInt (StringGrid2.Cells [j, 0]); //b n-1
j:= j+2; inc (k);
End;
For i:=k to n-1 do x[i]:=0;
For i:= 1 to m do c[m-i+1]:=n-i;
d:= true;
Repeat
For i:=1 to n-1 do
Begin
s:= 0;
For j:=1 to m do
s:= s + a[j, i]*x[c[j]];
b[i]:= s-x[i];
End;
f:= false;
For i:=1 to n-1 do
If b[i]<0 then begin f:= true; break; end;
If f then
Begin
minb:= 1;
For i:=1 to n-1 do
If b[i]<b[minb] then minb:=i;
k:=0;
For i:=1 to m do
If a[i, minb]<=0 then inc (k);
If k=m then begin f:=false; d:=false; break; end;
For i:=1 to m do
If a[i, minb]<=0 then
q[i]:= -1 else
q[i]:= a[i, n]/a[i, minb];
minq:= 1;
For i:=1 to m do
If (q[i]<q[minq]) and (q[i]>=0) then minq:=i;
If q[minq]<0 then begin d:=false; break; end;
s:= a[minq, minb];
For j:=1 to n do
a[minq, j]:= a[minq, j]/s;
For i:=1 to minq-1 do
Begin
s:= a[i, minb];
If s<>0 then
For j:=1 to n do
a[i,j]:=a[i,j]-s*a[minq, j];
End;
For i:=minq+1 to m do
Begin
s:= a[i, minb];
If s<>0 then
For j:=1 to n do
a[i,j]:=a[i,j]-s*a[minq, j];
End;
c[minq]:= minb;
End
Until f=false;
If d then
Begin
s:=0;
For i:=1 to m do
s:=s + x[c[i]]*a[i, n];
Label6.Caption:= 'Целевая функция:' + #13 + FloatToStr (s);
For i:=1 to m do
If c[i]<=StringGrid2.ColCount then
StringGrid3.Cells [c[i]*2-1, 0]:= FloatToStr (a[i, n]);
j:=1;
While j<StringGrid3.ColCount do
Begin
If StringGrid3.Cells [j, 0]= '' then StringGrid3.Cells [j, 0]:= '0';
j:= j+2;
End;
End else
Label6.Caption:= 'Нет конечного решения!';
end;
end.