is it possible to use cell array to define Lb and Ub of genetic algorithm in Optimization Toolbox

1 vue (au cours des 30 derniers jours)
i am creating a code to minimize a function using genetic algorithm where i have 2 decision variables x15 and x16.
x15 is a 2x6 vector, x16 is 1x6 vector.
next code is my file for variables defininsion
function Variables(x15, x16)
% Declaration of global variables
global x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18
%% Input Data
x1 = 6; % j
x2 = 2; % m
x3 = 1; % i
x4= 2880; %P_G "6L34DF"
x5 = [0, 0, 1204, 2147, 1761, 5100];% P_Prop
x6 = [250, 600, 1500, 450, 450, 450]; % P_EL
x7= [2847, 1533, 197, 2267, 1478, 438]; % T
x8= 2919.786477; % u
x9= -6490.928826; % v
x10= 10952.80516; % w
x11 = 4400; % 8V31DF P_SMCR
x12 = 1128.256228;% a
x13 = -1940.085409; % b
x14 = 7938.533808; % c
%% Decision Variables
x15 = zeros(x2,x1);
x16 = zeros(x3, x1);
%% Dependent Variables
x17 = x12 .* x15.^2 + x13 .* x15+ x14; % SFOC_ME
x18 = x8 .* x16.^2 + x9 .* x16 + x10 ; % SFOC_G
end
and this is my File for ObjectiveFunction (Fittness Function)
function y = ObjectiveFunction(x15, x16)
% Declaration of global variables
global y x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18
%% Objective Function
y = 2*(((x11' .* x15) .* x17) * x7') +((x4'.* x16) .* x18) * x7'; % TFC
end
and i have inserted Lower and Ubber Bound into the optimization toolbox as follows
lb = {{zeros(2,6)}, {zeros(1,6)}};
ub = {{ones(2,6)}, {ones(1,6)}};
nvar = 2
in addition, i refere to the next constraints file
function [c,ceq] = NonLinearConstraints
%% Declaration of global variables
global x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18
%%
for J = 1:x1
c = zeros(1,2*x1)
c(J) = x5(J) - x11 * x15(J)
c(J+x1) = x6(J) - x4 * x16(J)
end
ceq = [];
end
i have got this message
Error running optimization.
GA requires the following inputs to be of data type double: 'lb','ub'.
my question is, if this data type is not accepted by the ga, what is the code i should use to define lb and ub for a vector decision varialbe not a scaler variable as usual?
my second question is, does my code allow the algorithm to see the decison variables among other variables or not?
Thank you in advance :)

Réponses (1)

Ameer Hamza
Ameer Hamza le 30 Mai 2020
Modifié(e) : Ameer Hamza le 30 Mai 2020
Define lb and ub as simple vectors. For example
nvars = 18;
lb = zeros(1, nvars);
ub = ones(1, nvars)
Also you need to pass nvars=18, not nvars=2 to the ga().
  2 commentaires
Nourhan Elsayed
Nourhan Elsayed le 30 Mai 2020
thank you Ameer for your answer
if nvars = 18, does it mean that the algorithm is going to change all the 18 variables. i think yes. but i dont want the algorithm to change all the 18 variables, just x15 and x16.
Ameer Hamza
Ameer Hamza le 30 Mai 2020
Ok. In that case, use nvars=2 and just define lb and ub to be [0 0] and [1 1].
Can you show how you are calling ga() with the function in your question? It will help in understanding if there is an issue in writing the commands.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by