Matlab comes with the Genetic algorithm Toolbox is gads, input help GA can see the use of GA, GA function The most complete format is [X,fval,exitflag,output,population,scores]=ga (FITNESSFCN , nvars,a,b,aeq,beq,lb,ub,nonlcon,options),
y=100* (x1^2-x2) ^2 + (1-X2) ^2 maximum value, X1 and X2 are within the range [ -2.048,2.048]:
>> [x,val,flag,output,population,scores]=ga(@(x)-100*(x(1)^2-x(2))^2-(1-x(1))^2, 2, [],[],[],[],[-2.048, -2.048], [2.048, 2.048])
Optimization terminated: average change in the fitness value less than options.TolFun.
x =
2.0480 -2.0466
val =
-3.8960e+03
flag =
1
output =
problemtype: 'boundconstraints'
rngstate: [1x1 struct]
generations: 51
funccount: 1040
message: [1x86 char]
maxconstraint: 0
population =
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0434
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0466
2.0480 -2.0427
2.0441 -2.0463
2.0480 -2.0466
2.0475 -2.0427
scores =
1.0e+03 *
-3.8960
-3.8960
-3.8960
-3.8960
-3.8960
-3.8960
-3.8960
-3.8918
-3.8959
-3.8960
-3.8960
-3.8960
-3.8959
-3.8960
-3.8959
-3.8960
-3.8911
-3.8757
-3.8959
-3.8883
In addition, input GA can be manipulated directly on the graphical interface.