How can I modify the FitnessFunction when doing optimization?
조회 수: 1 (최근 30일)
이전 댓글 표시
Say my problem is to maximize y= r*x(1)+(x(2))^2 using Genetic Algorithm (with constraints). But my assignment is to do this optimization 100 times with r=1:100.So after the 1st result r will change 1 to 2, then another result and so on.. How can i do this in the most efficient way?
댓글 수: 2
Alan Weiss
2017년 3월 21일
I think that the most efficient way is to write down the solution without using the genetic algorithm. If you really want to maximize that function on an unbounded domain then the answer is infinity. If you have a bounded domain, well, it is again easy to calculate. And if you really have a minimization problem, then again it is easy to calculate the optimum. Have the genetic algorithm find the value of a function that always returns 0, and add it to the calculated solution.
If you meant something else, then please explain what you really want.
Alan Weiss
MATLAB mathematical toolbox documentation
답변 (1개)
John D'Errico
2017년 3월 21일
편집: John D'Errico
2017년 3월 21일
Easy enough.
You could simply create the objective function inside a loops, as such...
for r = 1:100
fun = @(x) r*x(1)+(x(2))^2;
% do optimization here:
...
end
Each time through the loop, the current value of r was used to create the objective function, overwriting the function handle with a new one.
Or, I might have written it like this.
fun = @(x,r) r*x(1)+(x(2))^2;
for r = 1:100
fr = @(x) fun(x,r);
% do optimization here:
...
end
In the second form, I create a two variable function, then inside the loop, I create a second function that calls the first, but with a fixed value of r, set at the current value.
Be careful, as your objective is to maximize. Most optimizers in MATLAB are MINIMIZATION tools. You can convert a maximization problem into a minimization problem by negating the objective function.
댓글 수: 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!