how can I solve an error of a different number of elements in GA multiobjective optimization?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all,
here is my code.
fitness =@levulinicAcid;
nvars = 2;
[x,fval] = gamultiobj(fitness, nvars, [],[],[],[],[0.2 10],[0.3 100]);
%%Check the results
x(1) = 10:10:100;
x(2) = 0.2:0.01:0.3;
f1 = -(-4.398907104 + 69.627287709*x(1) - 73.88575606*x(2));
f2 = 5.5828360656 + 0.0697243039*x(1) - 0.052863409*x(2); %FEDI
f3 = 119.81506557 + 1291.2552396*x(1) - 249.4926284*x(2); %GWP
figure; hold on
plot(x(1),x(2),f1);
plot(x(1),x(2),f2);
plot(x(1),x(2),f3);
grid;
xlabel('x');
ylabel('f');
2 commentaires
Réponses (1)
Stephan
le 9 Jan 2019
Hi,
try:
% Optimize with gamultiobj
fitness =@levulinicAcid;
nvars = 2;
[x,fval] = gamultiobj(fitness, nvars, [],[],[],[],[0.2 10],[0.3 100]);
% Plot results
subplot(3,1,1)
scatter3(x(:,1),x(:,2),fval(:,1),'or')
xlabel('x(1)')
ylabel('x(2)')
title('y1')
subplot(3,1,2)
scatter3(x(:,1),x(:,2),fval(:,2),'og')
xlabel('x(1)')
ylabel('x(2)')
title('y2')
subplot(3,1,3)
scatter3(x(:,1),x(:,2),fval(:,3),'ob')
xlabel('x(1)')
ylabel('x(2)')
title('y3')
% Objective function
function y = levulinicAcid(x)
y(1) = -(-4.398907104 + 69.627287709*x(1) - 73.88575606*x(2)); %NPV
y(2) = 5.5828360656 + 0.0697243039*x(1) - 0.052863409*x(2); %FEDI
y(3) = 119.81506557 + 1291.2552396*x(1) - 249.4926284*x(2); %GWP
end
This runs for me on R2018b and gives a result:
![result_gamultiobj.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/200436/image.png)
Best regards
Stephan
5 commentaires
Stephan
le 10 Jan 2019
"I would like to know how many generation can be formed?"
I do not know that there is a limit other than the time and resources you have available. The default is 100 * nvars. But look at your iterations - the algorithm converges after about 100...120 generations for your problem. So why do you want to change that?
"what result am I supposed to show from Genetic Algorithm? pareto front only?"
I can not tell you which plot is the most useful for you. For the given problem the pareto front is a straight line in the 3D-space of your objectives. Does it help you to interpret the results? Do you have more insight to the problem by looking how the y(i) depends from x(1) and x(2)? I can not say - it is just the question of what helps you most to interprete your results and work with them.
A possible way to get an idea of what could be the most helpful plot is to try it out with some different plots and with a quiet big population:
% Optimize with gamultiobj
options = optimoptions('gamultiobj','Display','iter',...
'MaxGeneration',200,...
'PopulationSize',2500,...
'PlotFcn',@gaplotpareto);
fitness =@levulinicAcid;
nvars = 2;
[x,fval] = gamultiobj(fitness, nvars, [],[],[],[],[0.2 10],[0.3 100],options);
% Plot results
figure(2)
subplot(2,2,1)
scatter3(fval(:,1),fval(:,2),fval(:,3),'or')
xlabel('y(1)')
ylabel('y(2)')
zlabel('y(3)')
title('Pareto Front')
subplot(2,2,2)
scatter3(x(:,1),x(:,2),fval(:,1),'or')
xlabel('x(1)')
ylabel('x(2)')
title('y1')
subplot(2,2,3)
scatter3(x(:,1),x(:,2),fval(:,2),'og')
xlabel('x(1)')
ylabel('x(2)')
title('y2')
subplot(2,2,4)
scatter3(x(:,1),x(:,2),fval(:,3),'ob')
xlabel('x(1)')
ylabel('x(2)')
title('y3')
% Objective function
function y = levulinicAcid(x)
y(1) = -(-4.398907104 + 69.627287709*x(1) - 73.88575606*x(2)); %NPV
y(2) = 5.5828360656 + 0.0697243039*x(1) - 0.052863409*x(2); %FEDI
y(3) = 119.81506557 + 1291.2552396*x(1) - 249.4926284*x(2); %GWP
end
Using this code you get this result:
![result_multiobj.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/200514/image.png)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!