How to set up variable with only several states in the genetic algorithm
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
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.)
.
0 commentaires
Voir également
Catégories
En savoir plus sur Genetic Algorithm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!