Matlab interface bugfix

This commit is contained in:
Marcel Kronfeld 2011-02-01 10:59:21 +00:00
parent 9dfcf4d71a
commit d27b78092b
4 changed files with 33 additions and 22 deletions

View File

@ -12,9 +12,12 @@ function int = JEInterface(fhandle, datatype, range, varargin)
% range: a 2 x dim array defining the solution subspace with lower and % range: a 2 x dim array defining the solution subspace with lower and
% upper bounds; or a scalar defining the bitwidth for binary % upper bounds; or a scalar defining the bitwidth for binary
% problems. % problems.
% defaultArgs: (optional) additional constant argument to the target % initRange: in analogy to the range: a possibly different range for the
% initial solutions. It applies to double and int data types only.
% May be set equal to the range.
% defaultArgs: additional constant argument to the target
% function, empty by default. % function, empty by default.
% options: (optional) options as name-value pairs defining optimization parameters, % options: options as name-value pairs defining optimization parameters,
% especially tolerance and maximum function calls. % especially tolerance and maximum function calls.
% Check makeOoptions for default settings. % Check makeOoptions for default settings.
% %

View File

@ -25,16 +25,17 @@ elseif strcmp(int.dataType,eva2.server.go.problems.MatlabProblemDataTypeEnum.typ
% integer problem % integer problem
s=sprintf('Real valued problem in %d dimensions and range %s ', int.dim, mat2str(int.range)); s=sprintf('Real valued problem in %d dimensions and range %s ', int.dim, mat2str(int.range));
disp(s); disp(s);
size(int.range) %size(int.range);
%x=int.range(1,:)+ceil(rand(1,int.dim).*int.range(2,:)-int.range(1,:)); %x=int.range(1,:)+ceil(rand(1,int.dim).*int.range(2,:)-int.range(1,:));
x=(int.range(:,1)+ceil(rand(int.dim,1).*int.range(:,2)-int.range(:,1)))'; x=(int.range(:,1)+floor(rand(int.dim,1).*(ones(size(int.range(:,2)))+int.range(:,2)-int.range(:,1))))';
else else
error('Invalid data type in testEvalFunc.m!'); error('Invalid data type in testEvalFunc.m!');
end end
if (isempty(int.range)) if (isempty(int.range))
msg=sprintf('\nTesting value: %d, bin.: %s', x, dec2bin(x, int.dim)); msg=sprintf('\nTesting binary string %s', x);
else else
msg=sprintf('\nTesting value: %d', x); msg=sprintf('\nTesting value: %s', num2str(x));
end end
disp(msg); disp(msg);

View File

@ -77,7 +77,9 @@ public class MatlabEvalMediator {
// Integer.decode() // Integer.decode()
// //
if (question == null) System.err.println("Error: requesting evaluation for null array!"); if (question == null) System.err.println("Error: requesting evaluation for null array!");
} else System.err.println("Error, requesting evaluation for non array!"); } else { // if its not an array, it must be a BitSet
if (!(x instanceof BitSet)) System.err.println("Error, requesting evaluation for invalid data type! " + question.getClass());
}
// logMPAndSysOut("Synch requesting A requestEval " + getState()); // logMPAndSysOut("Synch requesting A requestEval " + getState());
synchronized(requesting) { synchronized(requesting) {
// logMPAndSysOut(" in synch requesting A requestEval " + getState()); // logMPAndSysOut(" in synch requesting A requestEval " + getState());

View File

@ -209,7 +209,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
} }
} else this.range=null; } else this.range=null;
if (initialRange!=null) { // these may be Matlab objects, so I do it by foot, just to be sure not to clone them within Matlab instead of here if (initRange!=null) { // these may be Matlab objects, so I do it by foot, just to be sure not to clone them within Matlab instead of here
this.initialRange = new double[initRange.length][initRange[0].length]; this.initialRange = new double[initRange.length][initRange[0].length];
for (int i=0; i<this.initialRange.length; i++) { for (int i=0; i<this.initialRange.length; i++) {
for (int j=0; j<this.initialRange[0].length; j++) this.initialRange[i][j]=initRange[i][j]; for (int j=0; j<this.initialRange[0].length; j++) this.initialRange[i][j]=initRange[i][j];
@ -217,7 +217,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
} else this.initialRange=null; } else this.initialRange=null;
if (Arrays.deepEquals(initialRange, range)) initialRange=null; if (Arrays.deepEquals(initialRange, range)) initialRange=null;
dataType=datType; // store the data type dataType=datType; // store the data type
log("### Data type is " + dataType); log("### Data type is " + dataType);
@ -582,18 +582,23 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
log("retrieving initial range..., first entry: " + ((initialRange==null) ? "null" : BeanInspector.toString(initialRange[0]))); log("retrieving initial range..., first entry: " + ((initialRange==null) ? "null" : BeanInspector.toString(initialRange[0])));
return initialRange; return initialRange;
} }
public String getName() {
return "MatlabProblem";
}
@Override // @Override
public String[] getAdditionalDataHeader() { // public String[] getAdditionalDataHeader() {
return ToolBox.appendArrays(super.getAdditionalDataHeader(), "matlabSol"); // return ToolBox.appendArrays(super.getAdditionalDataHeader(), "matlabSol");
} // }
@Override // @Override
public String[] getAdditionalDataInfo() { // public String[] getAdditionalDataInfo() {
return ToolBox.appendArrays(super.getAdditionalDataInfo(), "Additional solution representation"); // return ToolBox.appendArrays(super.getAdditionalDataInfo(), "Additional solution representation");
} // }
@Override // @Override
public Object[] getAdditionalDataValue(PopulationInterface pop) { // public Object[] getAdditionalDataValue(PopulationInterface pop) {
String addStr=((AbstractEAIndividual)pop.getBestIndividual()).getStringRepresentation(); //// String addStr=((AbstractEAIndividual)pop.getBestIndividual()).getStringRepresentation();
return ToolBox.appendArrays(super.getAdditionalDataValue(pop), addStr); // String addStr=BeanInspector.toString(pop.getBestIndividual());
} // return ToolBox.appendArrays(super.getAdditionalDataValue(pop), addStr);
// }
} }