Solving Optimization Problems

Multi-Objective Optimization with Linear and Nonlinear Constraints in Matlab

Hello everyone and welcome!

In this post, I’m going to show you how to solve multi-objective optimization with linear and nonlinear constraints in Matlab. This method is very easy and effective. Minimum programming skill is required.

Here are the details of the benchmark problem to test the performance of the method.

To solve this problem, we need to convert the linear and nonlinear constraints of the problem to these forms.

Let’s see how this multi objective optimization method works.

For more videos like this, check my YouTube channel here.

Matlab code

objective_function.m

function Output = objective_function(Input)
x1 = Input(1);
x2 = Input(2);
x3 = Input(3);
x4 = Input(4);
x5 = Input(5);
x6 = Input(6);

F1 = - (25*(x1-2)^2 + (x2-2)^2 + (x3-1)^2 + (x4-4)^2 + (x5-1)^2);
F2 = x1^2 + x2^2 + x3^2 + x4^2 + x5^2 + x6^2;

Output = [F1 F2];

nonlinear_constraints.m

function [C Ceq] = nonlinear_constraints(Input)
x1 = Input(1);
x2 = Input(2);
x3 = Input(3);
x4 = Input(4);
x5 = Input(5);
x6 = Input(6);

C(1)=(x3-3)^2 + x4 -4;
C(2)= -(x5-3)^2 - x6 +4;
Ceq = [];

solver.m

function [x,fval,exitflag,output,population,score] = solver(nvars,Aineq,bineq,lb,ub,MaxGenerations_Data)
%% This is an auto generated MATLAB file from Optimization Tool.

%% Start with the default options
options = optimoptions('gamultiobj');
%% Modify options setting
options = optimoptions(options,'MaxGenerations', MaxGenerations_Data);
options = optimoptions(options,'CrossoverFcn', {  @crossoverintermediate [] });
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'PlotFcn', { @gaplotpareto });
[x,fval,exitflag,output,population,score] = ...
gamultiobj(@objective_function,nvars,Aineq,bineq,[],[],lb,ub,@nonlinear_constraints,options);

main_program.m

clc
clear all

nvars =6;
Aineq = [-1 -1 0 0 0 0; 1 1 0 0 0 0; -1 1 0 0 0 0; 1 -3 0 0 0 0];
bineq = [-2; 6; 2; 2];
lb = [0; 0; 1; 0; 1; 0];
ub = [10; 10; 5; 6; 5; 10];
MaxGenerations_Data =100;
[x,fval,exitflag,output,population,score] = solver(nvars,Aineq,bineq,lb,ub,MaxGenerations_Data);
fval
x

P/s: If you find the post useful, share it to remember and to help other people as well.

Dr.Panda

View Comments

  • Hi dear
    First of all i would like to thanks you for a very interesting content of your channel really very useful. Secondly, if i will send you some problems to go on above them .
    Thanks so much.
    Best Regards

  • I tried but got an error, is there any suggestion

    Error using optimoptions (line 124)
    Invalid solver specified. Provide a solver name or handle (such as 'fmincon' or @fminunc).
    Type DOC OPTIMOPTIONS for a list of solvers.

    Error in solver (line 5)
    options = optimoptions('gamultiobj');

  • fval =

    -42.4672 4.0325
    -64.4425 4.3167
    -204.9162 25.4560
    -68.4659 4.4200
    -176.3779 23.3690
    -117.1029 9.2984
    -187.3962 24.2004
    -137.3266 20.3133
    -245.4875 37.6128
    -42.4672 4.0325
    -244.0463 33.8560
    -244.9977 36.3944
    -242.8695 31.1689
    -149.2609 21.4148
    -116.6668 8.4164
    -189.4040 24.3959
    -85.4876 4.8998
    -117.9602 18.7262
    -116.1207 6.9885
    -98.0002 5.4020
    -242.2967 30.1695
    -80.2893 4.7804
    -201.9388 25.1849
    -169.1371 22.7629
    -75.2741 4.6611
    -227.2502 27.2069
    -58.1491 4.1957
    -152.1515 21.7272
    -215.3331 26.2422
    -158.9071 21.9578
    -131.5660 19.9300
    -131.9951 20.0866
    -53.0899 4.1138
    -105.0623 5.6095
    -218.7035 26.5650
    -72.7025 4.5284
    -245.5291 37.8639
    -116.3443 7.5633
    -145.3884 21.1045
    -115.9527 6.0011
    -235.5090 27.8822
    -192.0645 24.6629
    -165.5557 22.4768
    -223.8144 26.9094
    -154.7908 21.7831
    -120.5257 19.0029
    -95.6976 5.2437
    -117.1029 9.3063
    -179.6290 23.7339
    -244.3910 34.7710
    -142.8774 21.0709
    -109.5279 5.7853
    -139.8956 20.6589
    -242.2426 29.0887
    -162.0649 22.2859
    -183.6902 24.0545
    -127.6009 19.6715
    -88.9368 5.0713
    -213.4980 26.1139
    -197.1802 24.9800
    -243.4899 32.6342
    -170.8270 22.9209
    -229.8207 27.5322
    -219.8152 26.8394
    -93.0124 5.1635
    -59.8934 4.2268
    -240.9637 28.6544
    -210.9423 25.9079
    -48.0658 4.0562
    -244.0555 33.8565
    x =

    0.9902 1.0089 1.0083 0.0010 1.0011 0.1235
    0.6133 1.3866 1.0052 0.0007 1.0007 0.0770
    4.7417 0.9267 1.0346 0.0205 1.0031 0.1899
    0.5553 1.4466 1.0047 0.0026 1.0023 0.0695
    4.5241 0.8750 1.0391 0.0207 1.0128 0.1739
    0.0001 2.0000 2.0548 0 1.0000 0.2760
    4.6107 0.9073 1.0345 0.0242 1.0052 0.1933
    4.1906 0.8299 1.0177 0.0015 1.0008 0.1610
    5.0009 1.0001 2.8319 0.0039 1.1594 1.4965
    0.9902 1.0089 1.0083 0.0010 1.0011 0.1235
    5.0008 1.0002 2.3868 0.0005 1.1213 0.9455
    5.0008 1.0001 2.6883 0.0000 1.1433 1.3608
    5.0007 1.0003 1.9016 0.0060 1.0769 0.6211
    4.2989 0.8820 1.0471 0.0142 1.0163 0.1644
    0.0003 2.0000 1.8383 0.0012 1.0000 0.1927
    4.6270 0.9081 1.0426 0.0405 1.0155 0.2046
    0.3339 1.6654 1.0030 0.0029 1.0028 0.0561
    4.0055 0.7808 1.0303 0.0094 1.0046 0.0423
    0.0004 2.0005 1.4038 0.0002 1.0000 0.1255
    0.1889 1.8308 1.0059 0.0037 1.0007 0.0356
    5.0006 1.0004 1.6977 0.0352 1.0346 0.4571
    0.3973 1.6081 1.0040 0.0096 1.0092 0.0999
    4.7192 0.9112 1.0346 0.0127 1.0025 0.0885
    4.4653 0.8501 1.0245 0.0161 1.0097 0.1789
    0.4622 1.5618 1.0019 0.0046 1.0013 0.0422
    4.9008 0.9847 1.0690 0.0188 1.0164 0.2084
    0.7089 1.2909 1.0060 0.0033 1.0020 0.1036
    4.3240 0.9017 1.0735 0.0105 1.0104 0.2096
    4.8163 0.9454 1.0327 0.0089 1.0315 0.1453
    4.3801 0.8153 1.0333 0.0148 1.0059 0.1680
    4.1382 0.8190 1.0458 0.0162 1.0078 0.1575
    4.1441 0.8628 1.0577 0.0295 1.0127 0.1520
    0.7922 1.2073 1.0067 0.0008 1.0009 0.1155
    0.1125 1.8931 1.0054 0.0015 1.0008 0.0184
    4.8404 0.9550 1.0547 0.0107 1.0329 0.2111
    0.4969 1.5054 1.0052 0.0034 1.0008 0.0562
    5.0009 1.0001 2.8632 0.0137 1.1906 1.4965
    0.0000 1.9995 1.5986 0.0013 1.0000 0.0981
    4.2644 0.8392 1.0840 0.0198 1.0115 0.1271
    0.0004 1.9998 1.0010 0.0003 1.0000 0.0010
    4.9576 1.0025 1.0846 0.0226 1.0361 0.2216
    4.6478 0.9221 1.0539 0.0460 1.0185 0.2464
    4.4358 0.8373 1.0254 0.0160 1.0086 0.1737
    4.8766 0.9804 1.0515 0.0124 1.0089 0.2081
    4.3469 0.8635 1.0452 0.0246 1.0127 0.1537
    4.0315 0.8069 1.0361 0.0090 1.0046 0.1271
    0.2145 1.7861 1.0018 0.0062 1.0014 0.0334
    0.0001 2.0000 2.0548 0 1.0039 0.2760
    4.5496 0.9019 1.0755 0.0112 1.0110 0.2072
    5.0005 1.0001 2.5241 0.0034 1.1192 1.0685
    4.2420 0.8848 1.0648 0.0047 1.0061 0.3837
    0.0657 1.9407 1.0068 0.0013 1.0005 0.0102
    4.2158 0.8758 1.0414 0.0150 1.0072 0.1389
    5.0008 1.0002 1.3927 0.0039 1.0304 0.2808
    4.4065 0.8153 1.0489 0.0148 1.0371 0.1680
    4.5822 0.9270 1.0599 0.0197 1.0158 0.2075
    4.1012 0.8473 1.0438 0.0130 1.0125 0.1382
    0.2925 1.7232 1.0059 0.0036 1.0010 0.0492
    4.8035 0.9395 1.0524 0.0142 1.0064 0.1937
    4.6834 0.8994 1.0421 0.0061 1.0092 0.3636
    5.0007 1.0002 2.1813 0.0028 1.1025 0.8081
    4.4793 0.8628 1.0284 0.0181 1.0119 0.1738
    4.9189 1.0331 1.0970 0.0149 1.0221 0.1467
    4.8482 0.9549 1.1478 0.0135 1.0321 0.1992
    0.2453 1.7576 1.0043 0.0023 1.0020 0.0408
    0.6817 1.3194 1.0064 0.0025 1.0009 0.0814
    4.9939 1.0040 1.2049 0.0193 1.0491 0.3936
    4.7851 0.9471 1.0170 0.0101 1.0181 0.2078
    0.8810 1.1183 1.0074 0.0017 1.0012 0.1108
    5.0008 1.0001 2.3868 0.0005 1.1213 0.9455

    Dear Sir,
    Out of all these values which one is the Optimal value of fval and x?

    • In multi objective optimization, all of them are optimal. They are equally important

  • Thank you a lot for this video. May God bless you.
    I have some question
    1) In the case of binary variables (for example in knapsack problem). How to specify the lower and uper bound?
    2) Also I would know the matlab code to obtain the result in decision space

  • Thank you a lot for this video. May God bless you. I have some question
    1) In the case of binary variables (for example in knapsack problem). How to specify the lower and uper bound? 2) Also I would know the matlab code to obtain the result in decision space

Recent Posts

Adaptive Re-Start Hybrid Genetic Algorithm in Matlab

Hello everyone! In this post, I am going to show you my innovative version of…

8 months ago

Test Your Understanding About Genetic Algorithm (Test 2)

Hello everyone. Let’s take a test to check your understanding about genetic algorithm, with multiple…

8 months ago

Adaptive Restart Hybrid Genetic Algorithm

Hello everyone! In this post, I am going to show you my innovative version of…

8 months ago

Adaptive Re-Start Hybrid Genetic Algorithm (Test the Performance in Case Studies)

Hello everyone. In this post, I am going to show you my innovative version of…

1 year ago

Adaptive Re-Start Hybrid Genetic Algorithm in Matlab

Hello everyone! Let’s see how my innovative version of Genetic Algorithm, called Adaptive Re-start Hybrid…

1 year ago

Crypto Quiz (Test Your Knowledge About Cryptocurrency)

Hello everyone! Let’s take a short quiz, to test your knowledge about crypto-currency, or crypto.…

2 years ago