Genetic Algorithm in Matlab tool box

2 views (last 30 days)
Suresh Nayak Bhukya
Suresh Nayak Bhukya on 23 Sep 2019
Commented: Athul Prakash on 3 Oct 2019
How to specify string length in Binary coded Genetic algorithm in Matlab toolbox?\
eg:Say String length as 16 bits for variable.

Answers (1)

Athul Prakash
Athul Prakash on 26 Sep 2019
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 Comments
Suresh Nayak Bhukya
Suresh Nayak Bhukya on 30 Sep 2019
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 on 3 Oct 2019
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!

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!