- 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!