# GA initial solution not used in problem base solver

6 views (last 30 days)

Show older comments

Hi,

I am using ga with integer variables to solve a minimization problem. I started by using a single point as the initial guess, but found out that it was not used, as ga resulted in worse solutions than the initial point. After this I tried with a population, but it did as poorly, losing to the original solution I had.

After this, I tried the example for initial population generation for GA when using solve(). Example is the first one in this link Create values for optimization problem - MATLAB optimvalues - MathWorks Nordic

I modified the example to include the best solution it finds with default rng and also to display each iteration. My script for this is below, with my additions commented. I concluded that having the best solution (x,y) = (1,1) in the initial population does not change the output, which to me seems that it is not actually using the given population. Same result with a single point guess.

Am I making some mistake, or is the initial population actually ignored here? I am using R2022b.

%%

clc

x = optimvar("x",LowerBound=-5,UpperBound=5);

y = optimvar("y",LowerBound=-5,UpperBound=5);

rosenbrock = (10*(y - x.^2)).^2 + (1-x).^2;

prob = optimproblem(Objective=rosenbrock);

rng default % For reproducibility

xval = -5 + 10*rand(1,100);

yval = -5 + 10*rand(1,100);

xval(1) = 1; %The best

yval(1) = 1; %solution

x0.x = 1; %The best solution for

x0.y = 1; %single point guess

vals = optimvalues(prob,x=xval,y=yval);

opts = optimoptions("ga",PopulationSize=100,Display="iter"); %Added 'iter' display

[sol,fv] = solve(prob,vals,Solver="ga",Options=opts)%Use x0 or vals as 2nd argument

##### 0 Comments

### Answers (2)

Nikhilesh
on 9 Mar 2023

Alan Weiss
on 10 Mar 2023

When using the problem-based approach you must pass initial points to ga using optimvalues. See https://www.mathworks.com/help/releases/R2022a/gads/global-initial-points.html

Alan Weiss

MATLAB mathematical toolbox documentation

##### 2 Comments

Alan Weiss
on 13 Mar 2023

Thanl you for letting me know about the typo. I'll fix it in the next release.

Alan Weiss

MATLAB mathematical toolbox documentation

### See Also

### Categories

Find more on

**Get Started with Problem-Based Optimization and Equations**in Help Center and File Exchange### Community Treasure Hunt

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

Start Hunting!