i trying solve problem using ga in matlab , optimization running through set number of generations , decreasing function value expected ( seen in figure below). not expected is not plotting percent criteria of generation me, instance in figure below should under 40% done, not.
here code:
intcon=[]; % set integer variables vfun=@(x)objective(x, univ_names, univ_data, weight_names, weight_data, net_names, net_data, normalized_name, normalized_data); nonlcon=@(x)constraint(x,net_names, net_data); pop = 40; gen =50; ini=rand(pop,nvars); time = inf; % time in (s) options = gaoptimset('timelimit', time, 'initialpopulation',ini,'populationsize',pop,'generations',gen,'plotfcns',{@gaplotbestfun, @gaplotstopping}); [x,fval,exitflag,output] = ga(vfun,nvars,[],[],[],[],x_l,x_u,nonlcon,intcon,options)
then, if let continue, starts on @ beginning ( @ worse function value) , @ point starts think it has met percentage of termination criteria number of generations
then after letting complete, get: and
optimization terminated: average change in fitness value less options.tolfun , constraint violation less options.tolcon. x =3.3242 1.8450 0.5918 0.6000 fval = 3.5208e+03 exitflag = 1 output = problemtype: 'nonlinearconstr' rngstate: [1x1 struct] generations: 3 funccount: 6160 message: [1x140 char] maxconstraint: 0
so, somehow picked worse function value found in first run! why doing "second" , "third run"?
in example, include iteration information , obvious not including best function value 1 generation next. instance on graph shown after 50 generations reduces function value 425 seen in bottom set of triangles on graph below:
but think min 435.011? , these 50 generations one. seen below: generation f-count f(x) constraint generations 1 1060 435.011 0 0 2 2100 434.396 0 0 3 3140 434.267 0 0
but, output in matlab terminal thinks that after 50 generations on graph 1 generation , prints screen
then after optiization terminated looks like:
any ideas? thanks!
the issue matlab's implementation of genetic algorithm non-linear constraint cannot handle design problem if there no integer variables! changed 1 of may variables integer variable as
intcon=[1]; % set integer variables
then ran same scripts , functions
optimization terminated: maximum number of generations exceeded.
x =
3.0000 1.6261 0.5881 0.6002
fval =
3.5410e+03
exitflag =
0
output =
problemtype: 'integerconstraints' rngstate: [1x1 struct] generations: 50 funccount: 2041 message: 'optimization terminated: maximum number of generations exceeded.' maxconstraint: 0