Solve a multiobjective optimization problem by problem-based approach in Matlab2021a
古いコメントを表示
I am trying this:
% teste_multiobjective file
x1 = optimvar('x1','LowerBound',0);
x2 = optimvar('x2','LowerBound',0);
s1 = 5*x1 + 2.5*x2 >= 5;
s2 = x1 + x2 <= 5;
s3 = 2*x1 + 2*x2 >= 3;
% s4 = 20*x1 + 10 * x2 == 20;
% s5 = 60*x1+90*x2 == 90;
prob = optimproblem('ObjectiveSense','minimize');
prob.Objective.obj1 = 20*x1 + 10*x2;
prob.Objective.obj2 = 60*x1 + 90*x2;
prob.Constraints.s1 = s1;
prob.Constraints.s2 = s2;
prob.Constraints.s3 = s3;
% prob.Constraints.s4 = s4;
% prob.Constraints.s5 = s5;
options = optimoptions('gamultiobj',HybridFcn="fgoalattain");
[sol,fval,exitflag,output] = solve(prob,Options=options);
disp(sol.x1)
disp(sol.x2)
disp(fval)
And matlab 2021a show me this:
Error using test_multiobjective
(line 16)
Objective must be a scalar
OptimizationExpression or a
struct containing a scalar
OptimizationExpression.
Does anyone help me, please?
採用された回答
その他の回答 (2 件)
It is working ok:
% teste_multiobjective file
x1 = optimvar('x1','LowerBound',0);
x2 = optimvar('x2','LowerBound',0);
s1 = 5*x1 + 2.5*x2 >= 5;
s2 = x1 + x2 <= 5;
s3 = 2*x1 + 2*x2 >= 3;
% s4 = 20*x1 + 10 * x2 == 20;
% s5 = 60*x1+90*x2 == 90;
prob = optimproblem('ObjectiveSense','minimize');
prob.Objective.obj1 = 20*x1 + 10*x2;
prob.Objective.obj2 = 60*x1 + 90*x2;
prob.Constraints.s1 = s1;
prob.Constraints.s2 = s2;
prob.Constraints.s3 = s3;
% prob.Constraints.s4 = s4;
% prob.Constraints.s5 = s5;
options = optimoptions('gamultiobj',HybridFcn="fgoalattain");
[sol,fval,exitflag,output] = solve(prob,Options=options);
disp(sol.x1)
disp(sol.x2)
disp(fval)
2 件のコメント
Ulisses Anastácio de Oliveira
2023 年 1 月 15 日
A = [-5 -2.5 ;1 1 ;-2 -2 ];
b = [-5;5;-3];
lb = [0; 0];
fitnessfcn = @(x)[20*x(1) + 10*x(2),60*x(1) + 90*x(2)];
x = gamultiobj(fitnessfcn,2,A,b,[],[],lb,[]);
[x1,I] = sort(x(:,1));
x2 = x(I,2);
plot(x1,x2)
% teste_multiobjective file
x1 = optimvar('x1','LowerBound',0);
x2 = optimvar('x2','LowerBound',0);
s1 = 5*x1 + 2.5*x2 >= 5;
s2 = x1 + x2 <= 5;
s3 = 2*x1 + 2*x2 >= 3;
% s4 = 20*x1 + 10 * x2 == 20;
% s5 = 60*x1+90*x2 == 90;
prob = optimproblem('ObjectiveSense','minimize');
prob.Objective.obj1 = 20*x1 + 10*x2;
prob.Objective.obj2 = 60*x1 + 90*x2;
prob.Constraints.s1 = s1;
prob.Constraints.s2 = s2;
prob.Constraints.s3 = s3;
% prob.Constraints.s4 = s4;
% prob.Constraints.s5 = s5;
options = optimoptions('gamultiobj',HybridFcn="fgoalattain");
[sol,fval,exitflag,output] = solve(prob,Options=options);
[x1,I] = sort(sol.x1);
x2 = sol.x2;
x2 = x2(I);
plot(x1,x2)
カテゴリ
ヘルプ センター および File Exchange で Multiobjective Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

