フィルターのクリア

keep solution from function into an array

2 ビュー (過去 30 日間)
Qonitat
Qonitat 2023 年 5 月 8 日
コメント済み: Qonitat 2023 年 5 月 9 日
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)

回答 (1 件)

LeoAiE
LeoAiE 2023 年 5 月 9 日
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, []);
  1 件のコメント
Qonitat
Qonitat 2023 年 5 月 9 日
thankyouu it helped a lott

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Least Squares についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by