How to use binary bits in genetic algorithm for integer constraints?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I have five different integer constraints. But when I select bit string option in matlab ga toolbox, I get the below error:
Optimization running. Error running optimization. Problem has integer constraints. PopulationType must be set to 'doubleVector'.
Also, I am not allowed to use single point/two point crossover. By default matlab is using scattered crossover when there are integer constraints. If it is possible to use binary bits for integer constraints in matlab ga toolbox, where may I set the size of the binary bits? Please help.
Accepted Answer
Walter Roberson
on 28 Feb 2017
When you use bitstring all variables are single bit binary that for performance reasons are stored as double.
You can use the other crossover with bitstring.
https://www.mathworks.com/help/gads/genetic-algorithm-options.html#f14223
10 Comments
Ripunjoy Gogoi
on 28 Feb 2017
Thanks for replying. Actually I want to use binary bits for my problem (integer constraint) so that I could use single point or two point crossover. I don't want to use real coded GA. But apparently if you have integer variables, GA Tool Box overrides with its default sets. Please suggest.
Walter Roberson
on 28 Feb 2017
Do not ask for integer constraints when population type is set to bitstring, and do not specify any constraints like lb or ub. Just give the population type as bitstring and give your choice of crossover. All variables will be configured as integer 0 or 1.
If you want use mixed integer with some variables that happen to be binary, or want to use all integer but some of them happen to be binary and you want special crossover, then that is a different situation than choosing population type bitstring, which is strictly for the case all bits are single bit binary.
For mixed integer or all integer cases where you want something different than the crossover provided automatically when you give intcons, then what you have to do is not tell it that you are using intcons or bitstring, and instead provide custom population and crossover and mutation functions that all just happen to only create integer values in appropriate positions
Ripunjoy Gogoi
on 28 Feb 2017
Ok. Thanks again. Let me try then.
Ripunjoy Gogoi
on 28 Feb 2017
Dear Walter, It's working. Thanks. Can you suggest me some reference material on the same? I want to study and see how is it actually works? Like how is it assigning 0 and 1 to integer variables and other stuff. Regards,
Ripunjoy
Walter Roberson
on 28 Feb 2017
Which arrangement did you end up using?
Ripunjoy Gogoi
on 28 Feb 2017
The one with not asking for integer constraints. The first one. I haven't specified any bounds.
Walter Roberson
on 28 Feb 2017
To confirm, you used population type bitstring ?
Ripunjoy Gogoi
on 1 Mar 2017
Yes, I have used population type as bit string (my constraints are only integers). But please tell me one thing, if I don't provide the bounds, how does is it know its bounds as I have bounds e.g. 5<x<15 (all integers). Actually these are some of the questions that I have. Also, how is it assigning 0 and 1 to integer variables, like are they single bit or 2 bits or so on. Please reply and if possible give me some links/files to refer. Thank you.
Walter Roberson
on 1 Mar 2017
When you use bitstring as the population type, the elements will only ever be assigned 0.0 or 1.0.
You should not be using bitstring for integer ranges without using custom functions. Well, other than the possibility of binary numbers where you want crossover and mutation to happen at any bit boundaries.
For integer ranges like -5 to 15 you should either use intcons or custom functions.
Ripunjoy Gogoi
on 1 Mar 2017
Ok. Thanks
More Answers (0)
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Tags
See Also
on 28 Feb 2017
on 1 Mar 2017
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)