필터 지우기
필터 지우기

How can I modify the FitnessFunction when doing optimization?

조회 수: 1 (최근 30일)
Tanvir Kaisar
Tanvir Kaisar 2017년 3월 21일
댓글: Tanvir Kaisar 2017년 3월 21일
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
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
Tanvir Kaisar
Tanvir Kaisar 2017년 3월 21일
Thanks for your comment... I am sorry that I have not mentioned that the objective function has constraints and bounded. I have to optimize it 100 times (with changing r values)..I am guessing I may have to use some kind of loop...but i dont know how should i approach

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
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.

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by