Solving Optimization Problems

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.

Dr.Panda

View Comments

      • 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

  • 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?

    • 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.

  • 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?

  • 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

  • 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.

  • 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.

  • 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

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…

5 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…

5 months ago

Adaptive Restart Hybrid Genetic Algorithm

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

6 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.…

1 year ago