Ho to Constraint GA to Generate Population Within Design Space

5 ビュー (過去 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 Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by