genetic algorithm simple problem

1 回表示 (過去 30 日間)
Phoenix98
Phoenix98 2018 年 12 月 10 日
コメント済み: Walter Roberson 2018 年 12 月 10 日
Hello ,
I have a simple problem to solve with the genetic algorithm in matlab
The fitness function is
that subject to
My question is how to apply these in matlab ga function?
  2 件のコメント
Mark Sherstan
Mark Sherstan 2018 年 12 月 10 日
編集済み: Mark Sherstan 2018 年 12 月 10 日
Look at this example here and then let us know if there is still need for clarification.
Phoenix98
Phoenix98 2018 年 12 月 10 日
Hi , I read it
but how to set the bounds lb and ub according to my problem?
below is the code with the fitness function
function y = fitness(x)
y = (3*x(1) + x(2) - 2*x(3)+0.8 \ 2*x(1)-x(2)+x(3)) + (4*x(1) -2*x(2)+x(3) \ 7*x(1)+3*x(2)-x(3));
% The main program
rng default
FitnessFunction = @fitness;
numberOfVariables = 3;
lb = [-1,-1];
ub = [0,0];
[x,fval] = ga(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub);

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 12 月 10 日
The item says 0 <= xi, i = 1, 2, 3. Therefore the entries are nonnegative. lb would be [0 0 0]. ub can be left empty or can be set to [inf inf inf]
  2 件のコメント
Phoenix98
Phoenix98 2018 年 12 月 10 日
Hi,
i tried these values and the f(x) in the solution equal to 2.471428 with x1=1,x2=0,x3=0 not equal to the matlab solution -2.190310
Walter Roberson
Walter Roberson 2018 年 12 月 10 日
So? You are using ga and ga only tries to find a global minima.
Besides, you are not implementing the formula you were given. In MATLAB,
(3*x(1) + x(2) - 2*x(3)+0.8 \ 2*x(1)-x(2)+x(3))
is the same as
((3*x(1)) + x(2) - (2*x(3)) + ((0.8 \ 2) * x(1)) - x(2) + x(3))
which is the same as
((3*x(1)) + x(2) - (2*x(3)) + ((0.8 / 2) * x(1)) - x(2) + x(3))
The form
first sequence \ second sequence
is not the same as
(first sequence) / (second sequence)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by