How to set up variable with only several states in the genetic algorithm
조회 수: 1 (최근 30일)
이전 댓글 표시
How to set up the constrain simple_constraint(x) in the genetic algorim optimization with variable x(2) and x(3)that can take only four values 0 1 2 4 ?
ObjectiveFunction = @simple_fitness;
nvars = 3; % Number of variables
LB = [0 0 0]; % Lower bound
UB = [1 4 4]; % Upper bound
ConstraintFunction = @simple_constraint;
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB, ...
ConstraintFunction)
function y = simple_fitness(x)
y = (x(1)^3*cos(x(2)*pi/2+0.9)*sin(x(2)*pi/2+0.2)+cos(x(3)*pi/2+0.3)) ;
function [c, ceq] = simple_constraint(x)
c = [];
ceq = [];
댓글 수: 0
답변 (1개)
Star Strider
2021년 8월 30일
See the documentation section on Minimize a Nonlinear Function with Integer Constraints and then set the bounds on ‘x(2)’ and ‘x(3)’ appropriately. (I have some experience with ga, however I have not used integer constraints to solve any problem.)
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!