遗传算法约束

时间:2014-06-10 09:12:53

标签: matlab genetic-algorithm

如何将以下约束传递给Matlab ga优化函数?请注意,x是向量1xnvars

约束1

0.2 <= sum(x,2)/(W*H) <= 0.4 

where `W` and `H` are two constant.

约束2

x(1) >= x(2) >= ... >= x(size(x,1)) 

1 个答案:

答案 0 :(得分:1)

有关文档,请参阅here

A = cat(1,ones(1,nvars), ones(1,nvars)*-1)/W/H;
b = [0.4;-0.2];    

function [ceq ce] = noncolon1(x)
    ce = [];
    ceq = x(1,2:end) - x(1,1:end-1);
end

[x , fval] = ga(@fitnessfunc,nvars,A,b,[],[],[],[],@noncolon1);