数学建模算法与应用——整数规划
2_3
某公司新购置了某种设备6台,欲分配给下属的4个企业,已知各企业获得这种设备后年创立润如图2所示,单位为千万元。问应该如何分配这些设备能使年创利润最大,最大利润是多少。
%非常规指派问题 clc,clear,close all prob = optimproblem(ObjectiveSense,max); x = optimvar(x,6,4,TYPE,integer,LowerBound,0,UpperBound,1); c = [4 2 3 4;6 4 5 5;7 6 7 6;7 8 8 6;7 9 8 6;7 10 8 6]; M=c.*x; prob.Objective = sum(sum(M)); prob.Constraints.con2 =sum(x)>=1;%每列求和,结果大于等于1 prob.Constraints.con1 =sum(x,2)==1;%每行求和,结果等于1 [sol,flav,flag] = solve(prob); xx = sol.x sum(sum(c.*xx))
本题最后可有多种情况,原因是设备3在甲企业和丙企业收益相同,设备4在乙丙企业收益相同。
2_6
clc,clear,close all prob = optimproblem; x = optimvar(x,5,TYPE,integer,LowerBound,0); prob.Objective = 20*x(1)+90*x(2)+80*x(3)+70*x(4)+30*x(5); prob.Constraints.con1 = x(1)+x(2)+x(5)>=30; prob.Constraints.con2 = x(3)+x(4)>=30; prob.Constraints.con3 = 3*x(1)+2*x(3)<=120; prob.Constraints.con4 = 3*x(2)+2*x(4)+x(5)<=48; [sol,flav,flag] = solve(prob); sol.x
2_8
指派矩阵
clc,clear,close all prob = optimproblem; x = optimvar(x,6,6,TYPE,integer,LowerBound,0,UpperBound,1); c = [6 7 5 8 9 10 6 3 7 9 3 8 8 11 12 6 7 9 9 7 5 4 7 6 5 8 9 6 10 7 9 8 7 6 5 9]; M=c.*x; prob.Objective = sum(M(:)); prob.Constraints.con1 = sum(x) == 1; prob.Constraints.con2 = sum(x,2) ==1; [sol,flav,flag] = solve(prob); sol.x
