Нахождение оптимального плана транспортной задачи распределительным методом
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
0); // коэффициенты[i,j]: =StrToIntDef (StringGrid1. Cells [j, i],0); // копия коэффициентов[i,j]: =0; // обнуляем массив;i: =1 to cc do[i]: =StrToIntDef (StringGrid1. Cells [i,rc+1],0); // коэффициенты при "потребитель"i: =1 to rc do[i]: =StrToIntDef (StringGrid1. Cells [cc+1, i],0); // коэффициенты при "производитель"(ComboBox1. Text=Минимального элемента) then
begin(min0) and (koef2 [i,j] < min) then: =koef2 [i,j]; // min элемент = koef2 [i,j]
k: =i; // первый индекс минимального элемента: =j; // второй индекс минимального элемента;;[k,p]: =0; // в массиве коэффициенты минимальному элементу присваиваем 0 чтоб программа не брала его снова
if (fund [k] 999999) then
if fund [k] >= need [p] then // количество производителей >= количества потребителей
begin[k,p]: =need [p];[k]: =fund [k] - need [p];[p]: =0;i: =k to rc doj: =p to p do[i,j]: =0;fund [k] =need [p] theno: =k to k dol: =p to cc do
koef2 [o,l]: =0;;// количество производителей < количества потребителей
if min= need [j] then[i,j]: =need [j];[i]: =fund [i] - need [j];[j]: =0;[i,j]: =fund [i];[j]: =need [j] - fund [i];[i]: =0;mas123 [i,j]: =0;;: =0;. StringGrid1. ColCount: =cc+2;. StringGrid1. RowCount: =rc+2;. StringGrid2. ColCount: =cc+2;. StringGrid2. RowCount: =rc+2;i: =1 to rc doj: =1 to cc domas123 [i,j] =0 then Form2. StringGrid1. Cells [j, i]: =Form2. StringGrid1. Cells [j, i]: =IntToStr (mas123 [i,j]);: =sum+mas123 [i,j] *koef [i,j];;2. Edit1. Text: =IntToStr (sum); // выводим значение целевой функции в Edit
raspred_metod (mas123);. Show;
end;TForm1. pereraspred (i: integer); // осуществляется построение следующего опорного плана
var,e,w,rc,cc,min: integer;
mas2: arr;: =Form2. StringGrid1. RowCount-2;: =Form2. StringGrid1. ColCount-2;q: =1 to rc dow: =1 to cc do[q,w]: =mas [q,w]; // копия опорного плана
// *****достаем адреса ячеек, которые были записаны при составлении контура**
for q: =0 to k-1 do: =0;: =2;w0) then[contur [i,w],contur [i,w+1]]: =abs (mas2 [contur [i,w],contur [i,w+1]] - min);: =w+2;;q: =0 to Length (contur) - 1 dow: =0 to rc*cc*2-1 do[q,w]: =0; // онуляем контур_metod (mas2);
end;TForm1. proced; // процедура для нахождения отрицательного значения по сумме контура
var,j,max,nom_max,rc,cc,sum1: integer;: array of integer;: boolean;: =false;: =Form2. StringGrid1. RowCount-2;: =Form2. StringGrid1. ColCount-2;(massiv,k);: =-1;i: =0 to k-1 do: =j+1;abs (contur [i,rc*cc*2-1]) <>contur [i,rc*cc*2-1] then: =true;[j]: =i; // номер контура
end;;flag=false then // если flag=false тогда программа прекращает расчет и выводит оптимальный план и значение ЦФ
begin: =0;i: =1 to rc doj: =1 to cc domas [i,j] =0 then Form2. StringGrid2. Cells [j, i]: =Form2. StringGrid2. Cells [j, i]: =IntToStr (mas [i,j]);: =sum1+mas [i,j] *koef [i,j];;. Edit2. Text: =IntToStr (sum1);: =0;_max: =0;i: =0 to k-1 domassiv [i] <>0 thenabs (max) <abs (contur [massiv [i],rc*cc*2-1]) then
begin_max: =massiv [i]; // номер максимального по модулю контура с нуля
max: =contur [massiv [i],rc*cc*2-1];
end;;(nom_max);;TForm1. raspred_metod (mas12: arr);
var,j,q,w,rc,cc: integer; // переменные для массива
begin: =Form2. StringGrid1. RowCount-2;: =Form2. StringGrid1. ColCount-2;i: =1 to rc doj: =1 to cc do[i,j]: =mas12 [i,j];i: =1 to rc doj: =1 to cc domas [i,j] =0 then: =k+1;(contur,k,rc*cc*2);(aPath,rc*cc*2);q: =0 to Length (aPath) - 1 do aPath [q]: =0; (i,j); // находим контур
// Form2. Memo1. Lines. Add (Контур + IntToStr (i) + + IntToStr (j));
// Form2. Memo1. Lines. Add (Ячейки: );q: =k-1 to k-1 do: =;w: =0 to rc*cc*2-1 doaPath [w] <>0 then[q,w]: = aPath [w];: =s+IntTostr (contur [q,w]) + ;;
// Form2. Memo1. Lines. Add (s);;;;: =-1;i0 then koef2 [contur [i,j],contur [i,j+1]]: =koef [contur [i,j],contur [i,j+1]] * (-1)koef2 [contur [i,j],contur [i,j+1]]: =koef [contur [i,j],contur [i,j+1]];[i,rc*cc*2-1]: =contur [i,rc*cc*2-1] +koef2 [contur [i,j],contur [i,j+1]];;: =j+2;: =q+1;;;();;TForm1. sum_pot (StringGrid: TStringGrid): integer;,j: integer;: =0;i: =StringGrid. ColCount-1 to StringGrid. ColCount-1 doj: =1 to StringGrid1. RowCount-1 do: =result+StrToIntDef (StringGrid. Cells [i,j],0);;TForm1. sum_proiz (StringGrid: TStringGrid): integer;,j: integer;: =0;i: =1 to StringGrid. ColCount-1 doj: =StringGrid1. RowCount-1 to StringGrid1. RowCount-1 do: =result+StrToIntDef (StringGrid. Cells [i,j],0);;TForm1. StringGrid1DrawCell (Sender: TObject; ACol, ARow: Integer;: TRect; State: TGridDrawState);
// окраска последнего столбца и последней строки StringGrid1 в оранжевый цветArow=StringGrid1. RowCount-1 then. Canvas. Brush. Color: =clHighlight; // цвет. Canvas. FillRect (Rect); // Закрашиваем задний фон. Canvas. TextOut (Rect. Left,Rect. Top,StringGrid1. Cells [Acol,Arow]); // закрашиваем текст, и выравнивание текста
end;ACol=StringGrid1. ColCount-1 then. Canvas. Brush. Color: =clHighlight;. Canvas. FillRect (Rect);. Canvas. TextOut (Rect. Left,Rect. Top,StringGrid1. Cells [Acol,Arow]);;;TForm1. StringGrid1KeyPress (Sender: TObject; var Key: Char);( (not (key in [0. 9])) and (key<>#8)) then key: = #0;(StringGRid1. Col=StringGrid1. ColCount-1) and (StringGRid1. Row=StringGrid1. RowCount-1) then: =#0;;TForm1. StringGrid1GetEditText (Sender: TObject; ACol,: Integer; var Value: String);
var: HWND; // указатель на дескриптор окна// handle это индефикатор объекта указатель
h: = GetTopWindow ( (Sender as TStringGrid). Handle); // h присваиваем handle компонента stringgridh <> 0 then(h). Perform (EM_SETLIMITTEXT, 5, 0); // находим handle и устанавливаем max количество символов 5
end;TForm1. SpinEdit1Change (Sender: TObject);,j,rc,cc: integer;: =StringGrid1. RowCount; // строки: =StringGrid1. ColCount; // столбцыi: =1 to cc doj: =1 to rc do. Cells [i,j]: =; // очищаем таблицу
StringGrid1. ColCount: =SpinEdit1. Value+2; // увеличиваем количество столбцов
StringGrid1. Cells [StringGrid1. ColCount-2,0]: =A+IntToStr (StringGrid1. ColCount-2); // назначаем имя столбцу. Cells [StringGrid1. ColCount-1,0]: =Производители; // назначаем имя последнего столбца. Cells [StringGrid1. ColCount-1,StringGrid1. RowCount-1]: =A; // назначаем имя таблицы
end;
procedure TForm1. SpinEdit2Change (Sender: TObject);,j,rc,cc: integer;: =StringGrid1. RowCount; // строки: =StringGrid1. ColCount; // столбцыi: =1 to cc-1 doj: =1 to rc do. Cells [i,j]: =; // очищаем таблицу
StringGrid1. RowCount: =SpinEdit2. Value+2; // увеличиваем количество строк
StringGrid1. Cells [0,StringGrid1. RowCount-2]: =B+IntToStr (StringGrid1. RowCount-2); // назначаем имя строки. Cells [0,StringGrid1. RowCount-1]: =Потребители; // назначаем имя последней строки. Cells [StringGrid1. ColCount-1,StringGrid1. RowCount-1]: =A; // назначаем имя таблицы
end;
procedure TForm1. SpinEdit1KeyPress (Sender: TObject; var Key: Char);: =#0;;TForm1. SpinEdit2KeyPress (Sender: TObject; var Key: Char);: =#0;;TForm1. Button2Click (Sender: TObject);(Автором этой программы являеться студент группы ПО-305+ #13#10+ УГК имени И.И. Ползунова-- - Ищенко Евгений);
end;.