Put weight sum in Genetic algorithm

13 ビュー (過去 30 日間)
Rendra Hakim hafyan
Rendra Hakim hafyan 2019 年 4 月 16 日
コメント済み: Walter Roberson 2020 年 3 月 8 日
Dear All,
I just made a coding of combination between weighted sum and genetic algorithm. But, I can't converge it
would you like to correct my coding?
function f = objfun(x,w1,w2);
%Defining mu1 and mu2
f1 = -(-4457.267829 + 55.8942295*x(1) + 5973.4177215*x(2));
f2 = 24.33773251 + 0.3871253086*x(1) + x(1)^2*-0.002159815;
%Defining the AOF
f = f1*w1 + f2*w2;
%Lower and upper bounds
LB = [25 0.7];
UB = [75 0.8];
nvars =2;
% Optimize with gamultiobj
options = optimoptions('gamultiobj','Display','iter',...
'MaxGeneration',200,...
'PopulationSize',100,...
'CrossoverFraction',0.8,...
'MigrationFraction',0.01,...
'PlotFcn',@gaplotpareto);
%Initialize counter j
j = 1;
%for loop that changes the weights. Each iteration of the for loop produces
%one Pareto Point
for i = 0.1:0.5:1
%Assigning weights
w1 = i;
w2 = 1-i;
%Calling fmincon and passing weights to objfun and confun
[x,fval] = gamultiobj(@objfun, nvars, [],[],[],[],LB,UB,w1,w2,options);
%finding objective function values
solx(j) = -(-4457.267829 + 55.8942295*x(1) + 5973.4177215*x(2));
soly(j)=24.33773251 + 0.3871253086*x(1) + x(1)^2*-0.002159815;
%Incrementing the counter
j = j+1;
end
%Plotting the Pareto frontier
plot(solx,soly,'*')
xlabel('objective 1')
ylabel('objective 2')

回答 (4 件)

Alan Weiss
Alan Weiss 2019 年 4 月 16 日
You seem to be mixing up solving a multiobjective problem by using gamultiobj once and solving it by using fmincon repeatedly.
First you need to define your objective functions as a single file taking ONE argument, not three:
function f = objfun(x);
f(1) = -(-4457.267829 + 55.8942295*x(1) + 5973.4177215*x(2));
f(2) = 24.33773251 + 0.3871253086*x(1) + x(1)^2*-0.002159815;
Then the following should work:
LB = [25 0.7];
UB = [75 0.8];
nvars =2;
% Optimize with gamultiobj
options = optimoptions('gamultiobj','Display','iter',...
'MaxGeneration',200,...
'PopulationSize',100,...
'CrossoverFraction',0.8,...
'PlotFcn',@gaplotpareto);
[x,fval] = gamultiobj(@objfun,nvars, [],[],[],[],LB,UB,[],options);
Alan Weiss
MATLAB mathematical toolbox documentation

Rendra Hakim hafyan
Rendra Hakim hafyan 2019 年 4 月 17 日
Is it possible to combine weighted sum method with gamultiobj?
to be frank, I try to solve it with fmincon to know whether it can be solved or not.
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 4 月 17 日
fmincon cannot handle multiple objectives.
Your second equation defines a quadratic. That has a single extrema point. Differentiate on x1 and solve on x1. The result is about 89, which is outside of the bounds. Therefore the minima will be either at the upper bound or the lower bound. A quick test shows the minima is at the lower bound for x1.
Now examine the first equation. -(-Constant + something*x1 + something*x2) . The minima of that will be at the maxima of -Constant + something*x1 + something*x2 . Since the coefficient associated with x1 is positive. and the bounds are positive, the maxima will be when x1 is at its upper bound. Since the coefficient associated with x2 is positive and the bounds are positive, the maximum will be when x2 is at its upper bound. So the minima of the negative of that will be at upper bounds of x1 and x2.
So you have two equations, one of which does not care about x2 and is minimized when x1 is lowest, and the other of which is minimized when x1 and x2 are maxima.
And.. now what? You have equations that cannot both be simultaneously maximized. The locations to chose therefore depends upon how you want to weight the importance of solving the two equations. fmincon cannot solve that because there is no meaningful solution without a choice of weights.
You happen to have weights. Out of the weights you can construct a single equation, and minimize the single value.

サインインしてコメントする。


Manh Do Van
Manh Do Van 2020 年 1 月 1 日
Thank you so much Prof.Walter Roberson. However, the Rendra Hakim hafyan's question is " Is it possible to combine weighted sum method with gamultiobj? " I have the same idea, but I think there are two methods " weighted sum method and multiple GA" to solve the multi-optimization problems. Could some one have the same research answer for the question:
Is it possible to combine weighted sum method with gamultiobj? "
Regards,
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 1 月 1 日
You can do like the original poster did in calculating
f = f1*w1 + f2*w2;
Provided that f1, f2, w1, w2 are all scalar (which they are in the user code), that defines a single objective that is a weighted sum. gamultiobj() does not care how many temporary variables you use in creating that single value from the inputs.
If you only have a single output, such as the f = f1*w1 + f2*w2 output, then there is probably no benefit to using gamultiobj: you might as well use ga()
It is not of any special interest to ask whether gamultiobj can be used with weighted sums when the user does the weighting themselves -- it is about like asking whether gamultiobj can be used when expressions are added . gamultiobj does not care what the calculation is, just that it returns an output.
It is only of special interest to ask whether gamultiobj can be used with weighted sums if your question is really about whether you can create separate objectives and tell gamultiobj what the weighting is between them is to be, instead of doing the weighting calculation yourself and returning the weighted value.
The answer to that is NO, gamultiobj() does not permit you to specify a weight vector or function; see https://www.mathworks.com/help/gads/gamultiobj.html#bvf79ug-options for the options.
Specifying a weight vector to calculate a single fitness is not compatible with the operation of gamultiobj(), which is intended to find Pareto Fronts.
If you want fitness by weighting objectives, return the already-weighted fitness value (and probably use ga())

サインインしてコメントする。


Manh Do Van
Manh Do Van 2020 年 1 月 1 日
Thank you for your trouble Prof.Walter Roberson,
Regards,
  2 件のコメント
gullnaz shahzadi
gullnaz shahzadi 2020 年 3 月 6 日
Can you please explain how can we define weights? I saw different methods to calculate weights but for any specific function, how can we get a specific weight? Let suppose I have three objective functions defind on same domain, I am just taking the average of all functions and trying to minimize the average, which seems not good. Can anyone please guide me that how should we define the weights in this situation? what will be the best approach? or how can I applu gamultiobjective of matlab for three objective functions?
thank you,
Walter Roberson
Walter Roberson 2020 年 3 月 8 日
There is no single best approach. You should be weighting them according to the relative importance that each one is minimized, which is something you need to decide based upon extra information you have available outside of the equations.
See the case I discussed above, https://www.mathworks.com/matlabcentral/answers/456596-put-weight-sum-in-genetic-algorithm#comment_694947 in which one equation pushes x2 to be minimum and the other pushes x2 to be maximum. There is no way to know, just looking at the equations, which is the "best" choice.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by