ga

2 ビュー (過去 30 日間)
Natalia
Natalia 2012 年 2 月 3 日
編集済み: Matt J 2013 年 10 月 1 日
Hello! I have a function:
function z=my_fun(x)
a=2;
b=3;
c=1;
z=a*x(1)-b*x(2)+c*x(3);
I use the genetic algoritm (ga, gatool) to generate input parameters x(1), x(2) and x(3). It is necessary for me, that x(1)<x(2)<x(3). How and where can I set this constraint? Thank you very much for any answer :)
Natalia

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 2 月 3 日
Interesting idea. This should be possible, probably with non-linear constraint option.
However, (disclaimer: this is just a thought/curiosity, no guarantees at all), what if you just sort x at the beginning of my_fun()? This would enforce the constraint in your fitness function and possibly cause convergence of the guesses. Let me know if/how it works for you.
function z=my_fun(x)
x = sort(x);
a=2;
b=3;
c=1;
z=a*x(1)-b*x(2)+c*x(3);
  2 件のコメント
Natalia
Natalia 2012 年 2 月 4 日
Yes, it works. But if I have more input parameters and more constraints (for example: x(1)<x(2)<x(3), x(5)<x(4)<x(1)) sort will not help.
I think it linear constraint (this is just a thought/curiosity too).
If x(1)<x(2)<x(3)
hence:
x(1)<x(2);
x(2)<x(3);
x(1)<x(3);
hence:
1*x(1)-1*x(2)+0*x(3)<0;
0*x(1)+1*x(2)-1*x(3)<0;
1*x(1)+0*x(2)-1*x(3)<0;
If A*x<b,
hence:
A=[1 -1 0; 0 1 -1; 1 0 -1]
b=[0;0;0]
I try to use it. And it works... What do you think about it?
Sean de Wolski
Sean de Wolski 2012 年 2 月 6 日
Yes, that looks good, I guess it is a linear constraint.

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

その他の回答 (0 件)

カテゴリ

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