Привет, ребята. Нужна ваша помощь при решении транспортной задачи. Все дело в том, что я нашла опорный план методом Фогеля, но мне еще нужен второй опорный план методом северо-западного угла. Я пыталась сделать это двумя способами, но почему-то при каждом Делфи выдает ошибку "EConvertError with message ''' is not valid integer value" и я прям уже не знаю что делать. И так, 1 способ: Вначале имеется таблица перевозок. я заношу поставки и потребности в одномерные массивы post и potr. После обрабатываю значения. Проверила, в массив из StringGrid все попадает корректно, но дальше ошибка. Привожу код обработки.:
i:=0; while i<=n-1 do begin j:=0; while j<=m-1 do begin if potr[j]<>0 then begin if post[i]<potr[j] then begin NWCorner.TabCor.Cells[j,i]:=inttostr(post[i]); potr[j]:=potr[j]-post[i]; post[i]:=0; j:=m-1; end else if post[i]>potr[j] then begin NWCorner.TabCor.Cells[j,i]:=inttostr(potr[j]); post[i]:=post[i]-potr[j]; potr[j]:=0; end else begin NWCorner.TabCor.Cells[j,i]:=inttostr(potr[j]); potr[j]:=0; post[i]:=0; end; end; j:=j+1; end; i:=i+1; end; end;
Пробовала вторым алгоритмом: делала на новой форме копию исходной таблицы, чтобы не жалко портить было, но в новую форму заносила только самый правый столбец(поставок) и нижнюю строку(потребления). Привожу код:
for i:=1 to NWCorner.TabCor.RowCount-2 do begin NWCorner.TabCor.Cells[table.ColCount-1,i]:=table.Cells[table.ColCount-1,i]; NWCorner.TabCor.Cells[0,i]:=table.Cells[0,i]; end; for i:=1 to NWCorner.TabCor.ColCount-2 do begin NWCorner.TabCor.Cells[i,table.RowCount-1]:=table.Cells[i,table.RowCount-1]; NWCorner.TabCor.Cells[i,0]:=table.Cells[i,0]; end; n := table.RowCount-1; m:= table.ColCount-1; for i:=1 to n-1 do for j:=1 to m-1 do begin If strtoint(NWCorner.TabCor.Cells[j,m])<>0 then if strtoint(NWCorner.TabCor.Cells[j,m])>strtoint(NWCorner.TabCor.Cells[n,i]) then begin NWCorner.TabCor.Cells[j,i]:=NWCorner.TabCor.Cells[n,i]; NWCorner.TabCor.Cells[j,m]:= inttostr(strtoint(NWCorner.TabCor.Cells[j,m])-strtoint(NWCorner.TabCor.Cells[n,i])); NWCorner.TabCor.Cells[n,i]:= inttostr(0); end else if strtoint(NWCorner.TabCor.Cells[j,m])<strtoint(NWCorner.TabCor.Cells[n,i]) then begin NWCorner.TabCor.Cells[j,i]:=NWCorner.TabCor.Cells[j,m]; NWCorner.TabCor.Cells[n,i]:= inttostr(strtoint(NWCorner.TabCor.Cells[n,i])-strtoint(NWCorner.TabCor.Cells[j,m])); NWCorner.TabCor.Cells[n,i]:= inttostr(0); end else begin NWCorner.TabCor.Cells[j,i]:=NWCorner.TabCor.Cells[j,m]; NWCorner.TabCor.Cells[j,m]:= inttostr(0); NWCorner.TabCor.Cells[n,i]:= inttostr(0); end; end;
Примечание: table - исходная таблица, NWCorner - StringGrid на новой форме. Подскажите, пожалуйста, что я не так делаю. Буду очень признательна. Спасибо!