Multi objective optimization for genetic algorithm showing out of bound solutions.

4 views (last 30 days)
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);
Multi-objective optimization: 2 Variables Options: CreationFcn: @gacreationuniform CrossoverFcn: @crossoverintermediate SelectionFcn: @selectiontournament MutationFcn: @mutationadaptfeasible Average Average Generation Func-count Pareto distance Pareto spread 1 50 1 1 2 100 0.0206928 0.411061 3 150 0.0199406 0.221978 4 200 0.00509167 0.0739517 5 250 0.0103144 0.312047 6 300 0.00535776 0.0785609 7 350 0.0101285 0.145853 8 400 0.010704 0.339981 9 450 0.00562346 0.128856 10 500 0.00644826 0.0969272 11 550 0.00824844 0.123374 12 600 0.00376789 0.0649277 13 650 0.0102013 0.13323 14 700 0.00809621 0.126988 15 750 0.0141773 0.201989 16 800 0.00746776 0.0974903 17 850 0.00525844 0.0701876 18 900 0.00572953 0.120595 19 950 0.0150192 0.193395 20 1000 0.0100848 0.126341 21 1050 0.00803535 0.215489 22 1100 0.0136081 0.200525 23 1150 0.00541403 0.0886357 24 1200 0.0040178 0.0620155 25 1250 0.00699872 0.102564 26 1300 0.0052385 0.0816008 27 1350 0.0109806 0.153293 28 1400 0.00582916 0.153478 29 1450 0.00876156 0.122766 30 1500 0.0124733 0.19677 Average Average Generation Func-count Pareto distance Pareto spread 31 1550 0.00679181 0.108716 32 1600 0.00837598 0.124589 33 1650 0.00662755 0.0902761 34 1700 0.0059547 0.134663 35 1750 0.00795628 0.120039 36 1800 0.0081142 0.135508 37 1850 0.00714794 0.134259 38 1900 0.0118365 0.164218 39 1950 0.00872715 0.1291 40 2000 0.0147769 0.192475 41 2050 0.00827088 0.129132 42 2100 0.00694102 0.11361 43 2150 0.00668206 0.105147 44 2200 0.0114985 0.140688 45 2250 0.00522078 0.0803578 46 2300 0.00697735 0.0999024 47 2350 0.0113815 0.153091 48 2400 0.0115905 0.156521 49 2450 0.00806875 0.116909 50 2500 0.00796998 0.11933 51 2550 0.00905485 0.133076 52 2600 0.00549726 0.0878519 53 2650 0.00664611 0.115028 54 2700 0.00828181 0.148065 55 2750 0.00677163 0.11915 56 2800 0.0098354 0.12161 57 2850 0.0120453 0.162291 58 2900 0.00665377 0.106378 59 2950 0.00637543 0.0988354 60 3000 0.0104169 0.13678 Average Average Generation Func-count Pareto distance Pareto spread 61 3050 0.00627528 0.0792071 62 3100 0.0068369 0.0978531 63 3150 0.00464378 0.0684661 64 3200 0.00591546 0.0897549 65 3250 0.00738431 0.110535 66 3300 0.00868434 0.192815 67 3350 0.00518109 0.0645982 68 3400 0.00560747 0.0883839 69 3450 0.00824552 0.202331 70 3500 0.00819077 0.109783 71 3550 0.00531933 0.0782256 72 3600 0.00702356 0.106576 73 3650 0.0059714 0.122619 74 3700 0.00886941 0.114288 75 3750 0.00728946 0.101009 76 3800 0.00425773 0.0627526 77 3850 0.00736038 0.114394 78 3900 0.00474414 0.0815989 79 3950 0.00400237 0.067633 80 4000 0.00997999 0.153975 81 4050 0.00455801 0.0775172 82 4100 0.0063894 0.0979791 83 4150 0.0081187 0.129505 84 4200 0.009662 0.139239 85 4250 0.00575785 0.0768275 86 4300 0.00579521 0.0873514 87 4350 0.00843108 0.13242 88 4400 0.00781309 0.122024 89 4450 0.00748439 0.117754 90 4500 0.00537968 0.076847 Average Average Generation Func-count Pareto distance Pareto spread 91 4550 0.0121643 0.146514 92 4600 0.00746221 0.0992378 93 4650 0.0068336 0.0979483 94 4700 0.0041051 0.0666727 95 4750 0.00604042 0.101174 96 4800 0.0105444 0.157265 97 4850 0.00633384 0.100006 98 4900 0.00743112 0.126459 99 4950 0.0111458 0.160848 100 5000 0.00558786 0.0895414 101 5050 0.00938994 0.131796 102 5100 0.00876371 0.131211 103 5150 0.00596723 0.0893314 104 5200 0.00374933 0.0602251 105 5250 0.00651905 0.108185 106 5300 0.00611937 0.104669 107 5350 0.0104159 0.14715 108 5400 0.00645118 0.0997381 109 5450 0.00710006 0.230089 110 5500 0.00558316 0.0826734 111 5550 0.0068663 0.106392 112 5600 0.00650016 0.112754 113 5650 0.00763674 0.104838 114 5700 0.00527261 0.10487 115 5750 0.00408311 0.0804505 gamultiobj stopped because the average change in the spread of Pareto solutions is less than options.FunctionTolerance.
% 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');
Optimal Solution:
fprintf('x1 = %.2f\nx2 = %.2f\n', x(1), x(2));
x1 = 159.98 x2 = 159.96
fprintf('Objective 1 Value: %.4f\n', -fval(1));
Objective 1 Value: 13.0075
fprintf('Objective 2 Value: %.4f\n', -fval(2));
Objective 2 Value: 11.0173

Answers (1)

Torsten
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)
ans = 3
x(2)
ans = 5
  7 Comments
Ahmed
Ahmed on 9 Mar 2024
By the way. If there are multiple solutions, then what are the final printed values (x1,x2, obj1, obj2) ?
Torsten
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!