[英]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.