Solve a multiobjective optimization problem by problem-based approach in Matlab2021a

조회 수: 2 (최근 30일)
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?

채택된 답변

Matt J
Matt J 2023년 1월 16일
편집: Matt J 2023년 1월 16일
You can use prob2matrices from this FEX download,
% teste_multiobjective file
x1 = optimvar('x1','LowerBound',0);
x2 = optimvar('x2','LowerBound',0);
con.s1 = 5*x1 + 2.5*x2 >= 5;
con.s2 = x1 + x2 <= 5;
con.s3 = 2*x1 + 2*x2 >= 3;
options = optimoptions('gamultiobj',HybridFcn="fgoalattain");
p=prob2matrices({x1,x2},'Constraints', con);
fitnessfcn = @(x)[20*x(1) + 10*x(2),60*x(1) + 90*x(2)];
x = gamultiobj(fitnessfcn,2,p.A,p.b,p.Aeq,p.beq,p.lb,p.ub,[],p.intcon,options)

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 1월 15일
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);
Solving problem using gamultiobj. Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
disp(sol.x1)
0.5000 0.9286 0.8427 0.6718 0.6207 0.5535 0.7163 1.2131 0.8641 1.4535 1.4535 1.1060 0.7336 0.7946 1.1636 1.0476 0.9609 1.2796
disp(sol.x2)
0.9995 0.5717 0.6682 0.8312 0.8812 0.9501 0.7895 0.2899 0.6376 0.0476 0.0476 0.3940 0.7664 0.7054 0.3364 0.4524 0.5391 0.2204
disp(fval)
19.9961 24.2890 23.5362 21.7473 21.2265 20.5704 22.2210 27.1606 23.6579 29.5454 29.5454 26.0605 22.3359 22.9464 26.6358 25.4756 24.6093 27.7957 119.9594 107.1712 110.6984 115.1156 116.5505 118.7150 114.0360 98.8739 109.2299 91.4904 91.4904 101.8185 112.9924 111.1607 100.0927 103.5733 106.1721 96.6128
  댓글 수: 2
Ulisses Anastácio de Oliveira
Ulisses Anastácio de Oliveira 2023년 1월 15일
Thanks!! You ran this in matlab 2022b, right? I am using matlab 2021a. Do you know if there is other way to write the code to fit it in matlab 2021a?
Torsten
Torsten 2023년 1월 15일
편집: Torsten 2023년 1월 16일
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,[]);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
[x1,I] = sort(x(:,1));
x2 = x(I,2);
plot(x1,x2)

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2023년 1월 15일
% 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);
Solving problem using gamultiobj. Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
[x1,I] = sort(sol.x1);
x2 = sol.x2;
x2 = x2(I);
plot(x1,x2)

카테고리

Help CenterFile Exchange에서 Get Started with Problem-Based Optimization and Equations에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by