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