Added simple initialization range interface (req. change of IndividualInterface); added MutateGAUniform;

This commit is contained in:
Marcel Kronfeld 2010-02-23 08:36:19 +00:00
parent bac6beb204
commit 126a1780f3
35 changed files with 328 additions and 222 deletions

View File

@ -1,8 +1,9 @@
function int = JEInterface(fhandle, range, varargin) function int = JEInterface(fhandle, range, varargin)
% EvA2 Interface for Matlab % EvA2 Interface for Matlab
% JEInterface(fhandle, range) % JEInterface(fhandle, range)
% JEInterface(fhandle, range, defaultargs) % JEInterface(fhandle, range, initRange)
% JEInterface(fhandle, range, defaultargs, options...) % JEInterface(fhandle, range, initRange, defaultargs)
% JEInterface(fhandle, range, initRange, defaultargs, options...)
% %
% Arguments: % Arguments:
% fhandle: a function handle defining the optimization target. % fhandle: a function handle defining the optimization target.
@ -43,6 +44,7 @@ int.resultArr = [];
int.f = ''; int.f = '';
int.dim = 0; int.dim = 0;
int.range = []; int.range = [];
int.initialRange=[];
int.mp = []; int.mp = [];
int.msg = ''; int.msg = '';
int.funCalls = 0; int.funCalls = 0;
@ -78,21 +80,42 @@ int = class(int,'JEInterface');
int.opts = makeOptions(int); int.opts = makeOptions(int);
if (nargin>2) if (nargin>2)
int.args = varargin{1}; int.initialRange=varargin{1};
disp('Fitness function argument: '); disp(int.args);
if (nargin > 3) if (isa(varargin{1}, 'double') && (size(varargin{1},1) == 2))
if (rem(nargin,2)==0) if (int.dim ~= size(varargin{1},2))
error('Invalid number of arguments!'); error('Invalid initial range: wrong dimensions');
end end
disp('Reading options:'); int.initialRange=transpose(varargin{1});
for i=2:2:nargin-2 s = ['Double valued initial search space: ' mat2str(int.initialRange)];
int=setOpt(int, varargin{i}, varargin{i+1}); disp(s);
end
if (nargin>3)
int.args = varargin{2};
disp('Fitness function argument: '); disp(int.args);
if (nargin > 4)
if (rem(nargin,2)==1)
error('Invalid number of arguments!');
end
disp('Reading options:');
for i=3:2:nargin-2
int=setOpt(int, varargin{i}, varargin{i+1});
end
end end
end end
end end
display(getOptions(int)); display(getOptions(int));
% finally create the java object % finally create the java object
int.mp = eva2.server.go.problems.MatlabProblem(int.dim, int.range); if (isempty(int.initialRange))
int.mp = eva2.server.go.problems.MatlabProblem(int.dim, int.range);
else
if (eq(size(int.range), size(int.initialRange)))
int.mp = eva2.server.go.problems.MatlabProblem(int.dim, int.range, int.initialRange);
else
error('Mismatching dimensions of range and initial range!');
end
end
disp('Java object created'); disp('Java object created');
testEvalFunc(int); testEvalFunc(int);

View File

@ -1,4 +1,7 @@
package eva2.server.go; package eva2.server.go;
import eva2.server.go.problems.InterfaceOptimizationProblem;
/* /*
* Title: EvA2 * Title: EvA2
* Description: * Description:
@ -62,7 +65,9 @@ public interface IndividualInterface {
public void defaultMutate(); public void defaultMutate();
/** /**
* Initialize the genotype randomly, usually in a uniform distribution. * Initialize the genotype randomly, usually in a uniform distribution. Make sure,
* if the problem has an initial range (it implements InterfaceHasInitialRange), that this
* initial range is used.
*/ */
public void defaultInit(); public void defaultInit(InterfaceOptimizationProblem prob);
} }

View File

@ -269,7 +269,11 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
/** This method will allow a default initialisation of the individual /** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved. * @param opt The optimization problem that is to be solved.
*/ */
public abstract void init(InterfaceOptimizationProblem opt); public void init(InterfaceOptimizationProblem opt) {
this.defaultInit(opt);
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.

View File

@ -5,6 +5,7 @@ import java.util.BitSet;
import eva2.server.go.operators.crossover.CrossoverESDefault; import eva2.server.go.operators.crossover.CrossoverESDefault;
import eva2.server.go.operators.mutation.InterfaceMutation; import eva2.server.go.operators.mutation.InterfaceMutation;
import eva2.server.go.operators.mutation.MutateESGlobal; import eva2.server.go.operators.mutation.MutateESGlobal;
import eva2.server.go.problems.InterfaceHasInitRange;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
@ -170,15 +171,6 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
/************************************************************************************ /************************************************************************************
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
* @param obj The initial value for the phenotype * @param obj The initial value for the phenotype
@ -189,7 +181,7 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
BitSet bs = (BitSet) obj; BitSet bs = (BitSet) obj;
this.SetBinaryGenotype(bs); this.SetBinaryGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for ESIndividualBinaryData is no BitSet!"); System.out.println("Initial value for ESIndividualBinaryData is no BitSet!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -260,10 +252,9 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
ESIndividualDoubleData.defaultMutate(m_Genotype, m_Range); ESIndividualDoubleData.defaultMutate(m_Genotype, m_Range);
} }
/** This method initializes the double vector public void defaultInit(InterfaceOptimizationProblem prob) {
*/ if (prob instanceof InterfaceHasInitRange && (((InterfaceHasInitRange)prob).getInitRange()!=null)) ESIndividualDoubleData.defaultInit(m_Genotype, (double[][])((InterfaceHasInitRange)prob).getInitRange());
public void defaultInit() { else ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
} }
/********************************************************************************************************************** /**********************************************************************************************************************
* These are for GUI * These are for GUI

View File

@ -4,6 +4,7 @@ package eva2.server.go.individuals;
import eva2.server.go.operators.crossover.CrossoverESDefault; import eva2.server.go.operators.crossover.CrossoverESDefault;
import eva2.server.go.operators.mutation.InterfaceMutation; import eva2.server.go.operators.mutation.InterfaceMutation;
import eva2.server.go.operators.mutation.MutateESGlobal; import eva2.server.go.operators.mutation.MutateESGlobal;
import eva2.server.go.problems.InterfaceHasInitRange;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.EVAERROR; import eva2.tools.EVAERROR;
import eva2.tools.math.Mathematics; import eva2.tools.math.Mathematics;
@ -200,9 +201,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
* @param opt The optimization problem that is to be solved. * @param opt The optimization problem that is to be solved.
*/ */
public void init(InterfaceOptimizationProblem opt) { public void init(InterfaceOptimizationProblem opt) {
this.defaultInit(); super.init(opt);
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
// evil operators may not respect the range, so at least give some hint // evil operators may not respect the range, so at least give some hint
if (!Mathematics.isInRange(m_Genotype, m_Range)) EVAERROR.errorMsgOnce("Warning: Individual out of range after initialization (and potential initial crossover/mutation)!"); if (!Mathematics.isInRange(m_Genotype, m_Range)) EVAERROR.errorMsgOnce("Warning: Individual out of range after initialization (and potential initial crossover/mutation)!");
} }
@ -218,7 +217,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!"); if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!");
this.SetDoubleGenotype(bs); this.SetDoubleGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for ESIndividualDoubleData is not double[]!"); System.out.println("Initial value for ESIndividualDoubleData is not double[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -300,10 +299,9 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
if (genotype[mutationIndex] > range[mutationIndex][1]) genotype[mutationIndex] = range[mutationIndex][1]; if (genotype[mutationIndex] > range[mutationIndex][1]) genotype[mutationIndex] = range[mutationIndex][1];
} }
/** This method initializes the double vector public void defaultInit(InterfaceOptimizationProblem prob) {
*/ if (prob instanceof InterfaceHasInitRange && (((InterfaceHasInitRange)prob).getInitRange()!=null)) ESIndividualDoubleData.defaultInit(m_Genotype, (double[][])((InterfaceHasInitRange)prob).getInitRange());
public void defaultInit() { else ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
} }
/** /**

View File

@ -1,12 +1,9 @@
package eva2.server.go.individuals; package eva2.server.go.individuals;
import java.util.Arrays;
import eva2.server.go.IndividualInterface;
import eva2.server.go.operators.crossover.CrossoverESDefault; import eva2.server.go.operators.crossover.CrossoverESDefault;
import eva2.server.go.operators.mutation.InterfaceMutation; import eva2.server.go.operators.mutation.InterfaceMutation;
import eva2.server.go.operators.mutation.MutateESGlobal; import eva2.server.go.operators.mutation.MutateESGlobal;
import eva2.server.go.problems.InterfaceHasInitRange;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
@ -187,14 +184,6 @@ public class ESIndividualIntegerData extends AbstractEAIndividual implements Int
/************************************************************************************ /************************************************************************************
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
@ -207,7 +196,7 @@ public class ESIndividualIntegerData extends AbstractEAIndividual implements Int
if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!"); if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!");
this.SetIntGenotype(bs); this.SetIntGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for ESIndividualIntegerData is not int[]!"); System.out.println("Initial value for ESIndividualIntegerData is not int[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -276,11 +265,11 @@ public class ESIndividualIntegerData extends AbstractEAIndividual implements Int
return result; return result;
} }
/** This method initializes the double vector public void defaultInit(InterfaceOptimizationProblem prob) {
*/ int[][] range = m_Range;
public void defaultInit() { if (prob instanceof InterfaceHasInitRange && (((InterfaceHasInitRange)prob).getInitRange()!=null)) range = (int[][])((InterfaceHasInitRange)prob).getInitRange();
for (int i = 0; i < this.m_Genotype.length; i++) { for (int i = 0; i < this.m_Genotype.length; i++) {
this.m_Genotype[i] = RNG.randomInt(this.m_Range[i][0], this.m_Range[i][1]); this.m_Genotype[i] = RNG.randomInt(range[i][0], range[i][1]);
} }
} }
/********************************************************************************************************************** /**********************************************************************************************************************

View File

@ -1,9 +1,9 @@
package eva2.server.go.individuals; package eva2.server.go.individuals;
import eva2.server.go.IndividualInterface;
import eva2.server.go.operators.crossover.CrossoverESDefault; import eva2.server.go.operators.crossover.CrossoverESDefault;
import eva2.server.go.operators.mutation.InterfaceMutation; import eva2.server.go.operators.mutation.InterfaceMutation;
import eva2.server.go.operators.mutation.MutateESGlobal; import eva2.server.go.operators.mutation.MutateESGlobal;
import eva2.server.go.problems.InterfaceHasInitRange;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
@ -214,14 +214,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
/************************************************************************************ /************************************************************************************
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
@ -234,7 +226,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!"); if (bs.length != this.m_Genotype.length) System.out.println("Init value and requested length doesn't match!");
this.SetPermutationGenotype(bs); this.SetPermutationGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for ESIndividualPermutationData is not int[]!"); System.out.println("Initial value for ESIndividualPermutationData is not int[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -325,12 +317,12 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
} }
} }
/** public void defaultInit(InterfaceOptimizationProblem prob) {
* This method initializes the double vector double[][][] range = m_Range;
*/ if (prob instanceof InterfaceHasInitRange && (((InterfaceHasInitRange)prob).getInitRange()!=null)) range = (double[][][])((InterfaceHasInitRange)prob).getInitRange();
public void defaultInit() {
for (int i = 0; i < this.m_Genotype.length; i++) { for (int i = 0; i < this.m_Genotype.length; i++) {
ESIndividualDoubleData.defaultInit(m_Genotype[i], m_Range[i]); ESIndividualDoubleData.defaultInit(m_Genotype[i], range[i]);
} }
} }

View File

@ -75,9 +75,9 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
((AbstractEAIndividual)this.m_BitSet).init(opt); ((AbstractEAIndividual)this.m_BitSet).init(opt);
} }
public void defaultInit() { public void defaultInit(InterfaceOptimizationProblem prob) {
((AbstractEAIndividual)this.m_Numbers).defaultInit(); ((AbstractEAIndividual)this.m_Numbers).defaultInit(prob);
((AbstractEAIndividual)this.m_BitSet).defaultInit(); ((AbstractEAIndividual)this.m_BitSet).defaultInit(prob);
} }
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the

View File

@ -91,15 +91,6 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
/************************************************************************************ /************************************************************************************
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
* @param obj The initial value for the phenotype * @param obj The initial value for the phenotype
@ -110,7 +101,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
BitSet bs = (BitSet) obj; BitSet bs = (BitSet) obj;
this.SetBinaryGenotype(bs); this.SetBinaryGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for GAIndividualBinaryData is no BitSet!"); System.out.println("Initial value for GAIndividualBinaryData is no BitSet!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -175,9 +166,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
return this.m_GenotypeLength; return this.m_GenotypeLength;
} }
/** This method inits the genotpye of the individual public void defaultInit(InterfaceOptimizationProblem prob) {
*/
public void defaultInit() {
for (int i = 0; i < this.m_GenotypeLength; i++) { for (int i = 0; i < this.m_GenotypeLength; i++) {
if (RNG.flipCoin(0.5)) this.m_Genotype.set(i); if (RNG.flipCoin(0.5)) this.m_Genotype.set(i);
else this.m_Genotype.clear(i); else this.m_Genotype.clear(i);

View File

@ -208,14 +208,6 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
/************************************************************************************ /************************************************************************************
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
@ -228,7 +220,7 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
if (bs.length != this.m_Range.length) System.out.println("Init value and requested length doesn't match!"); if (bs.length != this.m_Range.length) System.out.println("Init value and requested length doesn't match!");
this.SetDoubleGenotype(bs); this.SetDoubleGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for GAIndividualDoubleData is not double[]!"); System.out.println("Initial value for GAIndividualDoubleData is not double[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -290,9 +282,7 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
return this.m_GenotypeLength; return this.m_GenotypeLength;
} }
/** This method inits the genotpye of the individual public void defaultInit(InterfaceOptimizationProblem prob) {
*/
public void defaultInit() {
for (int i = 0; i < this.m_GenotypeLength; i++) { for (int i = 0; i < this.m_GenotypeLength; i++) {
if (RNG.flipCoin(0.5)) this.m_Genotype.set(i); if (RNG.flipCoin(0.5)) this.m_Genotype.set(i);
else this.m_Genotype.clear(i); else this.m_Genotype.clear(i);

View File

@ -237,15 +237,6 @@ public class GAIndividualIntegerData extends AbstractEAIndividual implements Int
/************************************************************************************ /************************************************************************************
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
* @param obj The initial value for the phenotype * @param obj The initial value for the phenotype
@ -257,7 +248,7 @@ public class GAIndividualIntegerData extends AbstractEAIndividual implements Int
if (bs.length != this.m_Range.length) System.out.println("Init value and requested length doesn't match!"); if (bs.length != this.m_Range.length) System.out.println("Init value and requested length doesn't match!");
this.SetIntGenotype(bs); this.SetIntGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for GAIndividualDoubleData is not double[]!"); System.out.println("Initial value for GAIndividualDoubleData is not double[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -333,9 +324,7 @@ public class GAIndividualIntegerData extends AbstractEAIndividual implements Int
return overallLength; return overallLength;
} }
/** This method inits the genotpye of the individual public void defaultInit(InterfaceOptimizationProblem prob) {
*/
public void defaultInit() {
int overallLength = 0; int overallLength = 0;
for (int i = 0; i < this.m_CodingLenghts.length; i++) overallLength += this.m_CodingLenghts[i]; for (int i = 0; i < this.m_CodingLenghts.length; i++) overallLength += this.m_CodingLenghts[i];
for (int i = 0; i < overallLength; i++) { for (int i = 0; i < overallLength; i++) {
@ -365,7 +354,7 @@ public class GAIndividualIntegerData extends AbstractEAIndividual implements Int
} }
indy.setIntegerDataLength(dimension); indy.setIntegerDataLength(dimension);
indy.SetIntRange(range); indy.SetIntRange(range);
indy.defaultInit(); indy.defaultInit(null);
System.out.println(""+indy.getStringRepresentation()); System.out.println(""+indy.getStringRepresentation());
System.out.println("System.exit(0)"); System.out.println("System.exit(0)");
int[] data = indy.getIntegerData(); int[] data = indy.getIntegerData();

View File

@ -74,9 +74,9 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
((AbstractEAIndividual)this.m_Program).init(opt); ((AbstractEAIndividual)this.m_Program).init(opt);
} }
public void defaultInit() { public void defaultInit(InterfaceOptimizationProblem prob) {
((AbstractEAIndividual)this.m_Numbers).defaultInit(); ((AbstractEAIndividual)this.m_Numbers).defaultInit(prob);
((AbstractEAIndividual)this.m_Program).defaultInit(); ((AbstractEAIndividual)this.m_Program).defaultInit(prob);
} }
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the

View File

@ -501,15 +501,6 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
/************************************************************************************ /************************************************************************************
* InterfaceEAIndividual methods * InterfaceEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
* @param obj The initial value for the phenotype * @param obj The initial value for the phenotype
@ -519,7 +510,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
if (obj instanceof InterfaceProgram) { if (obj instanceof InterfaceProgram) {
this.SetProgramGenotype((InterfaceProgram[])obj); this.SetProgramGenotype((InterfaceProgram[])obj);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for GPIndividualDoubleData is no InterfaceProgram[]!"); System.out.println("Initial value for GPIndividualDoubleData is no InterfaceProgram[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -574,9 +565,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
return this.m_GenotypeLengthPerProgram*this.m_Area.length; return this.m_GenotypeLengthPerProgram*this.m_Area.length;
} }
/** This method inits the genotpye of the individual public void defaultInit(InterfaceOptimizationProblem prob) {
*/
public void defaultInit() {
for (int i = 0; i < this.m_GenotypeLengthPerProgram*this.m_Area.length; i++) { for (int i = 0; i < this.m_GenotypeLengthPerProgram*this.m_Area.length; i++) {
if (RNG.flipCoin(0.5)) this.m_Genotype.set(i); if (RNG.flipCoin(0.5)) this.m_Genotype.set(i);
else this.m_Genotype.clear(i); else this.m_Genotype.clear(i);

View File

@ -3,6 +3,7 @@ package eva2.server.go.individuals;
import eva2.server.go.operators.crossover.CrossoverGIDefault; import eva2.server.go.operators.crossover.CrossoverGIDefault;
import eva2.server.go.operators.mutation.InterfaceMutation; import eva2.server.go.operators.mutation.InterfaceMutation;
import eva2.server.go.operators.mutation.MutateDefault; import eva2.server.go.operators.mutation.MutateDefault;
import eva2.server.go.problems.InterfaceHasInitRange;
import eva2.server.go.problems.InterfaceOptimizationProblem; import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
@ -189,15 +190,6 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
/************************************************************************************ /************************************************************************************
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
* @param obj The initial value for the phenotype * @param obj The initial value for the phenotype
@ -209,7 +201,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
if (bs.length != this.m_Range.length) System.out.println("Init value and requested length doesn't match!"); if (bs.length != this.m_Range.length) System.out.println("Init value and requested length doesn't match!");
this.SetIntGenotype(bs); this.SetIntGenotype(bs);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for GAIndividualDoubleData is not double[]!"); System.out.println("Initial value for GAIndividualDoubleData is not double[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -279,11 +271,12 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
this.m_Genotype[mutationIndex] = RNG.randomInt(this.m_Range[mutationIndex][0], this.m_Range[mutationIndex][1]); this.m_Genotype[mutationIndex] = RNG.randomInt(this.m_Range[mutationIndex][0], this.m_Range[mutationIndex][1]);
} }
/** This method initializes the GA genotype randomly public void defaultInit(InterfaceOptimizationProblem prob) {
*/ int[][] range = m_Range;
public void defaultInit() { if (prob instanceof InterfaceHasInitRange && (((InterfaceHasInitRange)prob).getInitRange()!=null)) range = (int[][])((InterfaceHasInitRange)prob).getInitRange();
for (int i = 0; i < this.m_Genotype.length; i++) { for (int i = 0; i < this.m_Genotype.length; i++) {
this.m_Genotype[i] = RNG.randomInt(this.m_Range[i][0], this.m_Range[i][1]); this.m_Genotype[i] = RNG.randomInt(range[i][0], range[i][1]);
} }
} }

View File

@ -75,9 +75,9 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
((AbstractEAIndividual)this.m_Permutation).init(opt); ((AbstractEAIndividual)this.m_Permutation).init(opt);
} }
public void defaultInit() { public void defaultInit(InterfaceOptimizationProblem prob) {
((AbstractEAIndividual)this.m_Integer).defaultInit(); ((AbstractEAIndividual)this.m_Integer).defaultInit(prob);
((AbstractEAIndividual)this.m_Permutation).defaultInit(); ((AbstractEAIndividual)this.m_Permutation).defaultInit(prob);
} }
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the

View File

@ -193,15 +193,6 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
/************************************************************************************ /************************************************************************************
* InterfaceEAIndividual methods * InterfaceEAIndividual methods
*/ */
/** This method will allow a default initialisation of the individual
* @param opt The optimization problem that is to be solved.
*/
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
* @param obj The initial value for the phenotype * @param obj The initial value for the phenotype
@ -211,7 +202,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
if (obj instanceof InterfaceProgram[]) { if (obj instanceof InterfaceProgram[]) {
this.SetProgramGenotype((InterfaceProgram[])obj); this.SetProgramGenotype((InterfaceProgram[])obj);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for GPIndividualDoubleData is no InterfaceProgram[]!"); System.out.println("Initial value for GPIndividualDoubleData is no InterfaceProgram[]!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -271,7 +262,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
this.m_Genotype[i].addNodesTo(allNodes); this.m_Genotype[i].addNodesTo(allNodes);
AbstractGPNode nodeToMutate = (AbstractGPNode) allNodes.get(RNG.randomInt(0, allNodes.size()-1)); AbstractGPNode nodeToMutate = (AbstractGPNode) allNodes.get(RNG.randomInt(0, allNodes.size()-1));
if (nodeToMutate.getParent() == null) { if (nodeToMutate.getParent() == null) {
this.defaultInit(); this.defaultInit(null);
} else { } else {
AbstractGPNode parent = nodeToMutate.getParent(); AbstractGPNode parent = nodeToMutate.getParent();
AbstractGPNode newNode = (AbstractGPNode)(((AbstractGPNode)this.m_Area[i].getRandomNode().clone())); AbstractGPNode newNode = (AbstractGPNode)(((AbstractGPNode)this.m_Area[i].getRandomNode().clone()));
@ -282,9 +273,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
} }
} }
/** This method initializes the program public void defaultInit(InterfaceOptimizationProblem prob) {
*/
public void defaultInit() {
for (int i = 0; i < this.m_Area.length; i++) { for (int i = 0; i < this.m_Area.length; i++) {
if (this.m_Area[i] == null) { if (this.m_Area[i] == null) {
EVAERROR.errorMsgOnce("Error in GPIndividualProgramData.defaultInit(): Area["+i+"] == null !!"); EVAERROR.errorMsgOnce("Error in GPIndividualProgramData.defaultInit(): Area["+i+"] == null !!");

View File

@ -91,12 +91,6 @@ public class OBGAIndividualPermutationData extends AbstractEAIndividual implemen
* AbstractEAIndividual methods * AbstractEAIndividual methods
*/ */
public void init(InterfaceOptimizationProblem opt) {
this.defaultInit();
this.m_MutationOperator.init(this, opt);
this.m_CrossoverOperator.init(this, opt);
}
/** This method will init the individual with a given value for the /** This method will init the individual with a given value for the
* phenotype. * phenotype.
* @param obj The initial value for the phenotype * @param obj The initial value for the phenotype
@ -106,7 +100,7 @@ public class OBGAIndividualPermutationData extends AbstractEAIndividual implemen
if (obj instanceof int[]) { if (obj instanceof int[]) {
this.SetPermutationGenotype((int[][]) obj); this.SetPermutationGenotype((int[][]) obj);
} else { } else {
this.defaultInit(); this.defaultInit(opt);
System.out.println("Initial value for OBGAIndividualBinaryData is no Permutation!"); System.out.println("Initial value for OBGAIndividualBinaryData is no Permutation!");
} }
this.m_MutationOperator.init(this, opt); this.m_MutationOperator.init(this, opt);
@ -180,8 +174,7 @@ public class OBGAIndividualPermutationData extends AbstractEAIndividual implemen
this.SetPermutationGenotype(permmatrix); this.SetPermutationGenotype(permmatrix);
} }
/*generates a random permutation */ public void defaultInit(InterfaceOptimizationProblem prob){
public void defaultInit(){
//System.out.println("Default Init!"); //System.out.println("Default Init!");
int[][] perm = new int[this.m_Genotype.length][]; int[][] perm = new int[this.m_Genotype.length][];
for (int p = 0; p < perm.length; p++) { for (int p = 0; p < perm.length; p++) {

View File

@ -216,10 +216,10 @@ public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable
indy4 = (ESIndividualDoubleData)indy1.clone(); indy4 = (ESIndividualDoubleData)indy1.clone();
if (false) { if (false) {
// random init // random init
indy1.defaultInit(); indy1.defaultInit(prob);
indy2.defaultInit(); indy2.defaultInit(prob);
indy3.defaultInit(); indy3.defaultInit(prob);
indy4.defaultInit(); indy4.defaultInit(prob);
} else { } else {
// value init // value init
tmpD[0] = 0; tmpD[0] = 0;

View File

@ -130,9 +130,9 @@ public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable
indy3 = (ESIndividualDoubleData)indy1.clone(); indy3 = (ESIndividualDoubleData)indy1.clone();
if (false) { if (false) {
// random init // random init
indy1.defaultInit(); indy1.defaultInit(prob);
indy2.defaultInit(); indy2.defaultInit(prob);
indy3.defaultInit(); indy3.defaultInit(prob);
} else { } else {
// value init // value init
tmpD[0] = 0.5; tmpD[0] = 0.5;

View File

@ -145,10 +145,10 @@ public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable
indy4 = (ESIndividualDoubleData)indy1.clone(); indy4 = (ESIndividualDoubleData)indy1.clone();
if (false) { if (false) {
// random init // random init
indy1.defaultInit(); indy1.defaultInit(prob);
indy2.defaultInit(); indy2.defaultInit(prob);
indy3.defaultInit(); indy3.defaultInit(prob);
indy4.defaultInit(); indy4.defaultInit(prob);
} else { } else {
// value init // value init
tmpD[0] = -1; tmpD[0] = -1;

View File

@ -205,10 +205,10 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
indy4 = (ESIndividualDoubleData)indy1.clone(); indy4 = (ESIndividualDoubleData)indy1.clone();
if (false) { if (false) {
// random init // random init
indy1.defaultInit(); indy1.defaultInit(prob);
indy2.defaultInit(); indy2.defaultInit(prob);
indy3.defaultInit(); indy3.defaultInit(prob);
indy4.defaultInit(); indy4.defaultInit(prob);
} else { } else {
// value init // value init
tmpD[0] = -1.9; tmpD[0] = -1.9;

View File

@ -0,0 +1,97 @@
package eva2.server.go.operators.mutation;
import java.io.Serializable;
import eva2.gui.GenericObjectEditor;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.individuals.InterfaceGAIndividual;
import eva2.server.go.populations.Population;
import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.tools.EVAERROR;
import eva2.tools.math.RNG;
/**
* Uniform mutation mutates every GA bit with a fixed probability.
*
* @author mkron
*
*/
public class MutateGAUniform implements InterfaceMutation, Serializable {
double bitwiseProb = 0.1;
private boolean useInvertedLength = true;
public MutateGAUniform() {}
public MutateGAUniform(MutateGAUniform o) {
setBitwiseProb(o.getBitwiseProb());
}
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1,
Population partners) {
if (indy1.getMutationOperator() instanceof MutateGAUniform) {
MutateGAUniform mute = (MutateGAUniform)indy1.getMutationOperator();
double smallerProb, largerProb;
smallerProb = Math.min(getBitwiseProb(), mute.getBitwiseProb());
largerProb = Math.max(getBitwiseProb(), mute.getBitwiseProb());
setBitwiseProb(RNG.randomDouble(smallerProb, largerProb));
}
}
public Object clone() {
return new MutateGAUniform(this);
}
public void hideHideable() {
setUseInvertedLength(isUseInvertedLength());
}
public String getStringRepresentation() {
return "Uniform GA mutation (" + getBitwiseProb() + ")";
}
public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) {
if (useInvertedLength && (individual instanceof InterfaceGAIndividual)) setBitwiseProb(((InterfaceGAIndividual)individual).getGenotypeLength());
}
/**
* Flip every bit with a certain probability.
*/
public void mutate(AbstractEAIndividual individual) {
if (individual instanceof InterfaceGAIndividual) {
InterfaceGAIndividual indy = (InterfaceGAIndividual)individual;
for (int i=0; i<indy.getGenotypeLength(); i++) {
if (RNG.flipCoin(bitwiseProb)) indy.getBGenotype().flip(i);
}
} else EVAERROR.errorMsgOnce("Error: Skipped mutation since " + this.getClass() + " is applicable for InterfaceGAIndividual individuals only! (pot. multiple occ.)");
}
public double getBitwiseProb() {
return bitwiseProb;
}
public void setBitwiseProb(double bitwiseProb) {
this.bitwiseProb = bitwiseProb;
}
public String bitwiseProbTipText() {
return "The probability of every bit to be flipped.";
}
public void setUseInvertedLength(boolean useInvertedLength) {
this.useInvertedLength = useInvertedLength;
GenericObjectEditor.setHideProperty(this.getClass(), "bitwiseProb", useInvertedLength);
}
public boolean isUseInvertedLength() {
return useInvertedLength;
}
public String useInvertedLengthTipText() {
return "Switch for using 1/l as mutation rate.";
}
public String getName() {
return "Uniform-GA-Mutation";
}
public String globalInfo() {
return "Uniform mutation mutates every GA bit with a fixed probability.";
}
}

View File

@ -1054,7 +1054,7 @@ public class PostProcess {
for (int i=0; i<curPopSize; i++) { for (int i=0; i<curPopSize; i++) {
// fill pop randomly // fill pop randomly
indy = prob.getIndividualTemplate().getClone(); indy = prob.getIndividualTemplate().getClone();
indy.defaultInit(); indy.defaultInit(prob);
pop.add(indy); pop.add(indy);
} }
pop.synchSize(); pop.synchSize();

View File

@ -240,21 +240,21 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
firePropertyChangedEvent(Population.populationInitialized); firePropertyChangedEvent(Population.populationInitialized);
} }
/** This method inits the population. Function and generation counters // /** This method inits the population. Function and generation counters
* are reset and m_Size default Individuals are created and initialized by // * are reset and m_Size default Individuals are created and initialized by
* the GAIndividual default init() method. // * the GAIndividual default init() method.
*/ // */
public void defaultInit(AbstractEAIndividual template) { // public void defaultInit(AbstractEAIndividual template) { Were missing the optimization problem - thus no initial range can be specified. And since no one calls this method, I removed it for now
this.m_Generation = 0; // this.m_Generation = 0;
this.m_FunctionCalls = 0; // this.m_FunctionCalls = 0;
this.m_Archive = null; // this.m_Archive = null;
this.clear(); // this.clear();
for (int i = 0; i < this.m_TargetSize; i++) { // for (int i = 0; i < this.m_TargetSize; i++) {
AbstractEAIndividual tmpIndy = (AbstractEAIndividual)template.clone(); // AbstractEAIndividual tmpIndy = (AbstractEAIndividual)template.clone();
tmpIndy.defaultInit(); // tmpIndy.defaultInit(null);
super.add(tmpIndy); // super.add(tmpIndy);
} // }
} // }
/** /**
* Create a population instance which distributes the individuals according to * Create a population instance which distributes the individuals according to

View File

@ -184,7 +184,13 @@ public abstract class AbstractOptimizationProblem implements InterfaceOptimizati
*/ */
public abstract void evaluate(AbstractEAIndividual individual); public abstract void evaluate(AbstractEAIndividual individual);
/**
* The default initialization method. Clone the given template individual, calls its init method
* and add it to the population until the target size is reached. Earlier individuals are removed.
* @param population
* @param template
* @param prob
*/
public static void defaultInitPopulation(Population population, AbstractEAIndividual template, InterfaceOptimizationProblem prob) { public static void defaultInitPopulation(Population population, AbstractEAIndividual template, InterfaceOptimizationProblem prob) {
AbstractEAIndividual tmpIndy; AbstractEAIndividual tmpIndy;
population.clear(); population.clear();

View File

@ -1,6 +1,7 @@
package eva2.server.go.problems; package eva2.server.go.problems;
import eva2.server.go.strategies.InterfaceOptimizer; import eva2.server.go.strategies.InterfaceOptimizer;
import eva2.tools.math.Mathematics;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
@ -9,7 +10,9 @@ import eva2.server.go.strategies.InterfaceOptimizer;
* Time: 17:58:55 * Time: 17:58:55
* To change this template use Options | File Templates. * To change this template use Options | File Templates.
*/ */
public class F1Problem extends AbstractProblemDoubleOffset implements Interface2DBorderProblem, java.io.Serializable, InterfaceFirstOrderDerivableProblem { public class F1Problem extends AbstractProblemDoubleOffset implements Interface2DBorderProblem, InterfaceHasInitRange, java.io.Serializable, InterfaceFirstOrderDerivableProblem {
private double initialRangeRatio=1.; // reduce to initialize in a smaller subrange of the original range (in the corner box)
public F1Problem() { public F1Problem() {
super(); super();
setDefaultRange(10); setDefaultRange(10);
@ -93,4 +96,23 @@ public class F1Problem extends AbstractProblemDoubleOffset implements Interface2
} }
return grads; return grads;
} }
/**
* If initialRangeRatio<1, produce a reduced initial range in the negative corner of the range.
*/
public Object getInitRange() {
if (initialRangeRatio<1.) {
double[][] gR=makeRange();
double[][] initR = makeRange();
// double[] rng = Mathematics.shiftRange(initR);
Mathematics.scaleRange(initialRangeRatio, initR);
for (int i=0; i<getProblemDimension(); i++) {
double d=gR[i][0]-initR[i][0];
initR[i][0]+=d; // shift back by original offsets
initR[i][1]+=d;
}
// System.out.println(BeanInspector.toString(initR));
return initR;
} else return makeRange();
}
} }

View File

@ -2,13 +2,20 @@ package eva2.server.go.problems;
/** /**
* An interface for optimization problems having an extra initial range * An interface for optimization problems having an extra initial range
* opposed to the all-over problem range. * opposed to the global search range. This makes sense mainly for double
* * and integer data types such as ESIndividuals and GIIndividuals. For binary types,
* TODO generalize this! * the search range is defined by the bit length of the individual, respectively the
* dimension of the problem.
* *
* @author mkron * @author mkron
* *
*/ */
public interface InterfaceHasInitRange { public interface InterfaceHasInitRange {
public double[][] getInitRange(); /**
* The method should return the type expected by the individual type, e.g. double[][] or int[][].
* It may return null, in that case the global search range is used as initial range.
*
* @return An initial search range or null in case it is equal to the global search range.
*/
public Object getInitRange();
} }

View File

@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays;
import eva2.OptimizerFactory; import eva2.OptimizerFactory;
import eva2.OptimizerRunnable; import eva2.OptimizerRunnable;
@ -28,7 +29,7 @@ import eva2.server.stat.InterfaceTextListener;
* @author mkron * @author mkron
* *
*/ */
public class MatlabProblem extends AbstractOptimizationProblem implements InterfaceTextListener, Serializable { public class MatlabProblem extends AbstractOptimizationProblem implements InterfaceHasInitRange, InterfaceTextListener, Serializable {
private static final long serialVersionUID = 4913310869887420815L; private static final long serialVersionUID = 4913310869887420815L;
public static boolean TRACE = false; public static boolean TRACE = false;
transient OptimizerRunnable runnable = null; transient OptimizerRunnable runnable = null;
@ -42,6 +43,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
int verbosityLevel = 0; int verbosityLevel = 0;
private MatlabEvalMediator handler = null; private MatlabEvalMediator handler = null;
private boolean isDouble = true; private boolean isDouble = true;
private double[][] initialRange = null; // the initial range for double-valued problems
public static boolean hideFromGOE = true; public static boolean hideFromGOE = true;
@ -59,6 +61,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
// if (o.res != null) if (o.res.get() != null) res.set(o.res.get()); // if (o.res != null) if (o.res.get() != null) res.set(o.res.get());
this.range = o.range; this.range = o.range;
this.isDouble = o.isDouble; this.isDouble = o.isDouble;
this.initialRange = o.initialRange;
// this.mtCmd = o.mtCmd; // this.mtCmd = o.mtCmd;
// currArray = null; // currArray = null;
} }
@ -72,7 +75,11 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
} }
public MatlabProblem(int dim, double[][] range) { public MatlabProblem(int dim, double[][] range) {
init(dim, range, defTestOut); init(dim, range, null, defTestOut);
}
public MatlabProblem(int dim, double[][] range, double[][] initRange) {
init(dim, range, initRange, defTestOut);
} }
public MatlabProblem(int dim, double lower, double upper) { public MatlabProblem(int dim, double lower, double upper) {
@ -112,13 +119,36 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
} }
public void initProblem() { public void initProblem() {
init(this.problemDimension, range, defTestOut); init(this.problemDimension, range, initialRange, defTestOut);
} }
private void init(int dim, double[][] rng, String outFile) { /**
problemDimension = dim; * Make deep clones for the ranges, or there may be deadlocks in communicating with Matlab!
*
* @param dim
* @param globalRange
* @param initRange
* @param outFile
*/
private void init(int dim, double[][] globalRange, double[][] initRange, String outFile) {
this.problemDimension = dim;
// if ((rng != null) && (dim != rng.length)) throw new ArrayIndexOutOfBoundsException("Mismatching dimension and range!"); // if ((rng != null) && (dim != rng.length)) throw new ArrayIndexOutOfBoundsException("Mismatching dimension and range!");
range = rng; if (globalRange!=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.range = new double[globalRange.length][globalRange[0].length];
for (int i=0; i<this.range.length; i++) {
for (int j=0; j<this.range[0].length; j++) this.range[i][j]=globalRange[i][j];
}
} 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
this.initialRange = new double[initRange.length][initRange[0].length];
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];
}
} else this.initialRange=null;
if (Arrays.deepEquals(initialRange, range)) initialRange=null;
if (range==null) isDouble = false; if (range==null) isDouble = false;
else isDouble = true; else isDouble = true;
@ -128,6 +158,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
// res = new ResultArr(); // res = new ResultArr();
setDebugOut(TRACE, defTestOut); setDebugOut(TRACE, defTestOut);
log("Initial range is " + BeanInspector.toString(initialRange) + "\n");
// log("range is " + BeanInspector.toString(range)+ "\n"); // log("range is " + BeanInspector.toString(range)+ "\n");
// log("template len: " + ((ESIndividualDoubleData)m_Template).getDGenotype().length + "\n"); // log("template len: " + ((ESIndividualDoubleData)m_Template).getDGenotype().length + "\n");
@ -448,4 +479,9 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
//sb.append("\n"); //sb.append("\n");
return sb.toString(); return sb.toString();
} }
public Object getInitRange() {
log("retrieving initial range..., first entry: " + ((initialRange==null) ? "null" : BeanInspector.toString(initialRange[0])));
return initialRange;
}
} }

View File

@ -132,7 +132,7 @@ public class FloodAlgorithm implements InterfaceOptimizer, java.io.Serializable
public void defaultInit() { public void defaultInit() {
this.m_FitnessCallsNeeded = 0; this.m_FitnessCallsNeeded = 0;
this.m_Best = new GAIndividualBinaryData(); this.m_Best = new GAIndividualBinaryData();
this.m_Best.defaultInit(); this.m_Best.defaultInit(m_Problem);
} }
/** This method will optimize /** This method will optimize

View File

@ -76,13 +76,17 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
} }
/** /**
* This method will optimize without specific operators, by just calling the problem method * This method will optimize without specific operators, by just calling the individual method
* for population initialization. * for initialization.
*/ */
public void optimize() { public void optimize() {
Population original = (Population)this.m_Population.clone(); Population original = (Population)this.m_Population.clone();
this.m_Problem.initPopulation(this.m_Population); // this.m_Problem.initPopulation(this.m_Population);
for (int i=0; i<m_Population.size(); i++) {
m_Population.getEAIndividual(i).defaultInit(null);
}
this.m_Population.SetFunctionCalls(original.getFunctionCalls()); this.m_Population.SetFunctionCalls(original.getFunctionCalls());
this.m_Problem.evaluate(this.m_Population); this.m_Problem.evaluate(this.m_Population);
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.m_Population.size(); i++) {
@ -111,7 +115,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
public void defaultInit() { public void defaultInit() {
this.m_FitnessCallsNeeded = 0; this.m_FitnessCallsNeeded = 0;
this.m_Best = new GAIndividualBinaryData(); this.m_Best = new GAIndividualBinaryData();
this.m_Best.defaultInit(); this.m_Best.defaultInit(m_Problem);
} }
/** This method will optimize /** This method will optimize
@ -119,7 +123,7 @@ public class MonteCarloSearch implements InterfaceOptimizer, java.io.Serializabl
public void defaultOptimize() { public void defaultOptimize() {
for (int i = 0; i < m_FitnessCalls; i++) { for (int i = 0; i < m_FitnessCalls; i++) {
this.m_Test = new GAIndividualBinaryData(); this.m_Test = new GAIndividualBinaryData();
this.m_Test.defaultInit(); this.m_Test.defaultInit(m_Problem);
if (this.m_Test.defaultEvaulateAsMiniBits() < this.m_Best.defaultEvaulateAsMiniBits()) this.m_Best = this.m_Test; if (this.m_Test.defaultEvaulateAsMiniBits() < this.m_Best.defaultEvaulateAsMiniBits()) this.m_Best = this.m_Test;
this.m_FitnessCallsNeeded = i; this.m_FitnessCallsNeeded = i;
if (this.m_Best.defaultEvaulateAsMiniBits() == 0) i = this.m_FitnessCalls +1; if (this.m_Best.defaultEvaulateAsMiniBits() == 0) i = this.m_FitnessCalls +1;

View File

@ -102,7 +102,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
transient final static String partTypeKey = "ParticleType"; transient final static String partTypeKey = "ParticleType";
public transient final static String partBestPosKey = "BestPosition"; public transient final static String partBestPosKey = "BestPosition";
transient final static String partBestFitKey = "BestFitness"; transient final static String partBestFitKey = "BestFitness";
transient final static String partVelKey = "Velocity"; public transient final static String partVelKey = "Velocity";
transient final static String multiSwTypeKey="MultiSwarmType"; transient final static String multiSwTypeKey="MultiSwarmType";
transient final static String multiSwSizeKey="MultiSwarmSize"; transient final static String multiSwSizeKey="MultiSwarmSize";
transient final static String indexKey="particleIndex"; transient final static String indexKey="particleIndex";
@ -569,7 +569,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
public static void resetIndividual(AbstractEAIndividual indy, double initialV) { public static void resetIndividual(AbstractEAIndividual indy, double initialV) {
if (indy instanceof InterfaceDataTypeDouble) { if (indy instanceof InterfaceDataTypeDouble) {
indy.setParents(null); indy.setParents(null);
indy.defaultInit(); indy.defaultInit(null);
indy.putData(partTypeKey, defaultType); // turn into default type indy.putData(partTypeKey, defaultType); // turn into default type
initIndividualDefaults(indy, initialV); initIndividualDefaults(indy, initialV);
initIndividualMemory(indy); initIndividualMemory(indy);

View File

@ -138,7 +138,7 @@ public class SimulatedAnnealing implements InterfaceOptimizer, java.io.Serializa
public void defaultInit() { public void defaultInit() {
this.m_FitnessCallsNeeded = 0; this.m_FitnessCallsNeeded = 0;
this.m_Best = new GAIndividualBinaryData(); this.m_Best = new GAIndividualBinaryData();
this.m_Best.defaultInit(); this.m_Best.defaultInit(m_Problem);
} }
/** This method will optimize /** This method will optimize

View File

@ -130,7 +130,7 @@ public class ThresholdAlgorithm implements InterfaceOptimizer, java.io.Serializa
public void defaultInit() { public void defaultInit() {
this.m_FitnessCallsNeeded = 0; this.m_FitnessCallsNeeded = 0;
this.m_Best = new GAIndividualBinaryData(); this.m_Best = new GAIndividualBinaryData();
this.m_Best.defaultInit(); this.m_Best.defaultInit(m_Problem);
} }
/** This method will optimize /** This method will optimize

View File

@ -207,7 +207,7 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
m_problem = (AbstractOptimizationProblem)problem; m_problem = (AbstractOptimizationProblem)problem;
range = null; range = null;
if (problem instanceof InterfaceHasInitRange) { if (problem instanceof InterfaceHasInitRange) {
initRange = ((InterfaceHasInitRange)problem).getInitRange(); initRange = (double[][])((InterfaceHasInitRange)problem).getInitRange();
} }
Population pop = new Population(1); Population pop = new Population(1);
problem.initPopulation(pop); problem.initPopulation(pop);

View File

@ -956,7 +956,7 @@ v[d] = cmin * v[d];
} }
} }
public void defaultInit() { public void defaultInit(InterfaceOptimizationProblem prob) {
// shouldnt be called as we are beyond the EvA framework in this class // shouldnt be called as we are beyond the EvA framework in this class
for (int i = 0; i < this.position.x.length; i++) { for (int i = 0; i < this.position.x.length; i++) {
this.position.x[0] = 0.; this.position.x[0] = 0.;