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

Walter Roberson
Walter Roberson 2016년 11월 25일
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 2016년 11월 25일
편집: Utkarsh Konge 2016년 11월 25일
@Walter Roberson I want to pass the just one bitstring

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 25일

0 개 추천

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

Utkarsh  Konge
Utkarsh Konge 2016년 11월 25일
From what I know, I would be using the "ga()" function. I dont know how to get the individual vector.
Walter Roberson
Walter Roberson 2016년 11월 25일
The vector is simply the argument that is passed to the objective function. You can extract individual elements by indexing. For example if the current bitstring is 0110 then that would be passed to your objective function as [0, 1, 1, 0]
Utkarsh  Konge
Utkarsh Konge 2016년 11월 25일
편집: Utkarsh Konge 2016년 11월 25일
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 2016년 11월 25일
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??

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

질문:

2016년 11월 25일

댓글:

2016년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by