Multi objective optimization for genetic algorithm showing out of bound solutions.
4 views (last 30 days)
Show older comments
Hello! I am comparatively new to Matlab.
I am working on a project. I need to optimize two objective functions which have two variables (x1,x2) in total.
x1 should be within 130 to 160, and x2 should be within 18 to 22.There are no other constraints. But the optimized solution is showing results x2 value of 160. I wrote the code with the help of some youtube videos and ChatGPT. What is the reason behind the value of x2 being more than 22?.
Here is the code:
% Define the first objective function
fun1 = @(x) -(1.10684 + 0.005818*x(1) + 0.498853*x(2));
% Define the second objective function
fun2 = @(x) -(82.015320468227 + 0.38563758777369*x(1) - 9.6030354792151*x(2) - 0.0095666666666666*x(1)*x(2) - 0.00055977777777776*x(1)^2 + 0.2517625*x(2)^2);
% Combine the objectives into a single function for multi-objective optimization
multiObjFun = @(x) [fun1(x), fun2(x)];
% Set lower and upper bounds for each parameter
lb = [130, 18];
ub = [160, 22];
% Use the genetic algorithm for multi-objective optimization
options = optimoptions('gamultiobj', 'Display', 'iter');
[x, fval, exitflag, output, population, scores] = gamultiobj(multiObjFun, 2, [], [], [], [], lb, ub, options);
% Display the Pareto front (trade-off solutions)
figure;
plot(scores(:, 1), scores(:, 2), 'o');
xlabel('Objective 1');
ylabel('Objective 2');
title('Pareto Front');
% Display information about the optimal solution(s)
fprintf('Optimal Solution:\n');
fprintf('x1 = %.2f\nx2 = %.2f\n', x(1), x(2));
fprintf('Objective 1 Value: %.4f\n', -fval(1));
fprintf('Objective 2 Value: %.4f\n', -fval(2));
0 Comments
Answers (1)
Torsten
on 8 Mar 2024
Edited: Torsten
on 8 Mar 2024
If you plot x(:,2) against x(:,1), you will see that both respect the bounds you prescribed:
figure(2)
[x1,idx] = sort(x(:,1))
plot(x1,x(idx,2))
Printing x(1) and x(2) for your two-dimensional array x means to plot x(1,1) and x(2,1):
x = [3 4;5 6];
x(1)
x(2)
7 Comments
Torsten
on 9 Mar 2024
Edited: Torsten
on 9 Mar 2024
There is no "best" solution. Each of the solution pairs you get in the arrays x(:,1) and x(:,2) are pareto-optimal. Read about the concept of what a "Pareto Front" means.
Imagine you want to make profit and save nature at the same time and you have two objective functions - one for profit, the other for state of environment. There cannot be an optimum that optimizes both simultaneously because the two targets are in conflict with each other. But given an amount of profit, you can find a point that best saves nature for this profit. And given a level of safety for nature, you can maximize profit under this constraint.
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!