l01p_e.m

来自「清华大学运筹学课件」· M 代码 · 共 36 行

M
36
字号
% the programm is with the integer 0-1 programming use enumber method

function [x,f]=L01p_e(c,A,b,N)

% the function is use the enumber function
% 0-1 linear programming problem
% min f=c'*x,s.t.A*x<=b,x=0 or 1
% N is the number of equational constraints in the front of the constraints
% x is the optimal solution and the f is the optimal value

if nargin<4
   N=0;
end

c=c(:);
b=b(:);
[m,n]=size(A);
x=[];
f=abs(c')*ones(n,1);
i=1;

while i<=2^n
    B=transdetobi(i-1,n)';
    t=A*B-b;
    t11=find(t(1:N,:)~=0);
    t12=find(t(N+1:m,:)>0);
    t1=[t11;t12];
    if isempty(t1)
       f=min([f,c'*B]);
       if c'*B==f 
          x=B;
       end
    end
  i=i+1;
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?