- 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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
0 Commenti
Risposta accettata
John D'Errico
il 20 Gen 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!