GA Optimization - supplying different constraints depending on loop cycle

6 visualizaciones (últimos 30 días)
Daniel K
Daniel K el 24 de Feb. de 2021
Editada: Daniel K el 24 de Feb. de 2021
Hello everyone,
I am trying to minimize my fitness function with the genetic algorithm. I have already set linear inequality constraints via the matrices A und b which are working fine (x0(1) < x0(2), x0(2) < x0(3), ....).
Now I want to add constraints so that the values computed for the fitness function don't get too high - speed should be <= 20 and range <= 10. Basically my code looks like as in the following:
function [out] = Optimization(x0)
variabel_Vektor = [x0(1) x0(2) x0(3) x0(4) x0(5) x0(6) x0(7) x0(8) x0(9)];
loop_1 = [4 3 2 1];
loop_2 = 1.0:-0.1:0.2; % length(1.0:-0.1:0.2) = 9, so x0 goes up to x0(9)
for S_1 = 1:length(loop_1)
for S_2 = 1:length(loop_2)
% various calculations follow here
% [.........]
if distance >= 0
range(S_1,S_2) = s_T - [(s_T - x0(S_2) - l - d) + s_B];
else range(S_1,S_2) = 0;
end
if distance < 0
speed(S_1,S_2) = sqrt(v0^2 - 2*loop_1(S_1)*g*[s_T-(s_T-x0(S_2)-l-d)]);
else speed(S_1,S_2) = 0;
end
end
end
% fitness function
out = sum(speed(:))+sum(range(:));
The constraints I want to add are the following:
% constraints for speed: each <= 20:
sqrt(v0^2 - 2*loop_1(S_1)*g*[s_T-(s_T-x0(S_2)-l-d)]) - 20 <= 0
% constraints for range: each <= 10:
s_T - [(s_T - x0(S_2) - l - d) + s_B] - 10 <= 0
For speed, I get a nonlinear inequality constraint and for range a linear inequality constraint. I don't know how to pass these constraints to matlab because in the expressions there is a dependency on the respective loop pass (S_2 for x0 and S_1).
Does anyone have an idea? I would really appreciate it! Thanks a lot.

Respuestas (0)

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by