Genetic algorithm viewing population

7 views (last 30 days)
I am using genetic algorithm on a string of 1s and 0s to solve an optimization problem. For this I have to pass the string generated to a function to check its feasibility. How can I store the population (i.e. the strings in every generation) and pass it to the function.
  2 Comments
Walter Roberson
Walter Roberson on 25 Nov 2016
Are you sure you need to pass the entire population at one time, and not just the current bitstring, which would be what the parameter to your objective function would be?
Utkarsh  Konge
Utkarsh Konge on 25 Nov 2016
Edited: Utkarsh Konge on 25 Nov 2016
@Walter Roberson I want to pass the just one bitstring

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Nov 2016
The objective function is automatically passed the current bitstring as a vector of double, values 0 and 1. You can pass that vector to a different function.
  4 Comments
Utkarsh  Konge
Utkarsh Konge on 25 Nov 2016
Edited: Utkarsh Konge on 25 Nov 2016
I am sorry if I am not getting this. But this is an example code -
fun = @(x) (10*x(1) + 20*x(2) - 30*x(3));
nvars = 3;
lb = [0 0 0];
ub = [1 1 1];
intcon = [1 2 3];
sol = ga(fun, nvars, [], [], [], [], lb, ub, [], intcon);
I dont know how to get the values of x it passes and factors to control it like the size of population, cross-over probability etc.
Thank you for your patience.
Walter Roberson
Walter Roberson on 25 Nov 2016
The x(1) and so on are the values it passes.
The control over size of the population and the like is through the options parameter. Possibly you want to use the OutputFcn parameter??

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!