📄 shuju.pas
字号:
unit shuju;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, Buttons,math;
const long=252;
type
Tfrmshuju = class(TForm)
panel2: TPanel;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
BitBtn1: TBitBtn;
RadioGroup1: TRadioGroup;
Label3: TLabel;
StringGrid1: TStringGrid;
BitBtn4: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmshuju: Tfrmshuju;
type myset=set of 1..long;//自定义集合类型,集合元素类型为整型,
//范围1..long。
var m,n:integer; //m供应站的数量;n需求站的数量
a:array[1..long] of Integer;//供应站的供应量(以单位计算)
b:array[1..long] of Integer;//需求站的需要量(以单位计算)
c:array[1..long] of array[1..long] of real;//运价矩阵
//c[i,j]表示从第i个供应站到第j个需求站单位产品的运输成本
x:array[1..long] of array[1..long] of Real;//运输矩阵
//x[i,j]表示从第i个供应站供应给第j个需求站x[i,j]个单位的产品
z:real;//目标函数值,即总的运输成本
r:Integer;//关键行,当前供应站的下标
s:Integer;//关键列,当前需求站的下标
rr:myset;//有待分配的供应站的下标的集合
ss:myset;//有待分配的需求站的下标的集合
u:array[1..long] of Real;//供应站的位势值
v:array[1..long] of Real;//需求站的位势值
d:array[1..long] of array[1..long] of real;//可能运费矩阵
biaoshi:array[1..long] of array[1..long] of Char;//标识符
implementation
{$R *.dfm}
uses jisuan;
procedure chushihuabianliang;
var i,j:Integer;
begin
for i:=1 to long do
begin
for j:=1 to long do
begin
c[i,j]:=0;
x[i,j]:=0;
d[i,j]:=0;
biaoshi[i,j]:=#0;
end;
a[i]:=0;
b[i]:=0;
u[i]:=0;
v[i]:=0;
end;
r:=0;
s:=0;
rr:=[];//空集合
ss:=[];//空集合
z:=0; //目标函数值,最小运费
end;
{-------------初始化所有全局变量变量----------------------------------}
procedure Tfrmshuju.BitBtn1Click(Sender: TObject);
var i,j:Integer;
begin
m:=StrToInt(Edit1.Text);//读取供应站的数量
n:=StrToInt(Edit2.Text);//读取需求站的数量
with StringGrid1 do
begin
RowCount:=m+2;
ColCount:=n+2;//动态设置行数和列数
Width:=ColCount*(DefaultColWidth+2);
Height:=RowCount*(DefaultRowHeight+2);//动态调整宽度和高度
top:=(panel2.Height-Height) div 2-20;
Left:=(panel2.Width-Width) div 2;//动态调整位置
for i:=1 to m do
Cells[0,i]:='A'+IntToStr(i);
for j:=1 to n do
Cells[j,0]:='B'+IntToStr(j);
Cells[0,0]:='供\需';
Cells[0,m+1]:='需求量';
Cells[n+1,0]:='供应量';//设置表框
end;
end;
{-------------------控制调整输入界面----------------------------------}
procedure Tfrmshuju.BitBtn4Click(Sender: TObject);
var i,j:Integer;
begin
chushihuabianliang;
m:=StrToInt(Edit1.Text);//读取供应站的数量
n:=StrToInt(Edit2.Text);//读取需求站的数量
for i:=1 to m do
for j:=1 to n do
if StringGrid1.Cells[j,i]<>'' then
c[i,j]:=StrToFloat(StringGrid1.Cells[j,i]);
//读取运价矩阵
for i:=1 to m do
if StringGrid1.Cells[n+1,i]<>'' then
a[i]:=StrToint(StringGrid1.Cells[n+1,i]);
//读取供应量
for j:=1 to n do
if StringGrid1.Cells[j,m+1]<>'' then
b[j]:=StrToint(StringGrid1.Cells[j,m+1]);
//读取需求量
frmjisan.Show;
frmshuju.Hide;
end;
{----------读取已知条件,运价矩阵、供应量、需求量------------}
procedure Tfrmshuju.BitBtn2Click(Sender: TObject);
var i,j:Integer;
begin
for i:=1 to StringGrid1.RowCount-1 do
for j:=1 to StringGrid1.ColCount-1 do
StringGrid1.Cells[j,i]:='';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -