优先考虑线性规划中的一些变量

时间:2014-01-10 18:35:47

标签: matlab optimization mathematical-optimization linear-programming cplex

我必须使用二进制整数线性编程来优化目标,我的目标函数是:

Maximize f= (c1 * x1) + (c2 * x2) +(c3 * x3) + ... + (c10000 * x10000)
Subject to some constraints

为了有效地解决问题,我想使用一些启发式,根据一种启发式方法,一些变量(xi)有更多机会成为答案的一部分(Xi=1) ,所以我的目标是给予这些变量优先级(偏好)以比平常方式更快地解决问题,我知道解决方案可能不是最优的,但我们主要关心的是时间。

所以我的问题是:

  • 如何在LP model
  • 中确定此变量的优先级
  • 我们可以将此变量的系数乘以constant (C>1),以便提高其优先级吗?或者通过将其系数乘以另一个constant (D<1)来减少其他变量的优先级?
  • 如果我们使用问题#2的方法,我们是否必须这样做只使用目标函数系数目标函数系数和约束系数都应该改变< / strong>与这些变量有关吗?

  • 应该注意的是,在问题#2的方法中,在求解LP模型之后,我们根据解决方案回滚系数中的任何变化(解决方案中有哪些变量)。

提前致谢

2 个答案:

答案 0 :(得分:1)

如果您知道xi将成为解决方案的一部分,则应将其1包含在您传递给bintprog的初始点x0中。已知可能不属于解决方案的xj的相同内容应包含在0中。如果初始点非常接近解决方案,这将减少找到它的时间。

x = bintprog(f,A,b,Aeq,beq,x0);

另一个选择是通过添加两个额外条件来放松BILP问题到LP问题

 x <= 1
-x <= 0

然后使用舍入解决方案将此问题作为BILP问题的初始点。

Here作者表示bintprog仅在小问题上表现良好。当我使用Octave代替Matlab时,我尝试了GNU Linear Programming Kit(glpk)。我试图从Matlab documentation解决BILP问题,这是一个脚本

close all; clear all;

f = [25,35,28,20,40,-10,-20,-40,-18,-36,-72,-11,-22,-44,-9,-18,-36,-10,-20]';
A = zeros(14,19);
A(1,1:19) = [25 35 28 20 40 5 10 20 7 14 28 6 12 24 4 8 16 8 16];
A(2,1) = 1; A(2,6) = -1; A(2,7) = -1; A(2,8) = -1; 
A(3,2) = 1; A(3,9) = -1; A(3,10) = -1; A(3,11) = -1;
A(4,3) = 1; A(4,12) = -1; A(4,13) = -1; A(4,14) = -1;
A(5,4) = 1; A(5,15) = -1; A(5,16) = -1; A(5,17) = -1;
A(6,5) = 1; A(6,18) = -1; A(6,19) = -1;
A(7,1) = -5; A(7,6) = 1; A(7,7) = 2; A(7,8) = 4;
A(8,2) = -4; A(8,9) = 1; A(8,10) = 2; A(8,11) = 4;
A(9,3) = -5; A(9,12) = 1; A(9,13) = 2; A(9,14) = 4;
A(10,4) = -7; A(10,15) = 1; A(10,16) = 2; A(10,17) = 4;
A(11,5) = -3; A(11,18) = 1; A(11,19) = 2;
A(12,2) = 1; A(12,5) = 1;
A(13,1) = 1; A(13,2) = -1; A(13,3) = -1;
A(14,3) = -1; A(14,4) = -1; A(14,5) = -1;
b = [125 0 0 0 0 0 0 0 0 0 0 1 0 -2]';
lb = zeros(size(f));
ub = ones(size(f));
ctype = repmat("U" , size(b))'; # inequality constraint
sense = 1; # minimization
param.msglev = 0;

vartype = repmat("C" , size(f)); # continuous variables
tic
for i = 1:10000
[xopt, fmin, errnum, extra] = glpk (f, A, b, lb, ub, ctype, vartype, sense, param);
end
toc
fprintf('Solution %s with value %f\n', mat2str(xopt), fmin)

vartype = repmat("I" , size(f)); # integer variables
tic
for i = 1:10000
[xopt, fmin, errnum, extra] = glpk (f, A, b, lb, ub, ctype, vartype, sense, param);
end
toc
fprintf('Solution %s with value %f\n', mat2str(xopt), fmin)

这些是找到的解决方案:

Elapsed time is 7.9 seconds.
Solution [0;0.301587301587301;1;1;0;0;0;0;0;0.603174603174603;0;1;1;0.5;1;1;1;0;0] with value -81.158730
Elapsed time is 11.5 seconds.
Solution [0;0;1;1;0;0;0;0;0;0;0;1;0;1;1;1;1;0;0] with value -70.000000

由于问题仍然很小,我不得不执行10000次迭代以使性能差异可见。与BILP解决方案相比,LP解决方案更快,而且非常接近。

答案 1 :(得分:0)

根据CPLEX Performance Tuning for Mixed Integer ProgramsIssuing priority orders,我们可以设置优先顺序来增加或减少CPLEX中某些变量的优先级,此方法如下:< / p>

options = cplexoptimset('cplex');
options.mip.ordertype=fsl;
[x,fval,exitflag,output] = cplexbilp(f, Aineq, bineq, Aeq, beq,[],options);

fsl是问题变量的优先级数组。 由于CPLEX可以根据问题数据特征自动生成优先级顺序,因此我们可以将优先级决定保留为CPLEX,如下所示:

value    branching priority order  
=====    ========================

  0      no automatic priority order will be generated (default)
  1      decreasing cost coefficients among the variables 
  2      increasing bound range among the variables
  3      increasing cost per matrix coefficient count among the variables

使用优先级后,我的问题解决了,解决方案是有效的,并且比以前更快收敛到解决方案!