How to find fixed number of variables with value 1 using Genetic Algorithm with population type Bitstring ?

3 views (last 30 days)
I am solving an objective function with Genetic Algorithm with population type bitstring (values 0 and 1 only) using toolbox.
The variables select rows of a matrix (10*10) and the objective function is to find a minimum value in a further calculated matrix using values from those rows.
The current variables are 10. So the the GA solves and find values of all 10 variables.
How to select a fix number of variables with a value of 1 ? example out of 10 variables, i need to find the solution of 1 for 5 variables only i.e. i want to find the 5 best rows from matrix.

Accepted Answer

Alan Weiss
Alan Weiss on 14 Sep 2021
If I understand you correctly (and I might not have understood), you want to impose a linear constraint on the population x
sum(x,2) == 5
meaning each row (individual) has exactly 5 with value 1, the rest have value 0.
If that is what you are trying to do, then I believe that you need to impose custom creation, mutation, and possibly crossover functions. The creation and mutation functions should ensure that you maintain exactly five individuals that have value 1. Some crossover functions might do this automatically, but you would have to check to be sure.
Custom creation function syntax which also has details on using bitstring such as which built-in crossover functions are available
Alan Weiss
MATLAB mathematical toolbox documentation
Ankur Shah
Ankur Shah on 16 Sep 2021
Edited: Ankur Shah on 16 Sep 2021
Can you share the source of it i.e ."mutation rate + crossover fraction = 1" ?
Also is it possible to know the creation, crossover and mutaiton function which matlab uses for solving it ?. I couldn't find in the documentation.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!