function [pop_natural,pop_costs] = pareto_GA( wfn, bounds, popsize, selection, mutrate, maxit ) % PARETO_GA - Implements a pareto genetic algorithm for multiple objective minimization (MOO) for *two* functions only % % Inputs: % wfn = a function handle accepting a double vector input and returning two columns of scalar output representing f_1 and f_2 function to minimize % bounds = [ number_of_variables x 2 ] input matrix where the ith row is the valid bounds for the ith variable % % Outputs: % x_bin = [ number_of_samples x npar ] pareto encoding of each variable in x % % Written by: % -- % John L. Weatherwax 2006-08-28 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- % Parse the parameters of the genetic algorithm (if not provided defaults are used) % if( nargin < 3 ) popsize = 100; % the population size end if( nargin < 4 ) selection = 0.5; % selection rate end if( nargin < 5 ) mutrate = 0.02; % the mutation rate end if( nargin < 6 ) maxit = 20; end % Check inputs: npar = size(bounds,1); assert( size(bounds,2)==2, 'bounds input must have two columns' ); keep = floor( selection * popsize ); M = ceil( (popsize-keep)/2 ); % the number of matings odds = 1; for ii=2:keep, odds = [odds ii*ones(1,ii)]; end odds = keep+1-odds; Nodds = length(odds); % _________________________________________________________________________ % Create the initial population % iga = 0; % generation counter initialized pop = rand(popsize,npar); % random population of normalized continious variables pop_natural = var_decode(pop,bounds); % Decode normalized variables into natural variables (the variables from the problem definition) fout = wfn( pop_natural ); % Find cost for each variable % % _________________________________________________________________________ while igakeep; break; end; if row(ic)>rowmut(iq) iq=iq+1; rowmut(ic)=row(ic); end end if rowmut(1)==0; rowmut=rowmut(2:length(rowmut)); end; fout(rowmut,:) = wfn( var_decode(pop(rowmut,:),bounds) ); fout(keep+1:popsize,:) = wfn( var_decode(pop(keep+1:popsize,:),bounds) ); % _________________________________________________________________________ % Stopping criteria if iga>maxit break; end %disp('the optimal solution at this timestep') %[iga cost(1) fout(1,:)] end % iga pop_natural = var_decode(pop,bounds); pop_costs = wfn( pop_natural );