Global optimization toolbox

6 views (last 30 days)
Af
Af on 12 Dec 2011
Answered: Hari on 11 Jun 2025
Hi
I recently got a trial version of Global optimization toolbox (ID #1370077)and I was trying to implement some of the examples which are provided in the documentations using GA algorithm. However, it seems that I can not get it work the way it is explained in there. For example, Constrained Minimization Problem has a fairly simple structure but every time I run the codes it gives the following error:
Optimization terminated: average change in the fitness value less than options.TolFun and constraint violation is less than options.TolCon.
I tried to decrease the Constraint tolerance in my codes but apparently it does not change anything. Below I put the codes that I have been using to do this. I appreciate if somebody has an idea how to deal with this case.
Best regards Afshin
ObjectiveFunction = @my_funTst; nvars = 2; % Number of variables LB = [0 0]; % Lower bound UB = [1 13]; % Upper bound ConstraintFunction = @nlinconstTst; options = optimset('TolFun',1e-8,'TolCon',1e-8); [x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,ConstraintFunction);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
On a separate file I have the objective and constraint functions
function y = my_funTst(x) y = 100 * (x(1)^2 - x(2)) ^2 + (1 - x(1))^2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [c ceq] = nlinconstTst(x)
c = [1.5 + x(1)*x(2) + x(1) - x(2); -x(1)*x(2) + 10]; ceq = [];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Answers (1)

Hari
Hari on 11 Jun 2025
Hi,
I understand that you're trying to solve a constrained minimization problem using the "ga" function from MATLAB's Global Optimization Toolbox, but you're encountering an early termination with a message indicating small changes in fitness and constraint violation—even though you've tightened tolerances.
I assume that your goal is to get the GA algorithm to properly handle your nonlinear constraints and not exit prematurely due to perceived convergence.
In order to ensure GA correctly solves this constrained optimization problem, you can follow the below steps:
Step 1: Use GA-specific options with "gaoptimset"
You're currently using "optimset", which is intended for functions like fmincon. For GA, use "gaoptimset" to specify GA-relevant options like "TolFun" and "TolCon".
Step 2: Increase population size or generations
GA may terminate early if the population is too small to explore the constraint landscape well. Increase the population size and the number of generations to allow more exploration.
Step 3: Verify constraints are not too restrictive
Ensure that the constraint function is not overly limiting feasible regions. Use plotting or manual checks to see if feasible regions exist within your bounds.
Step 4: Add plot functions to monitor progress
Use the "PlotFcn" option to add diagnostic plots. This can help visualize how GA progresses with constraints.
Step 5: Ensure constraints and objective are continuous and differentiable
Though GA does not rely on gradients, discontinuous functions may still lead to early convergence or poor feasibility.
Here’s a quick summary of revised option settings:
  • Use:
options = gaoptimset('TolFun',1e-8,'TolCon',1e-8,'PopulationSize',100,'Generations',200,'PlotFcn',{@gaplotbestf,@gaplotmaxconstr});
Refer to the documentation of the functions used:
Hope this helps!

Community Treasure Hunt

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

Start Hunting!