一个问题 (300分)

  • 主题发起人 主题发起人 zhengzhijia
  • 开始时间 开始时间
Z

zhengzhijia

Unregistered / Unconfirmed
GUEST, unregistred user!
[purple][?]各位大虾:
近来我遇到一个与统筹学有关的内容,可是看了数遍,也弄不清如何实现算法.如果那位
对数学或者算法有研究;或者您有统筹学软件包,能否帮帮我,我必将300奉上.谢谢[/purple]
 
问题呢?
 
约束方程组:
X1+ X2+ X3+ X4+ X5+ X6 = 1000
3.31 X1+ 3.23 X2+ 3.38 X3+ 2.77 X4+ 2.62 X5 >= 3100
65.0 X1+ 40.2 X2+ 7.80 X3+ 6.80 X4+ 14.6 X5 >= 14000
4.90 X2+ 1.60 X3+ 8.20 X4+ 10.8 X5 <= 4500
4.80 X1+ 0.32 X2+ 0.09 X3+ 0.03 X4+ 0.27 X5+ 30.50 X6>= 500
3.10 X1+ 0.50 X2+ 0.26 X3+ 0.27 X4+ 1.01 X5+ 14.30 X6>= 410
1.69 X1+ 1.01 X2+ 0.26 X3+ 0.26 X4+ 0.50 X5 >= 370
X1>= 20
目标
0.2* X1 + 0.3* X2 + 0.6 * X3 ...和最小,或小于某一个值
这只是个例子,我需要一个通用算法.
 
我做过它,算法是我自己写的,很长呀。估计有1000多行,其中包括了表达式自动识别:即
只要你按课本上的写法输入表达式,程序会自动求出最优解及所有可行解。我的信箱是:
yzrlz@elong.com
 
rlz:
能否将你的源码发给我,保定给你加300,谢谢
 
我的邮箱:
zhengzhijia@sohu.com
 
大家表个态,是不是都休息去啦.
 
我还是不很懂你的问题意思
 
线形规划的单纯形法子程序,给你一堆,自己慢慢看。来自于《Delphi常用数值算法》,网上有
该书光盘的下载,不记得网址了。
Procedure SIMPLX(var A:matrx2;
M, N, MP, NP, M1, M2, M3:integer;
var ICASE:integer;var IZROV, IPOSV:array of integer);
Label 1,2,3,4;
const
EPS =0.000001;
var
L1,L2,L3:array[0..100] of integer;
K,I,NL1,NL2,IR,KP,M12,IP,IQ,KH:integer;
Q1,BMAX:real;
begin
If M <> M1 + M2 + M3 then
begin
ShowMessage(' Bad input constraint counts');
Exit;
end;
NL1:=N;
For K:=1 To N do
begin
L1[K]:=K;
IZROV[K]:=K;
end;

NL2:=M;
For I:=1 To M do
begin
If A[I + 1, 1] < 0 then
begin
ShowMessage('Bad input tableau.');
Exit;
end;
L2:=I;
IPOSV:=N + I;
end;
For I:=1 To M2 do
L3:=1;
IR:=0;
If M2 + M3 = 0 then
GoTo 3;
IR:=1;
For K:=1 To N + 1 do
begin
Q1:=0;
For I:=M1 + 1 To M do
Q1:=Q1 + A[I + 1, K];
A[M + 2, K]:=-Q1;
end;
repeat
SIMP1(A, MP, NP, M + 1, L1, NL1, 0, KP, BMAX);
If (BMAX <= EPS) And (A[M + 2, 1] < -EPS) then
begin
ICASE:=-1;
Exit;
end
else
If (BMAX <= EPS) And (A[M + 2, 1] <= EPS) then
begin
M12:=M1 + M2 + 1;
If M12 <= M then
begin
For IP:=M12 To M do
begin
If IPOSV[IP] = IP + N then
begin
SIMP1(A, MP, NP, IP, L1, NL1, 1, KP, BMAX);
If BMAX > 0 then
GoTo 1;
end;
end;
end;
IR:=0;
M12:=M12 - 1;
If M1 + 1 > M12 then
Exit;
For I:=M1 + 1 To M12 do
begin
If L3[I - M1] = 1 then
begin
For K:=1 To N + 1 do
A[I + 1, K]:=-A[I + 1, K];
end;
end;
goto 3;
end;
SIMP2(A, M, N, MP, NP, L2, NL2, IP, KP, Q1);
If IP = 0 then
begin
ICASE:=-1;
Exit;
end;
1: SIMP3(A, MP, NP, M + 1, N, IP, KP);
If IPOSV[IP] >= N + M1 + M2 + 1 then
begin
For K:=1 To NL1 do
If L1[K] = KP then
goto 4;
4: NL1:=NL1 - 1;
For IQ:=K To NL1 do
L1[IQ]:=L1[IQ + 1];
end
else
begin
If IPOSV[IP] < N + M1 + 1 then
GoTo 2;
KH:=IPOSV[IP] - M1 - N;
If L3[KH] = 0 then
GoTo 2;
L3[KH]:=0;
end;
A[M + 2, KP + 1]:=A[M + 2, KP + 1] + 1;
For I:=1 To M + 2 do
A[I, KP + 1]:=-A[I, KP + 1];
2: IQ:=IZROV[KP];
IZROV[KP]:=IPOSV[IP];
IPOSV[IP]:=IQ;
until IR <> 0;
3: SIMP1(A, MP, NP, 0, L1, NL1, 0, KP, BMAX);
If BMAX <= 0 then
begin
ICASE:=0;
Exit;
end;
SIMP2(A, M, N, MP, NP, L2, NL2, IP, KP, Q1);
If IP = 0 then
begin
ICASE:=1;
Exit;
end;
SIMP3(A, MP, NP, M, N, IP, KP);
GoTo 2;
end;
Procedure SIMP1(var A:matrx2;
MP, NP, MM:integer;
LL:array of integer;
NLL, IABF:integer;var KP:integer;
var BMAX:real);
var
K:integer;
TEST:real;
begin
KP:=LL[1];
BMAX:=A[MM + 1, KP + 1];
For K:=2 To NLL do
begin
If IABF = 0 then
TEST:=A[MM + 1, LL[K] + 1] - BMAX
else
TEST:=Abs(A[MM + 1, LL[K] + 1]) - Abs(BMAX);
If TEST > 0 then
begin
BMAX:=A[MM + 1, LL[K] + 1];
KP:=LL[K];
end;
end;
end;
Procedure SIMP2(var A:matrx2;
M, N, MP, NP:integer;
L2:array of integer;
NL2:integer;var IP, KP:integer;
Q1:real);
label 1,2;
const
EPS = 0.000001;
var
I,J,II,K:integer;
FLAG,Q,QP,Q0:real;
begin
IP:=0;
FLAG:=0;
For I:=1 To NL2 do
begin
If A[L2 + 1, KP + 1] < -EPS then
FLAG:=1;
If FLAG = 1 then
goto 1;
end;
1: If FLAG = 0 then
Exit;
Q1:=-A[L2 + 1, 1] / A[L2 + 1, KP + 1];
IP:=L2;
For I:=I + 1 To NL2 do
begin
II:=L2;
If A[II + 1, KP + 1] < -EPS then
begin
Q:=-A[II + 1, 1] / A[II + 1, KP + 1];
If Q < Q1 then
begin
IP:=II;
Q1:=Q;
end
else
If Q = Q1 then
begin
For K:=1 To N do
begin
QP:=-A[IP + 1, K + 1] / A[IP + 1, KP + 1];
Q0:=-A[II + 1, K + 1] / A[II + 1, KP + 1];
If Q0 <> QP then
goto 2;
end;
2: If Q0 < QP then
IP:=II;
end;
end;
end;
end;

Procedure SIMP3(var A:matrx2;
MP, NP, I1, K1:integer;var IP, KP:integer);
var
PIV:real;
II,KK:integer;
begin
PIV:=1 / A[IP + 1, KP + 1];
For II:=1 To I1 + 1 do
begin
If II - 1 <> IP then
begin
A[II, KP + 1]:=A[II, KP + 1] * PIV;
For KK:=1 To K1 + 1 do
begin
If KK - 1 <> KP then
A[II, KK]:=A[II, KK] - A[IP + 1, KK] * A[II, KP + 1];
end;
end;
end;
For KK:=1 To K1 + 1 do
If KK - 1 <> KP then
A[IP + 1, KK]:=-A[IP + 1, KK] * PIV;
A[IP + 1, KP + 1]:=PIV;
end;

 
所有这些为验证上述子过程而编的验证过程
implementation
//PROGRAM D9R10
//Driver for routine SIMPLX
uses
unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
const
s1='%8.2f';
N = 4;
M = 4;
NP = 5;
MP = 6;
M1 = 2;
M2 = 1;
M3 = 1;
NM1M2 = N+M1+M2;
var
F:TextFile;
A:matrx2;
IZROV,IPOSV:array[0..4] of integer;
ANUM:array[0..5] of real;
TXT:array[0..7] of string;
ALPHA:array[0..5] of string;
I,J,JJ,JMAX,ICASE:integer;
STR1,STR2,STR3:string;
begin
SetLength(A,7,6);
TXT[1]:='x1';
TXT[2]:='x2';
TXT[3]:='x3';
TXT[4]:='x4';
TXT[5]:='y1';
TXT[6]:='y2';
TXT[7]:='y3';
A[1, 1]:=0;
A[1, 2]:=1;
A[1, 3]:=1;
A[1, 4]:=3;
A[1, 5]:=-0.5;
A[2, 1]:=740;
A[2, 2]:=-1;
A[2, 3]:=0;
A[2, 4]:=-2;
A[2, 5]:=0;
A[3, 1]:=0;
A[3, 2]:=0;
A[3, 3]:=-2;
A[3, 4]:=0;
A[3, 5]:=7;
A[4, 1]:=0.5;
A[4, 2]:=0;
A[4, 3]:=-1;
A[4, 4]:=1;
A[4, 5]:=-2;
A[5, 1]:=9;
A[5, 2]:=-1;
A[5, 3]:=-1;
A[5, 4]:=-1;
A[5, 5]:=-1;
A[6, 1]:=0;
A[6, 2]:=0;
A[6, 3]:=0;
A[6, 4]:=0;
A[6, 5]:=0;
SIMPLX(A, M, N, MP, NP, M1, M2, M3, ICASE, IZROV, IPOSV);
//输出计算结果到文件
AssignFile(F, 'd:/delphi_shu/p9/d9r10.dat');
Rewrite(F);
Writeln(F);
If ICASE = 1 then
Writeln(F, ' Unbounded objective function')
else
If ICASE = -1 then
Writeln(F, ' No solutions satisfy constraints given');
JJ:=1;
For I:=1 To N do
begin
If IZROV <= N + M1 + M2 then
begin
ALPHA[JJ]:=TXT[IZROV];
JJ:=JJ + 1;
end;
end;
JMAX:=JJ - 1;
Writeln(F);
STR1:=' ';
For JJ:=1 To JMAX do
STR1:=STR1 + ALPHA[JJ]+' ';
Writeln(F, ' ',STR1);
For I:=1 To M + 1 do
begin
If I > 1 then
ALPHA[1]:=TXT[IPOSV[I - 1]]
else
ALPHA[1]:=' ';
ANUM[1]:=A[I, 1];
JJ:=2;
For J:=2 To N + 1 do
begin
If IZROV[J - 1] <= (N + M1 + M2) then
begin
ANUM[JJ]:=A[I, J];
JJ:=JJ + 1;
end;
end;
JMAX:=JJ - 1;
STR2:=' ';
For JJ:=1 To JMAX do
begin
STR3:=' ';
STR3:=COPY(FloatToStr(ANUM[JJ]),1,7);
STR2:= STR2 + STR3 + ' ';
end;
Writeln(F, ALPHA[1],STR2);
end;
CloseFile(F);
//屏幕显示计算结果
memo1.Lines.LoadFromFile('d:/delphi_shu/p9/d9r10.dat');
end;
 
redfox:
我试一试,好的话全部给你。
WebExplorer:
求出我所列出方程的最优解!要得是算法;
谢谢各位!
 
redfox:
能否给个参数说明;
声明中 var A:matrx2 中; matrx2类型是如何定义的,我好像没发现定义方式
 
你去找本《运筹学教程》清华的,第一章就是这个问题,这种算法只有自己去理解,基本上
是看懂算法就可以写出程序(那上面是个通用的)
 
我从找书,到看懂,在写算法;黄花菜都凉啦!
 
哈哈!
我手头就有一本!
看懂就是看懂它的流程,不要看懂原理!
还是去找找吧!
 
多人接受答案了。
 
后退
顶部