% DE3RosenbrockND.m
% Script to run DE33F for minimizing the n-dimensional 
% Rosenbrock function 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
% Required functions: DE33F, RosenbracknDF.
% K. Ming Leung, 10/03/03

clear all; time = cputime;
fcn = 'RosenbrocknDF';  % compute the n-dimensional Rosenberg function
n = 10;                 % take 10 parameters
Xmax = 40*ones(n,1);    % specify range to create initial population
Xmin = -Xmax;
% parameters of DE: (must be adjusted for a given problem)
f = 0.85; c = 0.95; np = 20;  % good convergence for n=10 (nfe=33000)
%f = 0.85; c = 0.95; np = 20;  % good convergence for n=10 (nfe=33000)

vecTol = 1e-11; itMax = 3000;                           
[bestmem,bestval,nfe,data] = DE33F(fcn,Xmin,Xmax,f,c,np,vecTol,itMax);
fprintf('Best vector = [');
fprintf('%7.4f;', 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');

