How to use ga in matlab as a binary genetic algorithm?
15 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to use ga for binary variables only?
0 个评论
回答(1 个)
Stephan
2018-12-25
编辑:Stephan
2018-12-25
5 个评论
Walter Roberson
2018-12-25
rng(1,'twister')
IntCon = 1:3;
%% Start with the default options
options = optimoptions('ga');
%% options setting
options = optimoptions(options,'MaxGenerations', 500);
options = optimoptions(options,'MaxStallGenerations', inf);
options = optimoptions(options,'FunctionTolerance', 0);
options = optimoptions(options,'ConstraintTolerance', 0);
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'PlotFcn', { @gaplotbestf });
[x,fval,exitflag,output,population,score] = ...
ga(@fitness,3,[],[],[],[],[0 0 0],[1 1 1],@constraints,IntCon,options);
disp(x);
However, the best is not [1 0 0]: it is [1 0 1]
There are only 8 possible configurations for x, so there is no point in running 500 generations.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!