surf can not be drawn/how triple objective function is written in same page with ga solver?

1 回表示 (過去 30 日間)
I define this triple objective function in separate sheet ,but how I can define this with ga solver in same sheet?
%%%%%multiobjective(triple) optimization problems
function Z= tripleobjectivefunction(x,y)
f1 = 0.5.*(x.^2+y.^2) +sin(x.^2+y.^2);
f2 =((3.*x-2.*y+4).^2./8)+((x-y+1).^2)/27+15;
f3 =1/(x.^2+y.^2+1)-1.1.*exp(-(x.^2+y.^2));
Z=[f1,f2,f3];
end
I want to have surf but this is not possible since the function Z is unrecognized.
clc;
clear all;
close all;
nvars = 2;
lb = [-3 -3];
ub = [3 3];
%initial population
%crossover and mutation
options=optimoptions("gamultiobj",'InitialPopulationRange',[1;100],"PopulationSize",50,"MaxGenerations",100,"MaxStallGenerations",100,"FunctionTolerance",1e-4,"MutationFcn",{@mutationadaptfeasible,2},"CrossoverFcn",{@crossoverintermediate, 2},"PlotFcn",{@gaplotpareto ,@gaplotselection ,@gaplotbestf});
[x,fval,exitflag,output,population,score] = gamultiobj(@(x) tripleobjectivefunction(x(1),x(2)),nvars,[],[],[],[],lb,ub,[],options);
optimal_solution = x;
objective_functions = fval;
figure(1)
hold on
box on
plot3(fval(:,1),fval(:,2),fval(:,3),'mo')
figure(2)
[X,Y]=meshgrid(x,fval);
surf(X,Y,length(Z),'FaceAlpha',0.5)
hold off

採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 27 日
Your question is not clear.
nvars = 2;
lb = [-3 -3];
ub = [3 3];
%initial population
%crossover and mutation
options = optimoptions("gamultiobj", ...
'InitialPopulationRange', [1;100], ...
"PopulationSize", 50, ...
"MaxGenerations", 500, ...
"MaxStallGenerations", 100, ...
"FunctionTolerance", 1e-4, ...
"MutationFcn", {@mutationadaptfeasible,2}, ...
"CrossoverFcn", {@crossoverintermediate, 2}, ...
"PlotFcn", {@gaplotpareto ,@gaplotselection ,@gaplotbestf});
if isunix()
options.PlotFcn = {};
end
[x,fval,exitflag,output,population,score] = gamultiobj(@(x) tripleobjectivefunction(x(1),x(2)),nvars,[],[],[],[],lb,ub,[],options);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
optimal_solution = x;
objective_functions = fval;
figure(1)
hold on
box on
plot3(fval(:,1),fval(:,2),fval(:,3),'mo')
hold off
figure(2)
[X, Y] = meshgrid(linspace(lb(1),ub(1)), linspace(lb(2), ub(2)));
Z3c = arrayfun(@(x,y) tripleobjectivefunction(x,y), X, Y, 'uniform', 0);
Z3d = cell2mat(cellfun(@(z3) reshape(z3, 1, 1, []), Z3c, 'uniform', 0));
s1 = surf(X, Y, Z3d(:,:,1), 'FaceAlpha', 0.5, 'edgecolor', 'none', 'DisplayName', 'First Objective');
hold on
scatter3(x(:,1), x(:,2), fval(:,1), 'rx');
hold off
legend(s1);
figure(3)
s2 = surf(X, Y, Z3d(:,:,2), 'FaceAlpha', 0.5, 'edgecolor', 'none', 'DisplayName', 'Second Objective');
hold on
scatter3(x(:,1), x(:,2), fval(:,2), 'rx');
hold off
legend(s2);
figure(4)
s3 = surf(X, Y, Z3d(:,:,3), 'FaceAlpha', 0.5, 'edgecolor', 'none', 'DisplayName', 'Third Objective');
hold on
scatter3(x(:,1), x(:,2), fval(:,3), 'rx');
hold off
legend(s3)
%%%%%multiobjective(triple) optimization problems
function Z= tripleobjectivefunction(x,y)
f1 = 0.5.*(x.^2+y.^2) +sin(x.^2+y.^2);
f2 =((3.*x-2.*y+4).^2./8)+((x-y+1).^2)/27+15;
f3 =1/(x.^2+y.^2+1)-1.1.*exp(-(x.^2+y.^2));
Z=[f1,f2,f3];
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by