运筹学实验报告.docx
- 文档编号:28885106
- 上传时间:2023-07-20
- 格式:DOCX
- 页数:26
- 大小:28KB
运筹学实验报告.docx
《运筹学实验报告.docx》由会员分享,可在线阅读,更多相关《运筹学实验报告.docx(26页珍藏版)》请在冰豆网上搜索。
运筹学实验报告
运筹学实验报告
专业:
班级:
姓名:
学号:
指导教师:
数学与应用数学专业
2015-12-18
实验目录
一、实验目的
1、会利用适当的方法建立相关实际问题的数学模型;
2、会用数学规划思想及方法解决实际问题;
3、会用排队论思想及方法解决实际问题;
4、会用决策论思想及方法解决实际问题;
5、掌握MATLAB、LINGO等数学软件的应用;
2、实验要求
1、七人一组每人至少完成一项实验内容;
2、每组上交一份实验报告;
3、每人进行1~2分钟实验演示;
4、实验成绩比例:
出勤:
40%
课堂提问:
20%
实验报告:
30%
实验演示:
10%。
3、实验内容
1、线性规划
例运筹学74页14题
Minz=-2x1-x2
s.t.2x1+5x2≤60
x1+x2≤18
3x1+x2≤44
X2≤10
X1,x2≥0
用matlab运行后得到以下结果:
theprogramiswiththelinearprogramming
Pleaseinputtheconstraintsnumberofthelinearprogrammingm=6
m=
6
Pleaseinputthevariantnumberofthelinearprogrammingn=2
n=
2
Pleaseinputcostarrayoftheobjectivefunctionc(n)_T=[-2,-1]'
c=
-2
-1
PleaseinputthecoefficientmatrixoftheconstraintsA(m,n)=[2,5;1,1;3,1;0,1;-1,0;0,-1]
A=
25
11
31
01
-10
0-1
Pleaseinputtheresourcearrayoftheprogramb(m)_T=[60,18,44,10,0,0]'
b=
60
18
44
10
0
0
Optimizationterminated.
Theoptimizationsolutionoftheprogrammingis:
x=
13.0000
5.0000
Theoptimizationvalueoftheprogrammingis:
opt_value=
-31.0000
LINDO程序
在命令窗口键入以下内容:
max-2x-y
subjectto
2x+5y<=60
x+y<=18
3x+y<=44
y<=10
end
按solve键在reportswindow出现:
Globaloptimalsolutionfound.
Objectivevalue:
0.000000
Totalsolveriterations:
0
VariableValueReducedCost
X0.0000002.000000
Y0.0000001.000000
RowSlackorSurplusDualPrice
10.0000001.000000
260.000000.000000
318.000000.000000
444.000000.000000
510.000000.000000
2、整数规划
课本第二章79页1题
Maxz=100x1+180x2+70x3
s.t.40x1+50x2+60x3≤10000
3x1+6x2+2x3≤600
x1≤130
X2≤80
x3≤200
x1x2x3≥0
程序运行及结果:
biprogram
the program is with the binary linear programming
Please input the constraints number of the programming m=5
m =
5
Please input the variant number of the programming n=5
n =
5
Please input cost array of the objective function c(n)_T=[100,180,70]'
c =
100
180
70
Please input the coefficient matrix of the constraints A(m,n)=[40,50,60;3,6,2;1,0,0;0,1,0;0,0,1]
A =
40 50 60
3 6 2
1 0 0
0 1 0
0 0 1
Please input the resource array of the program b(m)_T=[10000;600;130;80;200]
b =
10000
600
130
80
200
Optimization terminated.
The optimization solution of the programming is:
x =
0
0
0
The optimization value of the programming is:
opt_value =
0
程序名:
intprogramb程序说明:
% the programm is with the integer linear programming use branch and bound method!
%这个程序是用分支定界法解决整数规划问题
% please input the parameters in the main function in the command winows
%请在命令窗口输入这个主要定义函数的参数
function [x,f]=ILp(c,A,b,vlb,vub,x0,neqcstr,pre)
% min f=c'*x,s.t. A*x<=b,vlb<=x<=vub
% f的最小值等于c的转置乘以x,A乘以x小于等于b,x大于等于vlb小于等于vub
% the vectors of x is required as integers as whole
% x是整个的整数需要
% x0 is the initialization,'[]' is also ok
% x0是初始值,"[]"也可以是。
% neqcstr is the number of equational constraints,when 0 can be delete
% neqcstr是平均约束条件的数目,当0能删除时
% pre is the concise rate
% pre是简明率
% x is the integer optimization and f is the optimal value
% x是整数规划,f 是最优值
%%%%%%%%%%%%%%%%
if nargin<8,pre=0; % nargin is the factually input variants number (这个参数是实际输入的变量个数)
if nargin<7,neqcstr=0;
if nargin<6,x0=[];
if nargin<5,vub=[];
if nargin<4,vlb=[];
end
end
end
end
end
%%%%%%%%%%%%%%%%%%
% set to column vectors
%建立列向量
x0=x0(:
);
c=c(:
);
b=b(:
);
vlb=vlb(:
);
vub=vub(:
);
mm=1;
j=1;
nvars=length(c'); % number of variants(变量的个数)
fvub=inf;
xall=[];
fall=[];
x_f_b=[];
[xtemp,ztemp,how]=lp(c,A,b,vlb,vub,x0,neqcstr,-1);
ftemp=c'*xtemp;
%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(how,'ok') % compare between how and ok(how和ok之间的比较)
temp0=round(xtemp);%临时变量四舍五入
temp1=floor(xtemp);%取比其小的整数
temp2=find(abs(xtemp-temp0)>pre);
mtemp=length(temp2);
if ~isempty(temp2)
x_f_b=[xtemp;ftemp;vlb;vub];
while j<=mm
i=1;
while i<=mtemp
%%%%%%%%%%%%%%%%%%%%%
if x_f_b(nvars+1,j)<=fvub
vlbl=x_f_b(nvars+2:
2*nvars+1,j);
vubl=x_f_b(2*nvars+2:
3*nvars+1,j);
vubl(temp2(i))=temp1(temp2(i));
[xtemp,z,how]=lp(c,[A;c'],[b;fvub],vlbl,vubl,x0,neqcstr,-1);
ftemp=c'*xtemp;
if strcmp(how,'ok')
templ0=round(xtemp);
templ1=floor(xtemp);
templ2=find(abs(xtemp-templ0)>pre);
if isempty(templ2)
xall=[xall,xtemp];
fall=[fall,ftemp];
fvub=min([fvub,fall]);
elseif ftemp<=fvub
x_f_b=[x_f_b,[xtemp;ftemp;vlbl;vubl]];
end
end
end
%%%%%%%%%%%%%%%%%%
if x_f_b(nvars+1,j)<=fvub
vlbr=x_f_b(nvars+2:
2*nvars+1,j);
vlbr(temp2(i))=temp1(temp2(i))+1;
vubr=x_f_b(2*nvars+2:
3*nvars+1,j);
[xtemp,z,how]=lp(c,[A;c'],[b;fvub],vlbr,vubr,x0,neqcstr,-1);
ftemp=c'*xtemp;
if strcmp(how,'ok')
tempr0=round(xtemp);
tempr1=floor(xtemp);
tempr2=find(abs(xtemp-tempr0)>pre);
if isempty(tempr2)
xall=[xall,xtemp];
fall=[fall,ftemp];
fvub=min([fvub,fall]);
elseif ftemp<=fvub
x_f_b=[x_f_b,[xtemp;ftemp;vlbr;vubr]];
end
end
end
%%%%%%%%%%%%%%%%%%%%%
i=i+1;
end % the second while
xint=x_f_b(1:
nvars,:
);
[m,mm]=size(xint);
j=j+1;
if j>mm
break
end % the end because the break (因为中断而结束)
temp0=round(xint(:
j));
temp1=floor(xint(:
j));
temp2=find(abs(xint(:
j)-temp0)>pre);
mtemp=length(temp2);
end % the end of while(结束当前)
else % correspond the second if(符合第一个如果)
x=xtemp;
f=ftemp;
end % the end of second if(第二个如果的结束)
%%%%%%%%%%%%%%%%%%5
if ~isempty(fall)
fmin=min(fall);
nmin=find(fall==fmin);
x=xall(:
nmin);
f=fmin;
end
else % correspond the first if(符合第一个如果)
x=nan*ones(1,nvars);
end
LINDO程序
例99页第6题第二问
在命令窗口键入以下内容:
max-11x1-4x2
st
-x1+2x2<=4
5x1+2x2<=16
2x1-x2<=4
end
ginx1
ginx2
按solve键在reportswindow出现:
Globaloptimalsolutionfound.
Objectivevalue:
0.000000
Extendedsolversteps:
0
Totalsolveriterations:
0
VariableValueReducedCost
X10.00000011.00000
X20.0000004.000000
RowSlackorSurplusDualPrice
10.0000001.000000
24.0000000.000000
316.000000.000000
44.0000000.000000
3、非线性规划
程序名:
unpfun1函数
unpfun1函数执行实例:
(课本第四章152页16题)
min4x1+6x2-2x1x2-2x^2,取初始点x0=(1;1)
在命令窗口键入以下内容:
f=4*x
(1)-2*x
(1)*x
(2)-x
(2)^2-6*x
(2);
[x,fval]=fminunc(@unpfun1,x0)(调用无约束线性规划函数)
按运行按钮在solutionreport窗口得到以下结果:
Warning:
Gradientmustbeprovidedfortrust-regionmethod;
usingline-searchmethodinstead.
>Infminuncat265
Optimizationterminated:
relativeinfinity-normofgradientlessthanoptions.TolFun.
x=
1.0e-006*
0.2541-0.2029
fval=
1.3173e-013
4、动态规划
程序名:
dynamic;dynfun1_1,dynfun1_2,dynfun1_3;
例180页第一题
程序说明:
dynamic程序:
%theprogrammiswiththedynamicprogrammingusetherecurisivemethodforthelasttofirst
%thisisthemainfunctionofthemethod
function[p_opt,fval,u]=dynprog(x,DecisFun,ObjFun,TransFun)
%thefunctionistosolvethedynamicexampleinthetextbook
%xisthesituationvariantanditscolumnnumberrepresentthestagesituation
%subfunctionDecisFun(k,x)istosolvethedecisionvariantofkstagevariantx
%subfunctionObjFun(k,x,u)istostageindexfunction
%subfunctionTransFun(k,x,u)isthestagetransformationfunction,uisthecorrespondingdecisionvariant
%p_opthasfouroutput,thefirstisthenumberofthestage,thesecondistheoptimalroadofdecision
%thethirdistheoptimalstategiesofthedecision,theforthistheindexfunctiongroup.
%fvalisacolumnvector,istorepresenttheoptimalvaluecorrespendtotheinitialstageisx
%
k=length(x(1,:
));
f_opt=nan*ones(size(x));
d_opt=f_opt;
t_vubm=inf*ones(size(x));
x_isnan=~isnan(x);
t_vub=inf;
%%%%%%%%%%%%%%%%%
%tocaculatetheteminatevalues
tmp1=find(x_isnan(:
k));
tmp2=length(tmp1);
fori=1:
tmp2
u=feval(DecisFun,k,x(i,k));
tmp3=length(u);
forj=1:
tmp3
tmp=feval(ObjFun,k,x(tmp1(i),k),u(j));
iftmp<=t_vub
f_opt(i,k)=tmp;
d_opt(i,k)=u(j);
t_vub=tmp;
end
end
end
%%%%%%%%%%%%%%%%
%recurisive
forii=k-1:
-1:
1
tmp10=find(x_isnan(:
ii));
tmp20=length(tmp10);
fori=1:
tmp20
u=feval(DecisFun,ii,x(i,ii));
tmp30=length(u);
forj=1:
tmp30
tmp00=feval(ObjFun,ii,x(tmp10(i),ii),u(j));
tmp40=feval(TransFun,ii,x(tmp10(i),ii),u(j));
tmp50=x(:
ii+1)-tmp40;
tmp60=find(tmp50==0);
if~isempty(tmp60),
ifnargin<5
tmp00=tmp00+f_opt(tmp60
(1),ii+1);
iftmp00<=t_vubm(i,ii)
f_opt(i,ii)=tmp00;
d_opt(i,ii)=u(j);
t_vubm(i,ii)=tmp00;
end
end
end
end
end
end
fval=f_opt(tmp1,1);
%%%%%%%%%%%%%%%%%%
%towritetheindexandparameterorresult
p_opt=[];
tmpx=[];
tmpd=[];
tmpf=[];
tmp0=find(x_isnan(:
1));
tmp01=length(tmp0);
fori=1:
tmp01
tmpd(i)=d_opt(tmp0(i),1);
tmpx(i)=x(tmp0(i),1);
tmpf(i)=feval(ObjFun,1,tmpx(i),tmpd(i));
p_opt(k*(i-1)+1,[1,2,3,4])=[1,tmpx(i),tmpd(i),tmpf(i)];
forii=2:
k
tmpx(i)=feval(TransFun,ii-1,tmpx(i),tmpd(i));
tm
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 运筹学 实验 报告