How to Solve Triple-Objective Optimization Problems Using Matlab

Hello everyone and welcome!

In this post, I’m going to show you a simple but effective method to solve triple objective optimization problems using Matlab.

Triple objective optimization is one of the popular multi-objective optimization problems used in various research fields, in which three objective functions are simultaneously optimized.

This method is based on multi-objective genetic algorithm solver in Matlab – it is very easy to use, and minimum programming skill is required.

If you want to download this Matlab code, look at the end of this post.

Here are details of the test function:

Let’s see how this method works.

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

Matlab Code

multi_objective_function.m

function Output = multi_objective_function(Input)

x = Input(1); % variable 1
y = Input(2); % variable 2

F1 = 0.5*(x^2 + y^2) + sin(x^2 + y^2); % objective 1
F2 = ((3*x -2*y +4)^2)/8 + ((x - y +1)^2)/27 +15;  % objective 1
F3 = 1/(x^2 + y^2 +1) - 1.1*exp(-x^2 -y^2); % objective 1
Output = [F1 F2 F3];

multi_objective_genetic_algorithm_solver.m

function [x,fval,exitflag,output,population,score] = multi_objective_genetic_algorithm_solver(nvars,lb,ub,PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data)
options = optimoptions('gamultiobj');
options = optimoptions(options,'PopulationSize', PopulationSize_Data);
options = optimoptions(options,'MaxGenerations', MaxGenerations_Data);
options = optimoptions(options,'MaxStallGenerations', MaxStallGenerations_Data);
options = optimoptions(options,'FunctionTolerance', FunctionTolerance_Data);
options = optimoptions(options,'ConstraintTolerance', ConstraintTolerance_Data);
options = optimoptions(options,'CrossoverFcn', {  @crossoverintermediate [] });
options = optimoptions(options,'Display', 'off');
[x,fval,exitflag,output,population,score] = ...
gamultiobj(@multi_objective_function,nvars,[],[],[],[],lb,ub,[],options);

Main_program.m

clc
clear all
close all

nvars = 2;
lb = [-3 -3];
ub = [3 3];
PopulationSize_Data = 500;
MaxGenerations_Data = 100;
MaxStallGenerations_Data = 100;
FunctionTolerance_Data = 0;
ConstraintTolerance_Data = 0;

[x,fval,exitflag,output,population,score] = multi_objective_genetic_algorithm_solver(nvars,lb,ub,PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data);

optimal_solution = x
objective_functions = fval
plot3(fval(:,1),fval(:,2),fval(:,3),'o')

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

47 Replies to “How to Solve Triple-Objective Optimization Problems Using Matlab”

      1. sir im applying this program code but always showing this errorIndex in position 1 exceeds array bounds.

        Error in Main_program (line 20)
        plot3(fval(1,:),fval(2,:),fval(3,:))
        , kindly make changes in my code so that ill get the graph.really need your help urgently

        function Output = multi_objective_function(Input)
        x(1) = Input(1); % variable 1
        x(2) = Input(2); % variable 2
        x(3) = Input(2); % variable 3
        x(4) = Input(2); % variable 4

        F1 = 84718*x(1)+72627.42*x(2)+41021.98*x(3)+58077.44*x(4); % objective 1
        F2 = -1124.424*x(1)-1004.247*x(2)-8.40858*x(3)-10.52292*x(4); % objective 2
        F3 = -51.524*x(1)-47.666*x(2)-19.136*x(3)-19.134*x(4); % objective 3
        Output = [F1 F2 F3];
        function [x,fval,exitflag,output,population,score] = multi_objective_genetic_algorithm_solver(nvars,Aeq,beq,Aineq,bineq,lb,ub,PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data)
        options = optimoptions(‘gamultiobj’);
        options = optimoptions(options,’PopulationSize’, PopulationSize_Data);
        options = optimoptions(options,’MaxGenerations’, MaxGenerations_Data);
        options = optimoptions(options,’MaxStallGenerations’, MaxStallGenerations_Data);
        options = optimoptions(options,’FunctionTolerance’, FunctionTolerance_Data);
        options = optimoptions(options,’ConstraintTolerance’, ConstraintTolerance_Data);
        options = optimoptions(options,’CrossoverFcn’, { @crossoverintermediate [] });
        options = optimoptions(options,’Display’, ‘off’);
        [x,fval,exitflag,output,population,score] = …
        gamultiobj(@multi_objective_function,nvars,Aeq,beq,Aineq,bineq,lb,ub,[],options);
        clc
        clear
        close all

        nvars = 4;
        Aineq =[1 1 1 1; 220.086 210.356 92.672 135.994; 464.75 203.194 261.548 206.638];
        bineq = [49.9; 660; 1136];
        lb = [0 0 0 0];
        ub = [];
        PopulationSize_Data = 500;
        MaxGenerations_Data = 100;
        MaxStallGenerations_Data = 100;
        FunctionTolerance_Data = 0;
        ConstraintTolerance_Data = 0;

        [x,fval,exitflag,output,population,score] = multi_objective_genetic_algorithm_solver(nvars,[],[],Aineq,bineq,lb,ub,PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data);

        optimal_solution = x;
        objective_functions = fval;
        plot3(fval(1,:),fval(2,:),fval(3,:))
        unable to plot it kindly resolve my problem

  1. Thanks a lot.
    But two question!
    First, is it possible to increase the number of input variables to 3 or more?
    Second, is this method called NSGAII bult in algorithm from Matlab to solve optimization?

    1. Hi, thanks for your interest! Yes, number of variables can be larger than 3. This is no NSGA II, this is multi objective genetic algorithm in Matlab. For NSGA II, please have a look other posts on this blog.

  2. Thank you so much.
    I have question about this procedure. when one of the objectives must be minimize and the rest of the objectives should be maximized in this case what to do?

  3. Interesting example!

    I’m having the following issue:

    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 multi_objective_genetic_algorithm_solver (line 2)
    options = optimoptions(‘gamultiobj’);

    I would appreciate some advice

  4. How can I relate the objective functions in my case. i have three independent variables and one dependent variable. how can i set objective to find the optimal results for dependent variable that i have got. Is there any way to find the equations for this kind of problems. Really need some tips.

  5. Hi, Its showing
    Invalid solver specified. Provide a solver name or handle (such as ‘fmincon’ or @fminunc).Type DOC OPTIMOPTIONS for a list of solvers.

    Error in multi_objective_genetic_algorithm_solver (line 2)
    options = optimoptions(‘gamultiobj’);

    Error in Main (line 14)
    [x,fval,exitflag,output,population,score] =
    multi_objective_genetic_algorithm_solver(nvars,lb,ub,PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,FunctionTolerance_Data,ConstraintTolerance_Data);
    It is not running.

  6. when i uused your program in my laptop; result showed the folowing error
    Undefined function or variable ‘multi_objective_function’.

    Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
    fcn_handle = @(x) fcn(x,FcnArgs{:});

    Error in gamultiobjMakeState (line 28)
    Score = FitnessFcn(state.Population(1,:));

    Error in gamultiobjsolve (line 8)
    state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);

    Error in gamultiobj (line 303)
    [x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, …

    Error in multi_objective_genetic_algorithm_solver (line 11)
    gamultiobj(@multi_objective_function,nvars,[],[],[],[],lb,ub,[],options);

    Error in main_program (line 14)
    [x,fval,exitflag,output,population,score] =
    multi_objective_genetic_algorithm_solver(nvars,lb,ub,PopulationSize_Data,MaxGenerations_Data,MaxStallGenerations_Data,Function

  7. Hello,thanks for your great videos,this video is helping me a lot,I have a question! how can I show all GA optimization steps to converge to a solution and also be able to change size of initial population each time?
    I will appreciate for your answer in advance

  8. Hi Sir,
    I am doing my thesis on the topic: “Time-Cost optimization using genetic algorithm in Construction Project”.
    I will appreciate if you can help me understand how I can encode my project data into GA, using the mathematical model ( i.e. objective functions and constraint functions ).

    1. Good to hear that! There are many GA codes on this blog which you can customize them to solve various optimization problems in your fields.

  9. Thank you very much, I´m using your code to perform a simulation of a microgrid with multiobjective results. God bless you.

  10. Thank you very much for your code.
    I would like to solve a problem similar to the example you gave in the video, but except that in my case, in addition to the constraints on the vairables of the functions, I also have constraints on the functions to be optimized.
    Starting from your example proposed in the video, let’s also consider that the desired limits of F1, F2 and F3 are respectively: 0.01 ≤ F1 ≤ 2; 15 ≤ F2 ≤ 15.07 and -0.07 ≤ F3 ≤ 0.06. In this case, can you give me the complete code allowing to bring out all the feasible solutions and to deduce the optimal solutions answering my additional constraints on F1, F2 and F3 that I added?

      1. Good morning,
        I would like you to give me a complete code taking into account the additional constraints that I added to your code to solve triple objective optimization problems with Matlab by genetic algorithms(0.01 ≤ F1 ≤ 2; 15 ≤ F2 ≤ 15.07 and -0.07 ≤ F3 ≤ 0.06) and which will allow me in the end to display on the Pareto front the dominant solutions, the non-dominant solutions and the initial population.

        Can you help me with this code?

        It’s really very urgent and I’ve been really stuck since

  11. Good morning,
    I have a multiobjective optimization problem (three functions F1,F2 and F3) and with several multivariate constraints (HRC,Vc,f,ap).
    I would like to minimize three functions with multiple constraints and show on the same curve the optimal pareto front (non-dominated solutions), the dominated solutions and the initial population.

    The three functions to be minimized are:

    F1 = 2.83-0.24*HRC-0.04*Vc+157.78*f+184.58*ap
    F2 = -8.29+0.19*HRC-0.07*Vc+622.09*f+212.86*ap
    F3 = -9.22-0.23*HRC-0.08*Vc+695.92*f+307.37*ap

    The constraints are as follows:

    45 ≤ HRC ≤ 55.25
    50 ≤ Vc ≤ 300
    0.05 ≤ f ≤ 0.2
    0.1 ≤ ap ≤ 0.4

    and:

    16.04 ≤ F1 ≤ 90.41
    50.52 ≤ F2 ≤ 193.25
    50.04 ≤ F3≤ 178.67

    Can you help me by giving me the complete MATLAB code to solve my problem?

  12. Hello Sir, How can I use this example to minimise power loss and reactive power loss using DG system , Capacitor and Electricvehicle charging system ?

  13. Hi sir,
    I’m doing an optimization of system with 3 objective functions with different unit for each function.
    can I use this code to optimize the problem?

Leave a Reply

Your email address will not be published. Required fields are marked *