How to use ga in matlab as a binary genetic algorithm?

조회 수: 6 (최근 30일)
Phoenix98
Phoenix98 2018년 12월 25일
댓글: Walter Roberson 2018년 12월 25일
Hi,
I want to use ga for binary variables only?

답변 (1개)

Stephan
Stephan 2018년 12월 25일
편집: Stephan 2018년 12월 25일
Hi,
use IntCon and set lower and upper bounds to zero respectively ones.
Best regards
Stephan
  댓글 수: 5
Walter Roberson
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 CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by