From 489e0a6f3ff3fb2db5a5fc35e6e16d4cdabd631d Mon Sep 17 00:00:00 2001 From: Marcel Kronfeld Date: Wed, 16 Feb 2011 12:47:15 +0000 Subject: [PATCH] Multi-criterial example for the Matlab interface --- .../MatlabInterface/JEInterface-examples.m | 60 +++++++++++-------- resources/MatlabInterface/testfun.m | 18 +++++- .../go/problems/AbstractProblemInteger.java | 4 +- src/eva2/server/go/problems/I1Problem.java | 2 +- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/resources/MatlabInterface/JEInterface-examples.m b/resources/MatlabInterface/JEInterface-examples.m index 9b9b57a6..b284fb57 100755 --- a/resources/MatlabInterface/JEInterface-examples.m +++ b/resources/MatlabInterface/JEInterface-examples.m @@ -3,29 +3,37 @@ % URL: http://www.ra.cs.uni-tuebingen.de/software/EvA2/ % adapt the path settings! -addpath '/home/user/workspace/MatlabInterface' % .. directory containing @JEInterface -javaaddpath '/home/user/workspace/EvA2Base.jar' % .. the EvA2 base package -% 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 - -% 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); +addpath '/home/user/workspace/MatlabInterface' % .. directory containing @JEInterface +javaaddpath '/home/user/workspace/EvA2Base.jar' % .. the EvA2 base package +% 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 + +% 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=30; +JI=JEInterface(@testfun, 'binary', R, R, 4, 'Display', 'iter'); +JI=setOutputAllStatsFields(JI, 0); % suppress output of additional statistics, spares runtime with large populations +JI=optimizeWith(JI, 3, 'population', eva2.server.go.populations.Population(1000); +[sol, fit]=getResult(JI); +finalPop=getMultipleResults(JI); + +% binary case with a multi-objective fitness function +R=30; +JI=JEInterface(@testfun, 'binary', R, R, 6, 'Display', 'iter', 'TolX', 0, 'TolFun', 0, 'MaxFunEvals', 3000); +JI=optimizeWith(JI, 14); +% The resulting solution set is a pareto dominant set found with NSGA-II +[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); diff --git a/resources/MatlabInterface/testfun.m b/resources/MatlabInterface/testfun.m index 0862de5c..9e1e32b2 100644 --- a/resources/MatlabInterface/testfun.m +++ b/resources/MatlabInterface/testfun.m @@ -17,4 +17,20 @@ switch y end case 5 % simple parabola 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 diff --git a/src/eva2/server/go/problems/AbstractProblemInteger.java b/src/eva2/server/go/problems/AbstractProblemInteger.java index 115a2d9f..3a8137ca 100644 --- a/src/eva2/server/go/problems/AbstractProblemInteger.java +++ b/src/eva2/server/go/problems/AbstractProblemInteger.java @@ -1,7 +1,7 @@ package eva2.server.go.problems; 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.populations.Population; import eva2.server.go.strategies.InterfaceOptimizer; @@ -20,7 +20,7 @@ public abstract class AbstractProblemInteger extends AbstractOptimizationProblem } 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()) { ((InterfaceDataTypeInteger)this.m_Template).setIntegerDataLength(this.getProblemDimension()); } diff --git a/src/eva2/server/go/problems/I1Problem.java b/src/eva2/server/go/problems/I1Problem.java index ba160604..4aedb546 100644 --- a/src/eva2/server/go/problems/I1Problem.java +++ b/src/eva2/server/go/problems/I1Problem.java @@ -63,6 +63,6 @@ public class I1Problem extends AbstractProblemInteger implements java.io.Seriali } 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."; } } \ No newline at end of file