keep solution from function into an array
1 view (last 30 days)
Show older comments
i want to save solution from a function into an array, there will be x & fval loop input, and i want to save all the incumbent from the previous input to find the maximums ones, can someone help me? sorry for my english
function [x,fval] = BnB(f, A, b, Aeq, beq, lb, ub)
[x,fval] = linprog(f,A,b,Aeq,beq,lb,ub);
[incumbent] = updateincumbent(x,fval)
for i=1:length(x)
if --- && --- && fval>=incumbent
K = ;
K(i)=;
Aeq1 = [--];
beq1 = [--];
Aeq2 = [--];
beq2 = [--];
[x1,fval1] = BnB(f, A, b, Aeq1, beq1, lb, ub);
[x2,fval2] = BnB(f, A, b, Aeq2, beq2, lb, ub);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%incumbent function file
function [incumbent] = updateincumbent(x, fval)
if mod(x,1)==0 & isempty(fval)==0
incumbent=[fval];
else
incumbent=[0];
%here i want to save the incumbent into an array with the previous
%incumbent then saerch the maximum ones
incumbent=max(incumbent)
0 Comments
Answers (1)
LeoAiE
on 9 May 2023
function [x, fval, incumbent] = BnB(f, A, b, Aeq, beq, lb, ub, incumbent)
[x, fval] = linprog(f, A, b, Aeq, beq, lb, ub);
[incumbent] = updateincumbent(x, fval, incumbent);
for i = 1:length(x)
if --- && --- && fval >= incumbent
K = ;
K(i) = ;
Aeq1 = [--];
beq1 = [--];
Aeq2 = [--];
beq2 = [--];
[x1, fval1, incumbent] = BnB(f, A, b, Aeq1, beq1, lb, ub, incumbent);
[x2, fval2, incumbent] = BnB(f, A, b, Aeq2, beq2, lb, ub, incumbent);
end
end
function [incumbent] = updateincumbent(x, fval, incumbent)
if mod(x, 1) == 0 && isempty(fval) == 0
incumbent = [incumbent, fval];
else
incumbent = [incumbent, 0];
end
incumbent = max(incumbent);
[x, fval, incumbent] = BnB(f, A, b, Aeq, beq, lb, ub, []);
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!