Matlab线性规划优化算法(1)

在Matlab中解形如下式的线性规划问题:
在这里插入图片描述
其中包括优化对象 f’ * x, 不等式约束,等式约束,以及约束变量的上下界。
在Matlab中提供了linprog函数进行线性优化的求解:
eg:
[x,fval,exitflag,output,lambda] = linprog(f,A,b,Aeq,beq,lb,ub,options)
函数的输入f, 即为优化对象f, A,b, Aeq, beq, lb,ub 均为上式中的具体表达。最后的options是对优化过程进行参数设置,主要的包括:

options = optimoptions(‘linprog’,‘Algorithm’,‘interior-point’,‘Display’,‘iter’,‘MaxIterations’,10)

选择优化方法: 线性优化
选择优化算法: 内点法(线性优化中还提供其他算法)
显示: 显示循环次数
限制循环次数

还有其他参数可以设置:具体的搜索Matlab reference中的 Optimization Options Reference获得。
举个例子:
我们解下面的线性规划问题:

f = [-2;-1;1];

A = [1 4 -1; 2 -2 1];

b = [4;12];

Aeq = [1 1 2];
beq = 6;

lb = zeros(3,1);

给出对应优化参数设置并求解:

options = optimoptions('linprog','Algorithm','dual-simplex','Display','iter','MaxIterations',10)

[x,fval,exitflag,output,lambda]  = linprog(f,A,b,Aeq,beq,lb,ub,options)

我们可以获得如下的结果:

options = 

  linprog options:

   Options used by current Algorithm ('dual-simplex'):
   (Other available algorithms: 'interior-point', 'interior-point-legacy')

   Set properties:
              Algorithm: 'dual-simplex'
                Display: 'iter'
          MaxIterations: 10

   Default properties:
    ConstraintTolerance: 1.0000e-04
                MaxTime: Inf
    OptimalityTolerance: 1.0000e-07


LP preprocessing removed 0 inequalities, 0 equalities,
0 variables, and added 0 non-zero elements.

 Iter      Time            Fval  Primal Infeas    Dual Infeas  
    0     0.001    0.000000e+00   6.999174e+00   1.113300e+00  
    2     0.002   -1.080000e+01   1.750843e+00   0.000000e+00  
    4     0.002   -8.666667e+00   0.000000e+00   0.000000e+00  

Optimal solution found.


x =

    4.6667
         0
    0.6667


fval =

   -8.6667


exitflag =

     1


output = 

  struct with fields:

         iterations: 4
    constrviolation: 8.8818e-16
            message: 'Optimal solution found.'
          algorithm: 'dual-simplex'
      firstorderopt: 7.4015e-16


lambda = 

  struct with fields:

      lower: [3×1 double]
      upper: [3×1 double]
      eqlin: 0.3333
    ineqlin: [2×1 double]

其中包括了对参数的显示,每一步循环的数据,以及最终的最优点的值和函数值。

发布了56 篇原创文章 · 获赞 11 · 访问量 8728

猜你喜欢

转载自blog.csdn.net/gophae/article/details/104074737