- 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 次查看(过去 30 天)
显示 更早的评论
采纳的回答
John D'Errico
2023-1-20
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!