I am trying to implement a recursive function for branch and bound algorithm. each time of calling my algorithm recursively I am changing my lb and ub value in the recursive call. it is showing the error UB must be a real valued nx by 1 column vertor error in MATLAB
. My code is attached below:
function [cost] = BB(c, A, b, lb, ub, ctype, vartype, s, xmin, fmin, fid, NumberofNodes,min_cost, val);
[xmin_last, fmin_last, status] = glpk (c, A, b, lb, ub, ctype, vartype, s) %GLPK function
frac_value_1= find(xmin_last > 0.999);
xmin(frac_value_1)=1;
frac_value_2= find(xmin_last < 0.0001);
xmin(frac_value_2)=0;
frac_value=intersect(find (xmin_last > 0) , find( xmin_last < 1)) ; %positions of fractional variables
size(frac_value,1);
if (isempty(frac_value))
fprintf(fid,'no fractional value');
fprintf(fid,'\n\n');
cost = fmin_last
return
else
round_value=frac_value(1)
one_value_cost=find ( xmin_last== 1 ) %variables with value 1
zero_value_cost=find ( xmin_last==0) %variables with value 0
ub(zero_value_cost)=0 %changing ub for 0 values
%val=0
[cost_0] = BB(c, A, b, lb, ub(round_value)=0, ctype, vartype, s, xmin_last(round_value)=0, fmin_last, fid, NumberofNodes,min_cost,val=0);
%val=1
[cost_1] = BB(c, A, b, lb(round_value)=1, ub, ctype, vartype, s, xmin_last(round_value)=1, fmin_last, fid, NumberofNodes,min_cost, val=1);
end
min_cost = min(cost_0, cost_1)
endfunction;
It is showing error for ub(round_value)=0
and lb(round_value)=1
. Any help will be appreciated
If the find function finds more than one value it will return a vector of all the entries equal to zero or one. You should try selecting the first element of zero_value_cost.
If the find function doesn't find a one or a zero it will return an empty vector. Are you sure these values are in the vectors you are searching?