diff --git a/resources/MatlabInterface/@JEInterface/convertUnsignedJE.m b/resources/MatlabInterface/@JEInterface/convertUnsignedJE.m index a6e787f8..bb14388b 100644 --- a/resources/MatlabInterface/@JEInterface/convertUnsignedJE.m +++ b/resources/MatlabInterface/@JEInterface/convertUnsignedJE.m @@ -2,13 +2,24 @@ function [ z ] = convertUnsignedJE( int, x ) %CONVERTUNSIGNEDJE Convert signed 32-bit integer to unsigned. % Detailed explanation goes here -z=zeros(size(x,1),size(x,2), 'uint32'); -for j=1 : size(x,1) - for i=1 : size(x,2) - if (x(j,i) < 0) - z(j,i) = 1+bitxor(uint32(-x(j,i)), int.hexMask); +if strcmp(class(x),'java.util.BitSet') + z=num2str(10^(int.dim-1)); + for i=1:int.dim + if (x.get(i-1)) % Java indices start at zero! + z(i)='1'; else - z(j,i) = x(j,i); + z(i)='0'; + end + end +else + z=zeros(size(x,1),size(x,2), 'int32'); + for j=1 : size(x,1) + for i=1 : size(x,2) + if (x(j,i) < 0) + z(j,i) = 1+bitxor(uint32(-x(j,i)), int.hexMask); + else + z(j,i) = x(j,i); + end end end end \ No newline at end of file diff --git a/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m b/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m index 83db92e4..60145175 100644 --- a/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m +++ b/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m @@ -78,7 +78,7 @@ try % disp(sprintf('running mediator id %d',cnt)); int.mediator.run(cnt); % disp(sprintf('after running mediator id %d',cnt)); - cnt=cnt+1; + cnt=cnt+1; if (~int.mediator.isFinished()) % disp('getting question'); x = int.mediator.getQuestion(); diff --git a/resources/MatlabInterface/@JEInterface/testEvalFunc.m b/resources/MatlabInterface/@JEInterface/testEvalFunc.m index f5d44f4b..b085b15e 100644 --- a/resources/MatlabInterface/@JEInterface/testEvalFunc.m +++ b/resources/MatlabInterface/@JEInterface/testEvalFunc.m @@ -6,11 +6,13 @@ if (isempty(int.range)) % binary problem s=sprintf('Binary problem of bitwidth %d', int.dim); disp(s); - numInts=ceil(int.dim/wordwidth); + %numInts=ceil(int.dim/wordwidth); % generate trial vector - x=ceil(rand(1,numInts).*(2^wordwidth)); - overheadBits=numInts*wordwidth-int.dim; - x(numInts)=bitshift(x(numInts),-overheadBits); % shift right by overhead + %x=ceil(rand(1,numInts).*(2^wordwidth)); + %overheadBits=numInts*wordwidth-int.dim; + %x(numInts)=bitshift(x(numInts),-overheadBits); % shift right by overhead + bs=eva2.tools.math.RNG.randomBitSet(0.5, int.dim); + x=convertUnsignedJE(int, bs); else % double problem x=rand(1, int.dim); @@ -35,9 +37,10 @@ try res = feval(int.f, x, int.args); end catch ME - disp('Function evaluation failed:'); + disp('JEInterface: Test function evaluation failed:'); disp(ME.message); - error(['Test failed! ' ME.message]); + rethrow(ME); + %error(['Test failed! ' ME.message]); end disp('Function returned: '); diff --git a/src/eva2/server/go/problems/MatlabEvalMediator.java b/src/eva2/server/go/problems/MatlabEvalMediator.java index 2c8dbb61..af2f3bff 100644 --- a/src/eva2/server/go/problems/MatlabEvalMediator.java +++ b/src/eva2/server/go/problems/MatlabEvalMediator.java @@ -1,5 +1,7 @@ package eva2.server.go.problems; +import java.util.BitSet; + import eva2.gui.BeanInspector; /** @@ -240,7 +242,7 @@ public class MatlabEvalMediator { optSolSet = solSet; } - void setSolutionSet(int[][] solSet) { + void setSolutionSet(BitSet[] solSet) { // System.err.println("setting SolSet " + ((solSet != null) ? solSet.length : 0)); optSolSet = solSet; } diff --git a/src/eva2/server/go/problems/MatlabProblem.java b/src/eva2/server/go/problems/MatlabProblem.java index 3dadb53a..42c7d002 100644 --- a/src/eva2/server/go/problems/MatlabProblem.java +++ b/src/eva2/server/go/problems/MatlabProblem.java @@ -5,15 +5,17 @@ import java.io.FileOutputStream; import java.io.PrintStream; import java.io.Serializable; import java.util.Arrays; +import java.util.BitSet; import eva2.OptimizerFactory; import eva2.OptimizerRunnable; import eva2.gui.BeanInspector; +import eva2.server.go.PopulationInterface; import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.individuals.ESIndividualDoubleData; -import eva2.server.go.individuals.GAIndividualIntegerData; +import eva2.server.go.individuals.GAIndividualBinaryData; +import eva2.server.go.individuals.InterfaceDataTypeBinary; import eva2.server.go.individuals.InterfaceDataTypeDouble; -import eva2.server.go.individuals.InterfaceDataTypeInteger; import eva2.server.go.operators.postprocess.InterfacePostProcessParams; import eva2.server.go.operators.postprocess.PostProcess; import eva2.server.go.operators.postprocess.PostProcessParams; @@ -25,6 +27,7 @@ import eva2.server.go.operators.terminators.PopulationMeasureTerminator.Stagnati import eva2.server.go.populations.Population; import eva2.server.go.strategies.InterfaceOptimizer; import eva2.server.stat.InterfaceTextListener; +import eva2.tools.ToolBox; /** * Interface problem class for Matlab(TM). Towards EvA2 this behaves like any other double valued @@ -105,13 +108,18 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf ((InterfaceDataTypeDouble)this.m_Template).SetDoubleRange(range); } } else { - if (m_Template == null) m_Template = new GAIndividualIntegerData(); + ///// binary alternative + if (m_Template == null) m_Template = new GAIndividualBinaryData(getProblemDimension()); + + ///// Integer alternative + /*if (m_Template == null) m_Template = new GAIndividualIntegerData(); int intLen = 1+((getProblemDimension()-1)/32); int lastIntCodingBits = getProblemDimension()-((intLen-1)*32); if (lastIntCodingBits > 32) System.err.println("ERROR in MatlabProblem:initTemplate"); ((GAIndividualIntegerData)m_Template).setIntegerDataLength(intLen); ((GAIndividualIntegerData)m_Template).SetIntRange(Integer.MIN_VALUE, Integer.MAX_VALUE); if (lastIntCodingBits < 32) ((GAIndividualIntegerData)m_Template).SetIntRange(intLen-1, 0, (int)Math.pow(2, lastIntCodingBits)-1); + */ ///// // System.err.println("integer length is "+((GAIndividualIntegerData)m_Template).getIntegerData().length); // System.err.println("Range is " + BeanInspector.toString(((GAIndividualIntegerData)m_Template).getIntRange())); // m_Template = new GAIndividualBinaryData(); @@ -266,6 +274,17 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf optimize(optType, outputFilePrefix, null, null); } + /** + * Start an optimization using the MatlabProblem. The optType references the standard + * optimizer as in OptimizerFactory. An output file prefix is optional. In two arrays, + * name-value mappings can be given as additional parameters to the optimizer. + * + * @see OptimizerFactory.getOptRunnable + * @param optType + * @param outputFilePrefix + * @param specParams + * @param specValues + */ public void optimize(final int optType, String outputFilePrefix, Object[] specParams, Object[] specValues) { if (allowSingleRunnable && (runnable != null) && (!runnable.isFinished())) { System.err.println("Please wait for the current optimization to finish"); @@ -399,21 +418,21 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf } handler.setSolutionSet(solSet); } else { - int[][] solSet = new int[pop.size()][]; + BitSet[] solSet = new BitSet[pop.size()]; for (int i=0; i