How to set up variable with only several states in the genetic algorithm
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 30 Aug 2021
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 Comments
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!