classdef DummyClass
properties
end;
properties ( Constant )
end;
methods ( Static )
function [ resultOptimum ] = optfunc( x )
resultOptimum = -( x * x' );
end;
function [ x_par ] = findOptimumGA( MaxIter, a )
objectiveFunction = @( x ) DummyClass.optfunc( x );
x0 = round( rand( 1, 20000 ) > a );
lb = zeros( size( x0 ) );
ub = ones( size( x0 ) );
opts = gaoptimset( 'TolFun', 1e-40 );
opts = gaoptimset( opts, 'PlotFcns', @gaplotbestf );
opts = gaoptimset( opts, 'Generations', MaxIter );
opts = gaoptimset( opts,'InitialPopulation', x0 );
[x_par, fval, exitflag] = ga( objectiveFunction, numel(lb), [], [], [], [], lb, ub, [], 1 : numel(lb), opts);
fprintf( 'array len: %5d\n', numel( x_par ) );
fprintf( 'result sum: %5d\n', sum( x_par ) );
fprintf( 'non-zero rate: %f\n', mean( 0 ~= x_par ) );
end;
function [ x_par ] = findOptimumSA( MaxIter, a )
objectiveFunction = @( x ) DummyClass.optfunc( x );
x0 = round( rand( 1, 20000 ) > a );
lb = zeros( size( x0 ) );
ub = ones( size( x0 ) );
options = saoptimset('MaxIter', MaxIter );
[x_par, fval, exitFlag, output] = simulannealbnd( objectiveFunction, x0, lb, ub, options);
fprintf( 'array len: %5d\n', numel( x_par ) );
fprintf( 'result sum: %5d\n', sum( x_par ) );
fprintf( 'non-zero rate: %f\n', mean( 0 ~= x_par ) );
end;
end;
end