整数线性规划word版.docx
《整数线性规划word版.docx》由会员分享,可在线阅读,更多相关《整数线性规划word版.docx(13页珍藏版)》请在冰豆网上搜索。
整数线性规划word版
第三章整数线性规划
本章,我们介绍三种解决整数线性规划问题的软件:
第一种:
MATLAB中的optimizationtoolbox中的若干程序;
第二种:
LINDO软件;
第二种:
LINGO软件.
1.MATLAB程序说明
程序名:
intprogram,L01p_e,L01p_ie,transdetobi,biprogram
intprogram是利用分支定界法解决整数规划问题,是全部的整数规划问题;
L01p_e是利用枚举法解决0-1规划问题,变量要求全部为0或者1;
L01p_ie是利用隐枚举法解决0-1规划问题,变量要求全部为0或者1;
Transdetobi是枚举法和隐枚举法中利用到的将十进制数转化为二进制数的函数;
Biprogram是MATLAB6.5以上版本中有的求解0-1规划的函数的程序.
intprogram执行实例1:
在命令窗口的程序执行过程和结果如下:
>>c=[-20,-10];%将最大转化为最小;
>>a=[5,4;2,5];
>>b=[24;13];
>>[x,f]=intprogram(c,a,b,[0;0],[inf;inf],[],0,0.0001)%c,a,b之后[0;0]isthevalueoflowbound;[inf;inf]isthevalueofupbound;[]istheinitialization;0isthenumberoftheequationconstraints;0.0001istheconciserate.
x=
4.0000
1.0000
f=
-90
intprogram执行实例2:
书中例题3.3.1
在命令窗口的程序执行过程和结果如下:
>>c=[-1,-1];
>>a=[-4,2;4,2;0,-2];
>>b=[-1;11;-1];
>>[x,f]=intprogram(c,a,b,[0;0],[inf;inf],[],0,0.0001)
x=
22
11
f=
-3
L01p_e和L01p_ie执行实例:
在命令窗口的程序执行过程和结果如下:
>>c=[3,-2,5];%将最大转化为最小;
>>a=[1,2,-1;1,4,1;1,1,0;0,4,1];
>>b=[2;4;3;6];
>>x1=L01p_e(c,a,b);x2=L01p_ie(c,a,b);%x1表示利用枚举法解决0-1规划问题,x2表示用隐%枚举法解决问题,结果是一样的
>>x1
x1=
0
1
0
>>x2
x2=
0
1
0
biprogram执行实例:
在命令窗口的程序执行过程和结果如下:
theprogramiswiththebinarylinearprogramming
Pleaseinputtheconstraintsnumberoftheprogrammingm=4
m=
4
Pleaseinputthevariantnumberoftheprogrammingn=4
n=
4
Pleaseinputcostarrayoftheobjectivefunctionc(n)_T=[-9,-5,-6,-4]'
c=
-9
-5
-6
-4
PleaseinputthecoefficientmatrixoftheconstraintsA(m,n)=[6,3,5,2;0,0,1,1;
-1,0,1,0;0,-1,0,1]
A=
6352
0011
-1010
0-101
Pleaseinputtheresourcearrayoftheprogramb(m)_T=[9,1,0,0]'
b=
9
1
0
0
Optimizationterminatedsuccessfully.
x=
1
1
0
0
程序的相关知识:
Solvebinaryintegerprogrammingproblemsoftheform
wheref,b,andbeqarevectors,AandAeqarematrices,andthesolutionxisrequiredtobeabinaryintegervector--thatis,itsentriescanonlytakeonthevalues0or1.
语法如下:
x=bintprog(f)
x=bintprog(f,A,b)
x=bintprog(f,A,b,Aeq,beq)
x=bintprog(f,A,b,Aeq,beq,x0)
x=bintprog(f,A,b,Aeq,beq,x0,options)
[x,fval]=bintprog(...)
[x,fval,exitflag]=bintprog(...)
[x,fval,exitflag,output]=bintprog(...)
解释:
x=bintprog(f)solvesthebinaryintegerprogrammingproblem
x=bintprog(f,A,b)solvesthebinaryintegerprogrammingproblem
x=bintprog(f,A,b,Aeq,beq)solvestheprecedingproblemwiththeadditionalequalityconstraint.
x=bintprog(f,A,b,Aeq,beq,x0)setsthestartingpointforthealgorithmtox0.Ifx0isnotinthefeasibleregion,bintprogusesthedefaultinitialpoint.
x=bintprog(f,A,b,Aeq,Beq,x0,options)minimizeswiththedefaultoptimizationoptionsreplacedbyvaluesinthestructureoptions,whichyoucancreateusingthefunctionoptimset.
[x,fval]=bintprog(...)returnsfval,thevalueoftheobjectivefunctionatx.
[x,fval,exitflag]=bintprog(...)returnsexitflagthatdescribestheexitconditionofbintprog.SeeOutputArguments.
[x,fval,exitflag,output]=bintprog(...)returnsastructureoutputthatcontainsinformationabouttheoptimization.SeeOutputArguments.
2.LINDO程序说明
LINDO也提供了解决全整数规划、混合整数规划以及0-1规划的方法.
2.1解决全整数规划问题
程序名:
intlpall
intlpall执行实例:
在命令窗口键入以下内容:
max11x+10y
st
2x+y<12
x-3y>1
end
ginx!
thegeneralintegerstatement–GIN将变量约束为整数
giny!
thegeneralintegerstatement–GIN将变量约束为整数
按solve键在reportswindow出现:
LPOPTIMUMFOUNDATSTEP7
OBJECTIVEVALUE=72.4285736
NEWINTEGERSOLUTIONOF66.0000000ATBRANCH0PIVOT12
BOUNDONOPTIMUM:
66.00000
ENUMERATIONCOMPLETE.BRANCHES=0PIVOTS=12
LASTINTEGERSOLUTIONISTHEBESTFOUND
RE-INSTALLINGBESTSOLUTION...
OBJECTIVEFUNCTIONVALUE
1)66.00000
VARIABLEVALUEREDUCEDCOST
X6.000000-11.000000
Y0.000000-10.000000
ROWSLACKORSURPLUSDUALPRICES
2)0.0000000.000000
3)5.0000000.000000
NO.ITERATIONS=12
BRANCHES=0DETERM.=1.000E0]
2.2解决混合整数规划问题:
程序名:
intlpsec
intlpsec执行实例:
在命令窗口键入以下内容:
max11x+10y
st
2x+y<12
x-3y>1
end
ginx!
onlythegeneralintegerstatement–GIN只将变量x约束为整数
按solve键在reportswindows中出现以下内容:
LPOPTIMUMFOUNDATSTEP2
OBJECTIVEVALUE=72.4285736
SETXTO>=6AT1,BND=66.00TWIN=68.3316
NEWINTEGERSOLUTIONOF66.0000000ATBRANCH1PIVOT16
BOUNDONOPTIMUM:
68.33334
FLIPXTO<=5AT1WITHBND=68.333336
NEWINTEGERSOLUTIONOF68.3333359ATBRANCH1PIVOT16
BOUNDONOPTIMUM:
68.33334
DELETEXATLEVEL1
ENUMERATIONCOMPLETE.BRANCHES=1PIVOTS=16
LASTINTEGERSOLUTIONISTHEBESTFOUND
RE-INSTALLINGBESTSOLUTION...
OBJECTIVEFUNCTIONVALUE
1)68.33334
VARIABLEVALUEREDUCEDCOST
X5.000000-14.333333
Y1.3333330.000000
ROWSLACKORSURPLUSDUALPRICES
2)0.6666670.000000
3)0.000000-3.333333
NO.ITERATIONS=17
BRANCHES=1DETERM.=1.000E0
2.3解决0-1整数规划问题:
程序名:
intlp01
intlp01执行实例:
在命令窗口键入以下内容:
max-100x+20y+12z
st
y-10x<0
y+z<11
z<7
end
intx!
约束x为0-1变量
按solve键在reportswindows中出现以下内容:
LPOPTIMUMFOUNDATSTEP3
OBJECTIVEVALUE=124.000000
SETXTO>=1AT1,BND=112.0TWIN=84.009
NEWINTEGERSOLUTIONOF112.000000ATBRANCH1PIVOT9
BOUNDONOPTIMUM:
112.0000
DELETEXATLEVEL1
ENUMERATIONCOMPLETE.BRANCHES=1PIVOTS=9
LASTINTEGERSOLUTIONISTHEBESTFOUND
RE-INSTALLINGBESTSOLUTION...
OBJECTIVEFUNCTIONVALUE
1)112.0000
VARIABLEVALUEREDUCEDCOST
X1.00000020.000000
Y10.0000000.000000
Z1.0000000.000000
ROWSLACKORSURPLUSDUALPRICES
2)0.0000008.000000
3)0.00000012.000000
4)6.0000000.000000
NO.ITERATIONS=10
BRANCHES=1DETERM.=1.000E0
3.LINGO程序说明
除了特别说明,LINGO默认变量是非负的以及连续的,但是可用以下命令使得变量满足要求:
@GINrestrictsavariabletobeinganintegervalue,
@BINmakesavariablebinary(i.e.,0or1),
@FREEallowsavariabletoassumeanyrealvalue,positiveornegative
@BNDlimitsavariabletofallwithinafiniterange等.
程序名:
intlp(该程序主要是解决整数线性规划问题的,用上述命令赋予变量属性.)
intlp执行实例:
在模型命令窗口键入以下内容:
max=100*x+150*y;
x<=100;
y<=120;
x+2*y<=160;
@gin(x);@gin(y);!
若要只限制x,只要限制x即可.
按运行按钮在solutionreport窗口得到以下结果:
Globaloptimalsolutionfoundatiteration:
2
Objectivevalue:
14500.00
VariableValueReducedCost
X100.0000-100.0000
Y30.00000-150.0000
RowSlackorSurplusDualPrice
114500.001.000000
20.0000000.000000
390.000000.000000
40.0000000.000000
程序名:
bilp
bilp的执行实例:
在模型命令窗口键入以下内容:
max=-3*x1+2*x2+5*x3;
x1+2*x2-x3<=2;
x1+4*x2+x3<=4;
x1+x2<=3;
4*x2+x3<=6;
@bin(x1);@bin(x2);@bin(x3);
按运行按钮在solutionreport窗口得到以下结果:
Globaloptimalsolutionfoundatiteration:
0
Objectivevalue:
5.000000
VariableValueReducedCost
X10.0000003.000000
X20.000000-2.000000
X31.000000-5.000000
RowSlackorSurplusDualPrice
15.0000001.000000
23.0000000.000000
33.0000000.000000
43.0000000.000000
55.0000000.000000