Genetic Algorithm in Matlab tool box

1 次查看(过去 30 天)
How to specify string length in Binary coded Genetic algorithm in Matlab toolbox?\
eg:Say String length as 16 bits for variable.

回答(1 个)

Athul Prakash
Athul Prakash 2019-9-26
Hi Suresh,
Please check the documentation for ga() carefully:
Looks like you will need to specify that in 'nvars' argument (2nd position) in your call to ga()
To illustrate
Optimizing ps_example built-in function, I did the following:
op = optimoptions('ga', 'PopulationType', 'bitstring'); %set up the options to use PopulationType=bitstring
x = ga(@ps_example, 8, [], [], [], [], [], [], [], op); %to use 8 bits only.
So, ga runs by calling ps_example with eight 1/0 values. But this doesn't work out since ps_example is not a function defined on 1's and 0's alone.
Make sure that your optimizing function correctly accepts only 1's and 0's. Additionally, function should be able to run with your given number of inputs, 16 as you say.
Hope it helps you!
  2 个评论
Suresh Nayak Bhukya
Sir,
I am not able understand the above code. So please tell me in detail way.
Bounds for both variables are 0 to 10 and bit string length is 16.fbo.PNG
Athul Prakash
Athul Prakash 2019-10-3
ga() will optimize your function without using bit strings, by default. It performs mutation/crossover on x1 & x2 directly if you call
ga(@fun, 2) %fun being your obj. function coded in matlab
If you must use bitstrings, you can write the function 'fun' in such a way that it accepts 32 inputs (16 for each of x1, x2). Also, you will have to code your function to convert the bit string to your inputs x1/x2.
Good Luck!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by