Clear Filters
Clear Filters

How can I make the solution vary significantly?

1 view (last 30 days)
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 Comments
asaii
asaii on 9 Jan 2024
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 on 9 Jan 2024
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

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!