Info

This question is closed. Reopen it to edit or answer.

when i define my variable Simu_Hour in main file it make an infinite loop of GENETIC ALGORITHM

1 view (last 30 days)
function y=fitness(x)
p = 0;
global Simu_Hour;
for j = 1:Simu_Hour
tap=1+0.0125*x(144+j);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% CONSTRAINTS FUNCTION function [c, ceq]=constraints(x)
global Simu_Hour;
tap_num=0;c1_tap=0;c2_tap=0;c3_tap=0;c4_tap=0;c5_tap=0;c6_tap=0;
for j = 1:Simu_Hour-1
if x(144+j)~=x(145+j)
tap_num=tap_num+1 ;
else
end
%%MAIN FUNCTION % nvars = 240; global Simu_Hour;
Simu_Hour=2;
ObjectiveFunction = @fitness;
nvars = 168;
LB=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8]; UB=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]; ConstraintFunction = @constraints; X0 =[0 1 1 1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1 1 0 1 1 0 1 0 0 1 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 0 0 0 0 1 1 1 0 1 1 0 1 -3 -3 -4 0 -1 -2-1 -2 -1 -2 -1 -2 0 -3 -4 -4 -4 -2 -2 -3 -1 -1 -1 0];
opts = gaoptimset('InitialPopulation',X0, 'PopulationSize', 300, 'Generations', 600,'EliteCount', 20,'StallGenLimit' ,400,'TolFun', 1e-8,'PlotFcns',@gaplotbestf);
[x, fbest, exitflag] = ga(ObjectiveFunction, nvars, [], [], [], [],LB, UB, ConstraintFunction,1:168, opts);
display(x);

Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!