define nvars as a function handle in genetic algorithm
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
i am using genetic algorithm and the number of decision variables are dependent on the value of a certain decision variables (M, I, J)
so,
nvars = 2 + M*((2*J)+1)+ I*(J+1)
i used the optimization toolbox app and i copied the above function on the Number of Variables cell.
and i copied the "lb equation" and 'ub equation' on the Bounds cells.
the following is part of my code that defines decision variables, lb, and ub;
M = round(x(1))
I = round(x(2))
clear Ld_left
for m = 1:M
Ld_left(m,:)= [x(3+((m-1)*J):2+m*J)]
end
clear Ld_right
for m = 1:M
Ld_right(m,:)= [x(3+M*J+(m-1)*J : 2+ M*J + m*J)]
end
clear LF
for i= 1:I
LF(i,:)= [x(3+2*M*J+(i-1)*J : 2+2*M*J + i*J)]
end
clear P_mcr_m_Target
for m = 1:M
P_mcr_m_Target(m,:) = [x(2+m+2*M*J+I*J)]
end
clear P_mcr_i_Target
for i = 1:I
P_mcr_i_Target(i,:) = [x(2+M+i+2*M*J+I*J)]
end
%% number of variables
numberOfVariables= 2 + M*((2*J)+1)+ I*(J+1)
%% Variable bounds
%%
% Lower bound
M_mini = 1;
I_mini = 2;
Ld_left_min= zeros(1,M*J)
Ld_right_min = zeros(1,M*J)
P_mcr_m_Target_min = [500 500 500];
P_mcr_m_Target_mini = P_mcr_m_Target_min(1:M);
P_mcr_i_Target_min = [300 300 300 300];
P_mcr_i_Target_mini = P_mcr_i_Target_min(1:I);
LF_min= zeros(1,I*J)
lb = [1, 2, Ld_left_min, Ld_right_min, P_mcr_m_Target_mini , P_mcr_i_Target_mini , LF_min]
% Upper bound
M_max = 3;
I_max = 4;
Ld_left_max= ones(1,M*J);
Ld_right_max = ones(1,M*J);
P_mcr_m_Target_mx = [9000 9000 9000];
P_mcr_m_Target_max = P_mcr_m_Target_mx(1:M);
P_mcr_i_Target_mx = [5000 5000 5000 5000];
P_mcr_i_Target_max = P_mcr_i_Target_mx(1:I);
LF_max = ones(1,I*J);
ub = [3, 4, Ld_left_max, Ld_right_max, P_mcr_m_Target_max , P_mcr_i_Target_max , LF_max]
i always got this error
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
1 Kommentar
Walter Roberson
am 7 Sep. 2020
You do not indicate which line has the error, and you do not show us size() of each of the variables on that line, and you do not provide enough code or data for us to test with.
Antworten (1)
Matt J
am 7 Sep. 2020
nvars cannot evolve throughout the optimization, but conceivably your fitness function could contain optimization sub-problems as a way of calculating the ultimate fitness value. The sub-problem could have a number of unknowns that depends on the x(i) in the super-problem.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!