- Write your function as an objective function. I won't do that for you, but just start at the beginning and write it.
- Set up any constraints.
- Call GA.
How can I use the Genetic Algorithm (GA) to minimize a cost function of two variables C(T,K) where T is a real an K an integer.
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Réponse acceptée
John D'Errico
le 20 Jan 2023
Trivial.
And while you may think of it as a 2 variable problem, you have only ONE variable, a vector of length 2. One of those variables is constrained to be integer.
For example:
a = 1.25;
b = 100;
obj = @(xy) (a - xy(1)).^2 + b*(-1/8 + xy(1)-(xy(2)/10).^2).^2;
This is just effectively the Rosenbrock function, with a tweak or two in there. I'll constrain y to be an integer.
intcon = 2 % So only y is constrained to be integer
lb = [-20,-20];
ub = [20 20];
[xysol,fval,exitflag] = ga(obj,2,[],[],[],[],lb,ub,[],intcon)
fsurf(@(x,y) obj([x,y]),[0 2 8 13])
0 commentaires
Plus de réponses (0)
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!