简体   繁体   English

在Matlab中使用遗传算法时如何设置整数约束?

[英]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. 请注意,线性不等式约束Ab以及非线性约束nonlcon是可选的,如果不存在,可以将其替换为[]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MATLAB遗传算法中的约束-不仅仅是输入约束 - Constraints in MATLAB Genetic Algorithm - Not Just Input Constraints MATLAB遗传算法优化返回的整数值高于边界,并且违反了不等式约束。 为什么? - MATLAB genetic algorithm optimization returns integer values higher than boundaries and violates inequality constraints. Why? Matlab遗传算法如何利用分类精度作为适应度函数 - Genetic algorithm with matlab how to use classification accuracy as fitness function 如何使遗传算法能够收敛(Matlab) - How to allow the genetic algorithm to run to convergence (Matlab) 遗传算法Matlab最小化 - genetic algorithm matlab minimization matlab遗传算法优化 - Optimization with genetic algorithm in matlab Matlab中遗传算法的并行化 - Parallelization of a Genetic Algorithm in Matlab 在遗传算法中,如果没有约束,如何初始化种群以及如何确定染色体长度? - in genetic algorithm, how to initialize population and how to determine the length of chromosomes if there is no constraints? 在Matlab中使用遗传算法一次测试一组参数 - Testing one set of parameters one times using genetic algorithm in Matlab 预先分配一组结构,用于Matlab中的遗传算法 - Pre-allocate an array of structures for use in genetic algorithm in Matlab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM