why i get this error Size vector must be a row vector with real elements.

30 views (last 30 days)
Dear,
i have test this code to solve mixed integer problem but it give error her in this step
CoefMatZX = [repmat(-CoefZ,p,1),-U(1:p,:)*A; zeros(q,k+1),-V(1:q,:)*A];
it says error Size vector must be a row vector with real elements, that's because k is complex number and when i take
zeros(q,real(k)+1)
the loop doesn't stop, i don't know why.
%%Bender’s decompostion
% Application benders Decomposition algorithm to solve mixed- integer programming problem
% [OptX,OptY,OptValue]=BendersDecomposition(C,D,A,B,b)
% : To solve programming problems of the form :
% min C*x+D*y
% s.t. A*x+B*y>=b; x,0-1??variable,y>=0
% Iterative stop determination threshold value:LB/UB More than epsilon Can be flexibly adjusted according %to the complexity of the problem
function [OptX,OptY,OptValue]=BendersDecomposition(C,D,A,B,b)
C=[-1,-4];D=[-2,-3];A=[1 -3;-1 -3];B=[1 -2;-1 -1];b=[-2;-3];
epsilon = 0.99; %Stop iteration.
[nRowA,nColA] = size(A);
[nRowB,nColB] = size(B);
%step 1: Initialization
x0 = zeros(nColA,1);%The initial value
LB = -1e10;
UB = inf;
p = 0;
q = 0;
U = zeros(100,nRowA);
V = zeros(100,nRowA);
options = optimset('LargeScale', 'off', 'Simplex', 'on');
OptionsBint = optimset('MaxRLPIter',100000,'NodeSearchStrategy','bn',...
'MaxTime',50000);
while LB/UB<epsilon
%step 2: Subproblems
[UorV,fval,exitflag] = linprog((A*x0-b),B',D',[],[],zeros(nRowB,1),...
inf(nRowB,1),[],options)
if exitflag == 1 % Get extreme point
p = p+1;
U(p,:) = UorV'; % Extreme point
UB = C*x0 + U(p,:)*(b-A*x0);
elseif exitflag == -3 % Unbounded
q = q+1
V(q,:) = UorV'/1e16 % Pole direction
V(q,V(q,:)<0.0001) = 0;
else
msgbox('No feasible solution!')
return;
end
%step 3: Solving the main problem
if isinf(UB)
k = 17
else
k = ceil(log2(UB+1))-1 %k is complex number??According to 2^(k+1)-1 > UB Determines the minimum
%value of k
end
CoefZ =2.^(0:k) %z0,, The coefficient of vector zk
f = [CoefZ';zeros(nColA,1)] % Main objective function coefficient vector of
CoefMatZX = [repmat(-CoefZ,p,1),-U(1:p,:)*A; zeros(q,k+1),-V(1:q,:)*A];
bZX = [-(repmat(C*x0,p,1) + U(1:p,:)*b);-V(1:q,:)*b];
[OptZX,minZ,ExitflagBint] = bintprog(f,CoefMatZX,bZX,[],[],[],...
OptionsBint);
if ExitflagBint ==1
LB = minZ;
x0 = OptZX(k+2:end);
else
break;
end
LB,UB %#ok<NOPRT>
end
OptX = x0;
options = optimset('LargeScale', 'off', 'Simplex', 'on');
[OptY,OptValue] = linprog(D',-B,A*OptX-b,[],[],zeros(nColB,1),inf(nColB,1),...
[],options);
OptValue = C*OptX+D*OptY;
if true
% code
end
if true
% code
end
I need to run this code because there is no other one in matlab and it is useful to my work. thanks for any help.
regards,
Imola
  2 Comments
Alka Nair
Alka Nair on 17 Jun 2015
Hi, real(k) does not guarantee that it is an integer. Try explicitly making the dimension an integer value. Thank, Alka
Walter Roberson
Walter Roberson on 17 Jun 2015
In order for k to become complex, UB would have to be less than -1. Between -1 (inclusive) and 0 (inclusive) for UB, k would become negative and that would give problems. I do not understand the linear algebra well enough to see any reason why k < -1 should not be possible.

Sign in to comment.

Answers (0)

Categories

Find more on Filename Construction in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!