Examples for the usage of the Matlab interface

This commit is contained in:
Marcel Kronfeld 2011-02-01 14:38:08 +00:00
parent 881dc85159
commit 0b963d7907
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,31 @@
clear all
clear classes
% adapt the path settings!
addpath '/home/mkron/workspace/JE2Base/resources/MatlabInterface'
javaaddpath '/home/mkron/workspace/JE2Base/build'
addpath 'C:\Dokumente und Einstellungen\mkron\workspace\JE2Base\resources\MatlabInterface'
javaaddpath 'C:\Dokumente und Einstellungen\mkron\workspace\JE2Base\build'
% real valued case
R=[-5 -5 -5; 5 5 5];
JI=JEInterface(@testfun, 'double', R, R, 1, 'Display', 'iter', 'TolX', 0, 'TolFun', 0);
JI=optimize(JI, 4);
[sol, solFit]=getResult(JI);
finalPop=getMultipleResults(JI);
% binary case
R=20;
JI=JEInterface(@testfun, 'binary', R, R, 4, 'Display', 'iter');
JI=optimize(JI, 3);
[sol, fit]=getResult(JI);
finalPop=getMultipleResults(JI);
% integer case with specific initialization range
initR=[-15 -15 -15 -15 -15; -5 -5 -5 -5 -5];
R=[-15 -15 -15 -15 -15; 15 15 15 15 15];
JI=JEInterface(@testfun, 'int', R, initR, 5, 'Display', 'iter');
JI=optimize(JI, 3);
[sol, fit]=getResult(JI);
finalPop=getMultipleResults(JI);

View File

@ -0,0 +1,16 @@
function z = testfun(x, y)
switch y
case 1 % modulated parabola
z (1)=sum(x.*x)+cos ( x ( 1 ) ) * sin ( x ( 2 ) ) ;
case 2 % Branin
z ( 1 ) = ( x(2)-(5/(4*pi ^2))* x(1)^2+5*x (1)/ pi -6)^2+10*(1-1/(8* pi ) )* cos ( x (1) )+10;
case 3 % Himmelblau
z ( 1 ) = ( ( x (1)^2 + x ( 2 ) - 11)^2 + ( x ( 1 ) + x (2)^2 - 7 )^2 ) ;
case 4 % simple binary: changed to a char data type
z(1)=0;
for i=1:length(x)
if (x(i)=='1') ; z(1)=z(1)+1; end
end
case 5 % simple parabola
z (1)=sum( x .* x ) ;
end