[英]How to set the integer constraints when use the Genetic Algorithm in Matlab?
如果有人能告诉我如何设置变量的整数约束(即它们的变量只能为0或1),将不胜感激。
x = ga(fitnessfcn,nvars);
使用可选的ga
函数参数LB
(下限), UB
(上限)和IntCon
(整数约束)。 您要使用的MATLAB遗传算法函数的签名为:
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon)
例如,您可以使用MATLAB GA来解决10位二进制变量的问题,如下所示:
% Number of variables
nVars = 10
% Lower and upper bounds
LB = zeros(1, nVars);
UB = ones(1, nVars);
% Variables with integer constraints (all in this case)
IntCon = 1:nVars;
% Run the GA solver
x = ga(fitnessfcn, nVars, [], [], [], [], LB, UB, [], IntCon);
请注意,线性不等式约束A
和b
以及非线性约束nonlcon
是可选的,如果不存在,可以将其替换为[]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.