Solve a multiobjective optimization problem by problem-based approach in Matlab2021a
12 次查看(过去 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)
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 中查找有关 Multiobjective Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

