Multi-criterial example for the Matlab interface

This commit is contained in:
Marcel Kronfeld 2011-02-16 12:47:15 +00:00
parent 749c75fe2a
commit 489e0a6f3f
4 changed files with 54 additions and 30 deletions

View File

@ -3,29 +3,37 @@
% URL: http://www.ra.cs.uni-tuebingen.de/software/EvA2/ % URL: http://www.ra.cs.uni-tuebingen.de/software/EvA2/
% adapt the path settings! % adapt the path settings!
addpath '/home/user/workspace/MatlabInterface' % .. directory containing @JEInterface addpath '/home/user/workspace/MatlabInterface' % .. directory containing @JEInterface
javaaddpath '/home/user/workspace/EvA2Base.jar' % .. the EvA2 base package javaaddpath '/home/user/workspace/EvA2Base.jar' % .. the EvA2 base package
% addpath 'C:\Dokumente und Einstellungen\user\workspace\MatlabInterface' % Windows will look differently % addpath 'C:\Dokumente und Einstellungen\user\workspace\MatlabInterface' % Windows will look differently
% javaaddpath 'C:\Dokumente und Einstellungen\user\workspace\EvA2Base.jar' % Windows will look differently % javaaddpath 'C:\Dokumente und Einstellungen\user\workspace\EvA2Base.jar' % Windows will look differently
% real valued case % real valued case
R=[-5 -5 -5; 5 5 5]; R=[-5 -5 -5; 5 5 5];
JI=JEInterface(@testfun, 'double', R, R, 1, 'Display', 'iter', 'TolX', 0, 'TolFun', 0); JI=JEInterface(@testfun, 'double', R, R, 1, 'Display', 'iter', 'TolX', 0, 'TolFun', 0);
JI=optimize(JI, 4); JI=optimize(JI, 4);
[sol, solFit]=getResult(JI); [sol, solFit]=getResult(JI);
finalPop=getMultipleResults(JI); finalPop=getMultipleResults(JI);
% binary case % binary case
R=20; R=30;
JI=JEInterface(@testfun, 'binary', R, R, 4, 'Display', 'iter'); JI=JEInterface(@testfun, 'binary', R, R, 4, 'Display', 'iter');
JI=optimize(JI, 3); JI=setOutputAllStatsFields(JI, 0); % suppress output of additional statistics, spares runtime with large populations
[sol, fit]=getResult(JI); JI=optimizeWith(JI, 3, 'population', eva2.server.go.populations.Population(1000);
finalPop=getMultipleResults(JI); [sol, fit]=getResult(JI);
finalPop=getMultipleResults(JI);
% integer case with specific initialization range
initR=[-15 -15 -15 -15 -15; -5 -5 -5 -5 -5]; % binary case with a multi-objective fitness function
R=[-15 -15 -15 -15 -15; 15 15 15 15 15]; R=30;
JI=JEInterface(@testfun, 'int', R, initR, 5, 'Display', 'iter'); JI=JEInterface(@testfun, 'binary', R, R, 6, 'Display', 'iter', 'TolX', 0, 'TolFun', 0, 'MaxFunEvals', 3000);
JI=optimize(JI, 3); JI=optimizeWith(JI, 14);
[sol, fit]=getResult(JI); % The resulting solution set is a pareto dominant set found with NSGA-II
finalPop=getMultipleResults(JI); [finalSols, finalFit]=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

@ -17,4 +17,20 @@ switch y
end end
case 5 % simple parabola case 5 % simple parabola
z (1)=sum( x .* x ) ; z (1)=sum( x .* x ) ;
end case 6 % binary function with two criteria: longest sequence of zeros and number of ones
% Optimal solutions have the form 1*0*1* in {0,1}^length(x)
numOnes=0;
longestZeroLen=0;
currentZeroLen=0;
for i=1:length(x)
if x(i)=='1'
numOnes=numOnes+1;
currentZeroLen=0;
else
currentZeroLen=currentZeroLen+1;
if currentZeroLen>longestZeroLen ; longestZeroLen=currentZeroLen; end
end;
%disp(sprintf('at %f : numOnes=%f, currentZeroLen=%f, longest=%f ', i, numOnes, currentZeroLen, longestZeroLen));
end
z=[length(x)-longestZeroLen, length(x)-numOnes];
end

View File

@ -1,7 +1,7 @@
package eva2.server.go.problems; package eva2.server.go.problems;
import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.individuals.GAIndividualIntegerData; import eva2.server.go.individuals.GIIndividualIntegerData;
import eva2.server.go.individuals.InterfaceDataTypeInteger; import eva2.server.go.individuals.InterfaceDataTypeInteger;
import eva2.server.go.populations.Population; import eva2.server.go.populations.Population;
import eva2.server.go.strategies.InterfaceOptimizer; import eva2.server.go.strategies.InterfaceOptimizer;
@ -20,7 +20,7 @@ public abstract class AbstractProblemInteger extends AbstractOptimizationProblem
} }
protected void initTemplate() { protected void initTemplate() {
if (m_Template==null) m_Template = new GAIndividualIntegerData(); if (m_Template==null) m_Template = new GIIndividualIntegerData();
if (((InterfaceDataTypeInteger)this.m_Template).size()!=this.getProblemDimension()) { if (((InterfaceDataTypeInteger)this.m_Template).size()!=this.getProblemDimension()) {
((InterfaceDataTypeInteger)this.m_Template).setIntegerDataLength(this.getProblemDimension()); ((InterfaceDataTypeInteger)this.m_Template).setIntegerDataLength(this.getProblemDimension());
} }

View File

@ -63,6 +63,6 @@ public class I1Problem extends AbstractProblemInteger implements java.io.Seriali
} }
public static String globalInfo() { public static String globalInfo() {
return "I1(x) = x^2 is to be minimized."; return "A hyper parabola on integer values x with I1(x) = x^2 is to be minimized.";
} }
} }