ga
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 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!