How to make the initial population in genetic algorithm fixed?
Show older comments
Hello,
i am currently using genetic algorithm to optimize some variables for a problem, i know that there is creation function that creates random initial population, but how to stop creating random initial population? i want to compare the results of each time i run the algorithm with each other, and i cant compare between them if the initial population is different.
% Create optimization variables
Cf17 = optimvar("Cf","LowerBound",1e-9,"UpperBound",1e-2);
Lc15 = optimvar("Lc","LowerBound",1e-9,"UpperBound",1e-2);
Lf16 = optimvar("Lf","LowerBound",1e-9,"UpperBound",1e-2);
Cc14 = optimvar("Cc","LowerBound",1e-9,"UpperBound",1e-2);
f17 = optimvar("f","LowerBound",1e3,"UpperBound",15e4);
% Set initial starting point for the solver
initialPoint16.Cf = repmat(1e-9,size(Cf17));
initialPoint16.Lc = repmat(1e-9,size(Lc15));
initialPoint16.Lf = repmat(1e-9,size(Lf16));
initialPoint16.Cc = repmat(1e-9,size(Cc14));
initialPoint16.f = repmat(1e3,size(f17));
% Create problem
problem = optimproblem;
% Define problem objective
problem.Objective = fcn2optimexpr(@objectiveFcn,Lc15,Cc14,Lf16,Cf17,f17);
% Define problem constraints
problem.Constraints = constraintFcn(Cf17,f17);
% Set nondefault solver options
options8 = optimoptions("ga","ConstraintTolerance",1e-06,"Display","iter",...
"MaxGenerations",10,"PopulationSize",10,"SelectionFcn",...
"selectionroulette","PlotFcn","gaplotbestf");
% Display problem information
show(problem);
% Solve problem
[solution,objectiveValue] = solve(problem,initialPoint16,"Solver","ga",...
"Options",options8);
% Clear variables
clearvars Cf17 Lc15 Lf16 Cc14 f17 initialPoint16 options8
function objective = objectiveFcn(Lc,Cc,Lf,Cf,f)
Vo=500;
R=6;
DutyC=0.76;
s=tf('s');
dp = 1-DutyC;
w1 = -Lc;
w2 = dp*R;
u1 = Lc*Cc*R;
u2 = Lc;
u3 = (dp^2)*R;
x1 = Lf*Cf*(Lc^2)*dp*R*Cc;
x2 = ((Lf+(Lc*dp*R)-((dp^2)*R*Lf*Cf))*Lc*Cc)+((Lc^2)*Lf*Cf*dp*R);
x3 = ((Lf+(Lc*dp*R)-((dp^2)*R*Lf*Cf))*Lc)+(Lf*Cf*Lc*(dp^3)*(R^2));
x4 = ((Lf+(Lc*dp*R)-((dp^2)*R*Lf*Cf))*(dp^2)*R)-((dp^2)*R*Lc);
x5 = -((dp^4)*(R^2));
y1 = Lc*Cc*Lf*Cf;
y2 = (Lc*Cc) + (Lc*Lf*Cf);
y3 = Lc+Lf+(Lf*Cf*(dp^2)*R);
y4 = R*(dp^2);
Gvd = (Vo/dp)*((s*w1+w2)/((s^2)*u1+(s*u2)+u3))*((((s^4)*x1)+((s^3)*x2)+((s^2)*x3)+(s*x4)+x5)/(((s^3)*y1)+((s^2)*y2)+(s*y3)+y4));
w = 1.542362224647084e+04;
H = freqresp(Gvd,w);
objective = -20*log(abs(H));
end
function constraints = constraintFcn(Cf,f)
V_Ripple = 14.2857;
d = 0.76;
Vo=500;
R=6;
constraints(1) = Cf - (d*Vo)/(2*f*R*V_Ripple)==0;
end
Accepted Answer
More Answers (0)
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
