数学建模四0-1规划

这是问题:

 

 解:

 

单位换算:1‘06’8=66.8秒 

重点:记Cij为队员i泳姿为j的成绩;i=1,2,3,4,5;j=1,2,3,4;Xij=1即队员i参加泳姿j的比赛;

①.lingo代码

 

Min=66.8*x11+75.6*x12+87*x13+58.6*x14+57.2*x21+66*x22+66.4*x23+53*x24+78*x31+67.8*x32+84.6*x33+59.4*x34+70*x41+74.2*x42+
69.6*x43+57.2*x44+67.4*x51+71*x52+83.8*x53+62.4*x54;
%指不等式约束条件A*x<=b指每个人最多参加一种姿势游泳 [st_1] x11+x12+x13+x14<1; [st_2] x21+x22+x23+x24<1; [st_3] x31+x32+x33+x34<1; [st_4] x41+x42+x43+x44<1; [st_5] x51+x52+x53+x54<1;

%指等式约束条件Aeq*x=beq指每种姿势游泳有且仅有一个人参加 [st_6] x11+x21+x31+x41+x51=1; [st_7] x12+x22+x32+x42+x52=1; [st_8] x13+x23+x33+x43+x53=1; [st_9] x14+x24+x34+x44+x54=1;

  

%注意一条条罗列

结果如:

 

 

 

 注意看结果,最快成绩为253.2秒,x14=x21=x32=x43=1;其它=0;此时甲-自由泳;乙-蝶泳;丙-仰泳;丁-蛙泳

 

②matlab代码【超级详细!!看一遍就会!!】

>>  f=[66.8 75.6 87 58.6 57.2 66 66.4 53 78 67.8 84.6 59.4 70 74.2 69.6 57.2 67.4 71 83.8 64.2];
>> A=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1];
>>  b=[1;1;1;1;1];
%指不等式约束条件A*x<=b指每个人最多参加一种姿势游泳

>>  Aeq=[1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0;0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0;0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 ;...
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 ];
>>  beq=[1;1;1;1];
%指等式约束条件Aeq*x=beq指每种姿势游泳有且仅有一个人参加

>> intcon=1:1:20;%指20个整数变量的位置
>> lb=zeros(20,1);%指每个整数变量的下界为0;这里也可以写zeros(20)或者zeros(1,20)只是生成向量的方式的问题,只要最后结果是个向量都可以
>> ub=ones(20,1);%指每个整数变量的上界为1;这里也可以写zeros(20)或者zeros(1,20)
>> [x,fval]=intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)%用函数intlinprog求解整数线性规划问题,用bintprog也可以

运行结果为:

LP:                Optimal objective value is 253.200000.                                           


Optimal solution found.

Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value,
options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05
(the default value).


x =

     0
     0
     0
     1
     1
     0
     0
     0
     0
     1
     0
     0
     0
     0
     1
     0
     0
     0
     0
     0


fval =

  253.2000

总结:lingo代码相对简单。matlab代码很容易敲错,一定要细心;再就是剖析题目的能力要加强,学会从实际问题中抽出数学模型,进而求解。本题是一个0-1规划问题,并可以使用二维向量来理解;即Xij=1就是第i个人第j种泳姿参加比赛;Xij=0就是第i个人第j种泳姿不参加比赛!在写matlab向量一定要细心,还有时间换算将60分制化为百分制!

posted @ 2020-04-20 17:46  橘子大侠  阅读(1688)  评论(0编辑  收藏  举报