필터 지우기
필터 지우기

How can I make the solution vary significantly?

조회 수: 5 (최근 30일)
asaii
asaii 2024년 1월 9일
댓글: Walter Roberson 2024년 1월 9일
In this code, how can I make the solution of the last generation be completely different from the solution of the first generation?
In other words, how can I make the solution vary significantly?
I do not intend to change popsize and generationsize.
ThemeCopy
x = -10:0.5:10;
f1 = (x+2).^2 - 10;
f2 = (x-2).^2 + 20;
plot(x,f1);
hold on;
plot(x,f2,'r');
grid on;
title('Plot of objectives ''(x+2)^2 - 10'' and ''(x-2)^2 + 20''');
FitnessFunction = @simple_multiobjective;
numberOfVariables = 1;
[x,fval] = gamultiobj(FitnessFunction,numberOfVariables);
'simple_multiobjective' is used in Performing a Multiobjective Optimization Using the Genetic Algorithm.

Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});

Error in gamultiobjMakeState (line 47)
Score = FitnessFcn(state.Population(toEval,:));

Error in gamultiobjsolve (line 20)
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);

Error in gamultiobj (line 342)
[x,fval,exitFlag,output,population,scores,residuals] = gamultiobjsolve(FitnessFcn,nvars, ...
size(x)
size(fval)
A = []; b = [];
Aeq = []; beq = [];
lb = -1.5;
ub = 0;
x = gamultiobj(FitnessFunction,numberOfVariables,A,b,Aeq,beq,lb,ub);
options = optimoptions(@gamultiobj,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
FitnessFunction = @(x) vectorized_multiobjective(x);
options = optimoptions(@gamultiobj,'UseVectorized',true);
gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
  댓글 수: 3
asaii
asaii 2024년 1월 9일
I'm sorry I didn't make it clear enough.
“simple_multiobjective code” is defined as follows
function y = simple_multiobjective(x)
%SIMPLE_MULTIOBJECTIVE is a simple multi-objective fitness function.
%
% The multi-objective genetic algorithm solver assumes the fitness function
% will take one input x where x is a row vector with as many elements as
% number of variables in the problem. The fitness function computes the
% value of each objective function and returns the vector value in its one
% return argument y.
% Copyright 2007 The MathWorks, Inc.
y(1) = (x+2)^2 - 10;
y(2) = (x-2)^2 + 20;
Walter Roberson
Walter Roberson 2024년 1월 9일
x = -10:0.5:10;
f1 = (x+2).^2 - 10;
f2 = (x-2).^2 + 20;
plot(x,f1);
hold on;
plot(x,f2,'r');
grid on;
title('Plot of objectives ''(x+2)^2 - 10'' and ''(x-2)^2 + 20''');
FitnessFunction = @simple_multiobjective;
numberOfVariables = 1;
[x,fval] = gamultiobj(FitnessFunction,numberOfVariables);
gamultiobj stopped because the average change in the spread of Pareto solutions is less than options.FunctionTolerance.
size(x)
ans = 1×2
18 1
size(fval)
ans = 1×2
18 2
A = []; b = [];
Aeq = []; beq = [];
lb = -1.5;
ub = 0;
x = gamultiobj(FitnessFunction,numberOfVariables,A,b,Aeq,beq,lb,ub);
gamultiobj stopped because the average change in the spread of Pareto solutions is less than options.FunctionTolerance.
options = optimoptions(@gamultiobj,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
gamultiobj stopped because it exceeded options.MaxGenerations.
FitnessFunction = @(x) vectorized_multiobjective(x);
options = optimoptions(@gamultiobj,'UseVectorized',true);
gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
'vectorized_multiobjective' is used in Performing a Multiobjective Optimization Using the Genetic Algorithm.

Error in solution>@(x)vectorized_multiobjective(x) (line 21)
FitnessFunction = @(x) vectorized_multiobjective(x);

Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});

Error in gamultiobjMakeState (line 47)
Score = FitnessFcn(state.Population(toEval,:));

Error in gamultiobjsolve (line 20)
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);

Error in gamultiobj (line 342)
[x,fval,exitFlag,output,population,scores,residuals] = gamultiobjsolve(FitnessFcn,nvars, ...
function y = simple_multiobjective(x)
%SIMPLE_MULTIOBJECTIVE is a simple multi-objective fitness function.
%
% The multi-objective genetic algorithm solver assumes the fitness function
% will take one input x where x is a row vector with as many elements as
% number of variables in the problem. The fitness function computes the
% value of each objective function and returns the vector value in its one
% return argument y.
% Copyright 2007 The MathWorks, Inc.
y(1) = (x+2)^2 - 10;
y(2) = (x-2)^2 + 20;
end

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

답변 (0개)

카테고리

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