% DE3GriewangkND.m
% Script to test the use of DE for the n-dimensional Griewangk function.
% Minimization using differential evolution of R. Storn.
% R. Storn, "Diferential Evolution - A Simple and Efficient Heuristic
% Strategy for Global Optimization over Continuous Spaces",
% J. Global Optimization, vol. 11, p.341-359 (1997).
% The present Matlab program is based on the one by Rainer Storn
% (http://www.icsi.berkeley.edu/~storn/code.htm), which was
% improved by Ken Price, Arnold Neumaier and Jim Van Zandt
% The present program:
% (1) constructs the trial vectors more efficiently
% (2) makes the program loopless except for the main iteration loop:
% key point: operate on the entire population in "parallel"
% (3) requires only one copy of the population
% (4) uses identifier names that reflect the matrix nature of the variables
% (5) implements only scheme: DE/rand/1/bin for constructing trial vectors
% K. Ming Leung, 10/06/03, 10/23/03

clear all;
time = cputime;
fcn = 'GriewangkND';
n = 10;
Xmax = 400*ones(n,1);
Xmin = -Xmax;
f = 0.5; c = 0.25; np = 20; % good convergence for n=10 (nfe=14000)
tol = 1e-12; % tolerance in solution norm or function value
itMax = 20000; % maximum number of generations

[Bestmem,bestval,nfe,DATA] = DE33F(fcn,Xmin,Xmax,f,c,np,tol,itMax);
fprintf('Best vector = [\n');
fprintf(' %20.16f\n', Bestmem);
fprintf(' ]\n');
fprintf('Best function value = %10.4g\n', bestval);
fprintf('Number of function evaluations = %4d\n', nfe);

runtime = cputime - time,

semilogy(DATA(:,1),DATA(:,2),'LineWidth',1.5);
xlabel('Iteration','FontSize',16,'FontWeight','bold');
ylabel('Function Value','FontSize',16,'FontWeight','bold');