problem with writing uncommon constraint function in genetic algorithm???
显示 更早的评论
Hi everyone, How to write a constraint function in genetic algorithm that is not directly related to fitness function?
for example, suppose that fitness=x1+x2 ; y1<y2 while y1 and y2 is dependent on x1,x2 and other some parameters.
Any suggestion will be great help and I appreciate that.
thank you guys.
回答(1 个)
Alan Weiss
2015-12-16
Take a look at the documentation of nonlinear constraints. Your nonlinear constraint function would be something like this:
function [c,ceq] = confun(x)
% calculate y1 here
% calculate y2 here
c = y1 - y2;
ceq = [];
Alan Weiss
MATLAB mathematical toolbox documentation
4 个评论
Hamid
2015-12-17
Alan Weiss
2015-12-18
Your nonlinear constraint function needs to be a function of one variable, which I assume is Etouch.
function [c, ceq] = myconstr(Etouch)
c(1) = Etouch-GPR ;
c(2) = Estep-Es ;
c(3) = Etouch-Em ;
ceq = [];
end
Alan Weiss
MATLAB mathematical toolbox documentation
Hamid
2015-12-18
Alan Weiss
2015-12-28
I think that the error message is clear: GPR is undefined when the nonlinear constraint function runs. I suggest that you use the debugger to find out why.
Alan Weiss
MATLAB mathematical toolbox documentation
类别
在 帮助中心 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!