[英]How to set the integer constraints when use the Genetic Algorithm in Matlab?
如果有人能告诉我如何设置变量的整数约束(即它们的变量只能为0或1),将不胜感激。
x = ga(fitnessfcn,nvars);
Use the optional ga
function parameters LB
(lower bound), UB
(upper bound) and IntCon
(integer constraints). 使用可选的
ga
函数参数LB
(下限), UB
(上限)和IntCon
(整数约束)。 The signature for the MATLAB genetic algorithm function that you want to use is: 您要使用的MATLAB遗传算法函数的签名为:
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon)
For example, you could use the MATLAB GA to solve a 10 binary variable problem as follows: 例如,您可以使用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);
Notice that the linear inequality constraints A
and b
, and non-linear constraints nonlcon
are optional and can be replaced with []
if they don't exist. 请注意,线性不等式约束
A
和b
以及非线性约束nonlcon
是可选的,如果不存在,可以将其替换为[]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.