How to set up variable with only several states in the genetic algorithm
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Star Strider
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!