How to set up variable with only several states in the genetic algorithm

1 vue (au cours des 30 derniers jours)
Ole
Ole le 30 Août 2021
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 = [];

Réponses (1)

Star Strider
Star Strider le 30 Août 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.)
.

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by