Hi Dhanesh,
gamultiobj function in MATLAB designed for solving multi-objective optimization problems using genetic algorithms. It is based on NSGA-II. You can refer to the following documentation page which describes the algorithm in detail:
While gamultiobj is intended for multi-objective problems, it can technically be used for single-objective optimization as well. However, this is not its intended use, and doing so might not be as efficient or straightforward as using ga, which is specifically designed for single-objective optimization problems.
In the context of a single objective, gamultiobj would still attempt to apply NSGA-II principles, such as non-dominated sorting and crowding distance, but these concepts are more meaningful when there is more than one objective to balance and trade-off. It may introduce unnecessary complexity and computational overhead when applied to single-objective problems because it is designed to handle the additional complexity of balancing multiple objectives.
Here's a small snippet you can run to compare those two:
objectiveFunction = @(x) x^2;
options = optimoptions('ga', 'Display', 'iter');
[x_min_ga, fval_ga] = ga(objectiveFunction, 1, [], [], [], [], [], [], [], options);
Single objective optimization:
1 Variables
Options:
CreationFcn: @gacreationuniform
CrossoverFcn: @crossoverscattered
SelectionFcn: @selectionstochunif
MutationFcn: @mutationgaussian
Best Mean Stall
Generation Func-count f(x) f(x) Generations
1 100 0.02595 72.96 0
2 147 0.02595 116.7 1
3 194 0.02595 205.8 2
4 241 0.02595 223.4 3
5 288 0.01755 172 0
6 335 0.01755 88.91 1
7 382 0.01755 78.13 2
8 429 0.01755 83.1 3
9 476 0.01755 269.9 4
10 523 0.01755 210.1 5
11 570 0.01755 157 6
12 617 0.01755 158.1 7
13 664 0.01755 208.5 8
14 711 0.01755 151 9
15 758 0.01755 127.8 10
16 805 0.01755 88.95 11
17 852 0.01755 60.1 12
18 899 0.01755 66.69 13
19 946 0.01755 102.6 14
20 993 0.01755 79.87 15
21 1040 0.01755 96.1 16
22 1087 0.01755 124.9 17
23 1134 0.006718 178.7 0
24 1181 0.006718 104.8 1
25 1228 0.006718 117.3 2
26 1275 0.006718 161.4 3
27 1322 0.006718 121.8 4
28 1369 0.006718 132 5
29 1416 0.006718 89.44 6
30 1463 0.006718 40.31 7
Best Mean Stall
Generation Func-count f(x) f(x) Generations
31 1510 0.006718 94.43 8
32 1557 0.006718 97.58 9
33 1604 0.006718 82.11 10
34 1651 0.006718 112.5 11
35 1698 0.006718 117.9 12
36 1745 0.006718 103.2 13
37 1792 0.006718 78.08 14
38 1839 0.006718 39.81 15
39 1886 0.006718 31.41 16
40 1933 0.006718 28.81 17
41 1980 0.006718 43.18 18
42 2027 0.006718 49.38 19
43 2074 0.006718 41.64 20
44 2121 1.065e-05 79.02 0
45 2168 1.065e-05 80.68 1
46 2215 1.065e-05 73.73 2
47 2262 1.065e-05 54.3 3
48 2309 1.065e-05 89.05 4
49 2356 1.065e-05 48.17 5
50 2403 1.065e-05 23.23 6
51 2450 1.065e-05 17.99 7
52 2497 1.065e-05 23.4 8
53 2544 1.065e-05 50.62 9
54 2591 1.065e-05 19.32 10
55 2638 1.065e-05 23.7 11
56 2685 1.065e-05 15.5 12
57 2732 1.065e-05 24.41 13
58 2779 1.065e-05 25.29 14
59 2826 1.065e-05 50.39 15
60 2873 1.065e-05 14.48 16
Best Mean Stall
Generation Func-count f(x) f(x) Generations
61 2920 1.065e-05 26.72 17
62 2967 1.065e-05 17.84 18
63 3014 1.065e-05 17.64 19
64 3061 1.065e-05 25.4 20
65 3108 1.065e-05 11.52 21
66 3155 1.065e-05 11.08 22
67 3202 1.065e-05 9.892 23
68 3249 1.065e-05 13.94 24
69 3296 1.065e-05 9.873 25
70 3343 1.065e-05 7.289 26
71 3390 1.065e-05 11.5 27
72 3437 1.065e-05 5.441 28
73 3484 1.065e-05 4.708 29
74 3531 1.065e-05 3.984 30
75 3578 1.065e-05 3.166 31
76 3625 1.065e-05 4.912 32
77 3672 1.065e-05 6.814 33
78 3719 1.065e-05 2.401 34
79 3766 1.065e-05 3.773 35
80 3813 1.065e-05 7.385 36
81 3860 1.065e-05 8.928 37
82 3907 1.065e-05 7.369 38
83 3954 1.065e-05 10.71 39
84 4001 1.065e-05 7.032 40
85 4048 1.065e-05 5.481 41
86 4095 1.065e-05 4.072 42
87 4142 1.065e-05 3.252 43
88 4189 1.065e-05 3.971 44
89 4236 1.065e-05 2.208 45
90 4283 1.065e-05 1.376 46
Best Mean Stall
Generation Func-count f(x) f(x) Generations
91 4330 1.065e-05 1.61 47
92 4377 1.065e-05 1.641 48
93 4424 1.065e-05 2.602 49
94 4471 1.065e-05 0.9332 50
ga stopped because the average change in the fitness value is less than options.FunctionTolerance.
fprintf('Using ga, minimum found at x = %f, with value = %f\n', x_min_ga, fval_ga);
Using ga, minimum found at x = 0.003263, with value = 0.000011
objectiveFunctionMulti = @(x) [x^2];
options_multi = optimoptions('gamultiobj', 'Display', 'iter');
[x_min_multi, fval_multi] = gamultiobj(objectiveFunctionMulti, 1, [], [], [], [], [], [], options_multi);
Multi-objective optimization:
1 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 0.0321317
3 150 0 0
4 200 0 0
5 250 0 8.17904e-06
6 300 0 0.000259522
7 350 0 3.69276e-05
8 400 0 1.22248e-06
9 450 0 7.99074e-08
10 500 0 1.03809e-07
11 550 0 1.39688e-09
12 600 0 4.63282e-10
13 650 0 9.99213e-13
14 700 0 1.11751e-11
15 750 0 0
16 800 0 6.57523e-14
17 850 0 0
18 900 0 9.99953e-15
19 950 0 0
20 1000 0 0
21 1050 0 6.60005e-18
22 1100 0 4.93635e-18
23 1150 0 1.3223e-21
24 1200 0 3.44466e-22
25 1250 0 3.14748e-22
26 1300 0 4.2422e-23
27 1350 0 2.65388e-24
28 1400 0 1.63942e-24
29 1450 0 0
30 1500 0 0
Average Average
Generation Func-count Pareto distance Pareto spread
31 1550 0 1.76957e-27
32 1600 0 8.13294e-28
33 1650 0 0
34 1700 0 8.41608e-30
35 1750 0 0
36 1800 0 0
37 1850 0 4.22061e-32
38 1900 0 9.43028e-32
39 1950 0 1.98018e-33
40 2000 0 4.98924e-34
41 2050 0 0
42 2100 0 3.35167e-35
43 2150 0 0
44 2200 0 1.51582e-37
45 2250 0 3.20795e-38
46 2300 0 0
47 2350 0 1.41094e-38
48 2400 0 2.35215e-40
49 2450 0 2.03706e-40
50 2500 0 1.58766e-41
51 2550 0 1.1261e-42
52 2600 0 2.09347e-43
53 2650 0 0
54 2700 0 1.24148e-44
55 2750 0 0
56 2800 0 7.22048e-48
57 2850 0 5.85781e-48
58 2900 0 0
59 2950 0 1.29025e-49
60 3000 0 0
Average Average
Generation Func-count Pareto distance Pareto spread
61 3050 0 1.73138e-51
62 3100 0 7.10293e-52
63 3150 0 0
64 3200 0 9.62036e-54
65 3250 0 0
66 3300 0 0
67 3350 0 3.00963e-55
68 3400 0 5.49035e-57
69 3450 0 0
70 3500 0 5.4262e-60
71 3550 0 0
72 3600 0 0
73 3650 0 1.57124e-60
74 3700 0 0
75 3750 0 4.2247e-65
76 3800 0 0
77 3850 0 4.97387e-65
78 3900 0 5.07939e-67
79 3950 0 0
80 4000 0 3.98848e-69
81 4050 0 4.15712e-70
82 4100 0 0
83 4150 0 2.90571e-71
84 4200 0 1.81718e-71
85 4250 0 0
86 4300 0 3.97227e-75
87 4350 0 3.444e-75
88 4400 0 6.20629e-75
89 4450 0 5.50546e-76
90 4500 0 2.7077e-77
Average Average
Generation Func-count Pareto distance Pareto spread
91 4550 0 3.03244e-77
92 4600 0 0
93 4650 0 0
94 4700 0 0
95 4750 0 1.11228e-80
96 4800 0 0
97 4850 0 3.02763e-82
98 4900 0 5.85068e-84
99 4950 0 0
100 5000 0 1.76829e-84
101 5050 0 0
102 5100 0 6.31314e-87
gamultiobj stopped because the average change in the spread of Pareto solutions is less than options.FunctionTolerance.
fprintf('Using gamultiobj, one of the solutions found is at x = %f, with value = %f\n', x_min_multi(1,:), fval_multi(1,:));
Using gamultiobj, one of the solutions found is at x = 0.000000, with value = 0.000000
- Using ga, you will find a minimum at some x which is very close to the global minimum at (x = 0), demonstrating the effectiveness of ga in finding near-optimal solutions. The slight deviation from zero is typical for genetic algorithms, which are heuristic search methods that approximate the global optimum.
- Using gamultiobj, one of the solutions found is exactly at the global minimum, (x = 0.000000), with a function value of (0.000000). This perfect finding is partly due to the nature of gamultiobj and the simplicity of the problem. While gamultiobj is designed for multi-objective scenarios and can return a set of Pareto-optimal solutions, in this case, it effectively identified the optimal solution for the single-objective problem.