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!