Ho to Constraint GA to Generate Population Within Design Space

조회 수: 4 (최근 30일)
Mirhan
Mirhan 2025년 4월 10일
편집: Matt J 2025년 4월 10일
Dear all,
I’m currently working on a genetic algorithm-based optimization and would like to constrain the GA to select design variables strictly within a predefined design space.
While I can set upper and lower bounds for the variables, my design space is more complex, and I’m working with a large population. I’m wondering if there’s a way to configure the GA so that it generates the populations entirely within the valid design space, rather than just filtering or penalizing out-of-bounds individuals afterward.
Attached is a simple sketch illustrating the shape of my design space.
Thanks in advance for your guidance!
Best regards,
Mirhan

채택된 답변

Matt J
Matt J 2025년 4월 10일
편집: Matt J 2025년 4월 10일
Yes, you can reparametrize the design vector x as,
x=t1*v1+t2*v2
where v1 and v2 are the direction vectors of the two rays bounding your cone,
v1=[cosd(150),sind(150)]
v2=[cosd(30), sind(30)]
The new design variables are t=[t1,t2], which only need simple positivity constraints to confine x to the cone.
  댓글 수: 2
Mirhan
Mirhan 2025년 4월 10일
Thank you very much for your quick and helpful response!
I was wondering—how can I implement this into a classical genetic algorithm? I'm not quite sure where exactly this type of constraint should be defined within the algorithm.
Thank you again!
Best regards,
Mirhan
LB = [0 0 0];
UB = [10 10 10];
%% Optimization Options
PopulationSize = 50*nvars;
Generations = 50;
% Set GA options
options = optimoptions( 'ga',...
'Display', 'iter',...
'TolFun', 1e-9,...
'TolCon', 1e-3,...
'PlotFcn',{@gaplotbestf,@gaplotdistance});
ObjectiveFunction = @(x) simple_objective (x);
% Run Genetic Algorithm
[x_opt, fval_opt] = ga(ObjectiveFunction, nvars, [], [], [], [], LB, UB, [], options);
Matt J
Matt J 2025년 4월 10일
편집: Matt J 2025년 4월 10일
The code from your last comment is for a 3D problem, whereas your diagram was for a 2D problem. I will continue to assume the 2D problem whose design space is a cone at 30 degrees to the x-axis.
You need to reparametrize your fitness function in terms of t,
xoft=@(t) t(1)*v(1)+t(2)*v(2);
ObjectiveFunction = @(t) simple_objective( xoft(t));
% Run Genetic Algorithm
[t_opt, fval_opt] = ga(ObjectiveFunction, 2, [], [], [], [], [0,0], [], [], options);
x_opt = xoft(t_opt)

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

추가 답변 (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