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?
댓글 수: 0
채택된 답변
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)
댓글 수: 0
추가 답변 (2개)
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);
disp(sol.x1)
disp(sol.x2)
disp(fval)
댓글 수: 2
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);
[x1,I] = sort(sol.x1);
x2 = sol.x2;
x2 = x2(I);
plot(x1,x2)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Problem-Based Optimization and Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!