plotobjective(@shufcn,[-2 2; -2 2]);
FitnessFunction = @shufcn;
numberOfVariables = 2;
rng default % For reproducibility
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables);
fprintf('The number of generations was : %d', Output.generations);
fprintf('The number of function evaluations was : %d', Output.funccount);
fprintf('The best function value found was : %g', Fval);
opts = optimoptions(@ga,'PlotFcn',{@gaplotbestf,@gaplotstopping});
[x,Fval,exitFlag,Output] = ...
ga(FitnessFunction,numberOfVariables,[],[],[],[],[],[],[],opts);
opts.PopulationSize = 10;
Population = rand(3,2)
opts.InitialPopulationRange = [-1 0; 1 2];
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables,[],[],[], ...
[],[],[],[],opts);
fprintf('The number of generations was : %d', Output.generations);
fprintf('The number of function evaluations was : %d', Output.funccount);
fprintf('The best function value found was : %g', Fval);
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables);
fprintf('The best function value found was : %g', Fval);
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables);
fprintf('The best function value found was : %g', Fval);
thestate = rng;
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables);
fprintf('The best function value found was : %g', Fval);
rng(thestate);
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables);
fprintf('The best function value found was : %g', Fval);
strm = RandStream.getGlobalStream;
strm.State = Output.rngstate.State;
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables);
fprintf('The best function value found was : %g', Fval);
opts = optimoptions(opts,'MaxGenerations',150,'MaxStallGenerations', 100);
[x,Fval,exitFlag,Output] = ga(FitnessFunction,numberOfVariables,[],[],[], ...
[],[],[],[],opts);
fprintf('The number of generations was : %d', Output.generations);
fprintf('The number of function evaluations was : %d', Output.funccount);
fprintf('The best function value found was : %g', Fval);
opts = optimoptions(@ga,'SelectionFcn',@selectiontournament, ...
'FitnessScalingFcn',@fitscalingprop);
评论0