在Matlab中使用遗传算法时如何设置整数约束?(How to set the integer constraints when use the Genetic Algorithm in Matlab?)
如果有人能告诉我如何设置变量的整数约束(即,它们的变量只能是0或1),我将不胜感激。
x = ga(fitnessfcn,nvars);
It would be much appreciated if anybody can tell me how to set the integer constrain for the variables(i.e., they variables can only be either 0 or 1).
x = ga(fitnessfcn,nvars);
原文:https://stackoverflow.com/questions/37394612
更新时间:2020-02-05 07:53
最满意答案
使用可选的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