linprog(Matlab)vs glpk(Octave) - 为什么我会得到不同的解决方案?

时间:2016-07-24 21:26:46

标签: matlab octave mathematical-optimization linear-programming

我需要为网络流量问题找到一个初始可行的解决方案,该问题由Nx = b,x> = 0给出。我习惯了以下OCTAVE代码来完成这项工作:

function [x,exitflag] = FIND_EXTREME_POINT(A,b)
% 
% Function FIND_EXTREME_POINT
%
% Call: [x,fval] = FIND_EXTREME_POINT(A,b)
%
% MATLAB code for finding a extreme point of the set X = { x | Ax = b,
% x >= 0} by solving the auxiliary problem
%
%                        min  1'*y
%                        s.t. A*x + y = b           
%                                   x >= 0
%                                   y >= 0
%
% either to receive a feasible basis solution or to return infeasibility 
%
% Inputs:
%   A - m*n matrix 
%   b = m*1 rhs
%   
% Output:
%          x - n*1 vector respresenting an extreme point 
%   exitflag - 0 if problem is infeasibile, 1 if the problem is feasible
%


% setup parameters for LP solver
[m,n] = size(A);

A_aux = [A eye(m)];
c_aux = [zeros(1,n) ones(1,m)]';
lb = [zeros(1,n+m)]';
ub = [];
ctype = repmat('S',1,m);
vartype = repmat('C',1,n+m);

% solve auxiliary LP
[xmin, fmin] = glpk(c_aux, A_aux, b, lb, ub, ctype, vartype, 1);
...% driving out artifical variables

glpk-solver给出的解决方案与我的手写笔记相符。

出于某种原因,我正在使用MATLAB,我遇到了以下代码的问题:

function [x,exitflag] = FIND_EXTREME_POINT(A,b)
% 
% Function FIND_EXTREME_POINT
%
% Call: [x,fval] = FIND_EXTREME_POINT(A,b)
%
% ....
%

% setup parameters for LP solver
[m,n] = size(A);
x = []; % output vector

A_aux = [A eye(m)];
c_aux = [zeros(1,n) ones(1,m)]';
lb = [zeros(1,n+m)]';
ub = [];

% solve auxiliary LP
[xmin,fval] = linprog(c_aux,[],[],A_aux,b,lb,ub);
... % driving out artifical variables

一方面,由linprog-solver计算的最优解xmin是可行的,但另一方面,函数值fval不是零但它应该是这样的......其中是在我的MATLAB代码中出错?

一个小例子:

N = [1 1 0 0 0 0 0;
  -1 0 0 -1 0 0 0;
  0 -1 1 0 0 -1 0; 
  0 0 -1 1 1 0 0; 
  0 0 0 0 0 1 1;
  0 0 0 0 -1 0 -1];
b = [5 -5 0 0 0 0]';  

OCTAVE给了我:

xmin =

    5
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0

fval =

  0

MATLAB给了我:

xmin =

    0.2184
    4.7816
    4.7816
    4.7816
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000

fval =

  5.8775e-016

0 个答案:

没有答案