Convert most mutation strategies.

This commit is contained in:
Fabian Becker 2014-02-05 12:14:47 +01:00
parent 7e58bcf83c
commit 7232f818ce
19 changed files with 467 additions and 536 deletions

View File

@ -31,7 +31,7 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
this.m_NormalizationEnabled = d.m_NormalizationEnabled; this.m_NormalizationEnabled = d.m_NormalizationEnabled;
this.m_AvailableTargets = new InterfaceCrossover[d.m_AvailableTargets.length]; this.m_AvailableTargets = new InterfaceCrossover[d.m_AvailableTargets.length];
for (int i = 0; i < this.m_AvailableTargets.length; i++) { for (int i = 0; i < this.m_AvailableTargets.length; i++) {
//this.m_AvailableTargets[i] = (InterfaceMutation)d.m_AvailableTargets[i].clone(); //this.availableTargets[i] = (InterfaceMutation)d.availableTargets[i].clone();
this.m_AvailableTargets[i] = d.m_AvailableTargets[i]; this.m_AvailableTargets[i] = d.m_AvailableTargets[i];
} }
this.m_SelectedTargets = new InterfaceCrossover[d.m_SelectedTargets.length]; this.m_SelectedTargets = new InterfaceCrossover[d.m_SelectedTargets.length];

View File

@ -10,18 +10,14 @@ import java.util.ArrayList;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 20.05.2005
* Time: 13:53:46
* To change this template use File | Settings | File Templates.
*/ */
public class MutateEAMixer implements InterfaceMutation, java.io.Serializable { public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
private PropertyMutationMixer m_Mutators; private PropertyMutationMixer mutationMixer;
private boolean m_UseSelfAdaption = false; private boolean useSelfAdaption = false;
protected double m_Tau1 = 0.15; protected double tau1 = 0.15;
protected double m_LowerLimitChance = 0.05; protected double lowerLimitChance = 0.05;
public MutateEAMixer() { public MutateEAMixer() {
InterfaceMutation[] tmpList; InterfaceMutation[] tmpList;
@ -41,14 +37,14 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
System.out.println("Illegal access exception for " + (String) mutators.get(i)); System.out.println("Illegal access exception for " + (String) mutators.get(i));
} }
} }
this.m_Mutators = new PropertyMutationMixer(tmpList, false); this.mutationMixer = new PropertyMutationMixer(tmpList, false);
tmpList = new InterfaceMutation[2]; tmpList = new InterfaceMutation[2];
tmpList[0] = new MutateGINominal(); tmpList[0] = new MutateGINominal();
tmpList[1] = new MutateGIOrdinal(); tmpList[1] = new MutateGIOrdinal();
this.m_Mutators.setSelectedMutators(tmpList); this.mutationMixer.setSelectedMutators(tmpList);
this.m_Mutators.normalizeWeights(); this.mutationMixer.normalizeWeights();
this.m_Mutators.setDescriptiveString("Combining alternative mutation operators, please norm the weights!"); this.mutationMixer.setDescriptiveString("Combining alternative mutation operators, please norm the weights!");
this.m_Mutators.setWeightsLabel("Weigths"); this.mutationMixer.setWeightsLabel("Weigths");
} }
@ -58,7 +54,7 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
* @param mutators * @param mutators
*/ */
public MutateEAMixer(InterfaceMutation... mutators) { public MutateEAMixer(InterfaceMutation... mutators) {
this.m_Mutators = new PropertyMutationMixer(mutators, true); this.mutationMixer = new PropertyMutationMixer(mutators, true);
} }
public MutateEAMixer(InterfaceMutation m1, InterfaceMutation m2) { public MutateEAMixer(InterfaceMutation m1, InterfaceMutation m2) {
@ -70,10 +66,10 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
} }
public MutateEAMixer(MutateEAMixer mutator) { public MutateEAMixer(MutateEAMixer mutator) {
this.m_Mutators = (PropertyMutationMixer) mutator.m_Mutators.clone(); this.mutationMixer = (PropertyMutationMixer) mutator.mutationMixer.clone();
this.m_UseSelfAdaption = mutator.m_UseSelfAdaption; this.useSelfAdaption = mutator.useSelfAdaption;
this.m_Tau1 = mutator.m_Tau1; this.tau1 = mutator.tau1;
this.m_LowerLimitChance = mutator.m_LowerLimitChance; this.lowerLimitChance = mutator.lowerLimitChance;
} }
/** /**
@ -111,7 +107,7 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
InterfaceMutation[] mutators = this.m_Mutators.getSelectedMutators(); InterfaceMutation[] mutators = this.mutationMixer.getSelectedMutators();
for (int i = 0; i < mutators.length; i++) { for (int i = 0; i < mutators.length; i++) {
mutators[i].init(individual, opt); mutators[i].init(individual, opt);
} }
@ -125,22 +121,22 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
*/ */
@Override @Override
public void mutate(AbstractEAIndividual individual) { public void mutate(AbstractEAIndividual individual) {
this.m_Mutators.normalizeWeights(); this.mutationMixer.normalizeWeights();
double[] probs = this.m_Mutators.getWeights(); double[] probs = this.mutationMixer.getWeights();
if (this.m_UseSelfAdaption) { if (this.useSelfAdaption) {
for (int i = 0; i < probs.length; i++) { for (int i = 0; i < probs.length; i++) {
probs[i] *= Math.exp(this.m_Tau1 * RNG.gaussianDouble(1)); probs[i] *= Math.exp(this.tau1 * RNG.gaussianDouble(1));
if (probs[i] <= this.m_LowerLimitChance) { if (probs[i] <= this.lowerLimitChance) {
probs[i] = this.m_LowerLimitChance; probs[i] = this.lowerLimitChance;
} }
if (probs[i] >= 1) { if (probs[i] >= 1) {
probs[i] = 1; probs[i] = 1;
} }
} }
this.m_Mutators.normalizeWeights(); this.mutationMixer.normalizeWeights();
} }
InterfaceMutation[] mutators = this.m_Mutators.getSelectedMutators(); InterfaceMutation[] mutators = this.mutationMixer.getSelectedMutators();
double pointer = RNG.randomFloat(0, 1); double pointer = RNG.randomFloat(0, 1);
double dum = probs[0]; double dum = probs[0];
int index = 0; int index = 0;
@ -168,8 +164,8 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
*/ */
@Override @Override
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) { public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) {
for (int i = 0; i < this.m_Mutators.getSelectedMutators().length; i++) { for (int i = 0; i < this.mutationMixer.getSelectedMutators().length; i++) {
this.m_Mutators.getSelectedMutators()[i].crossoverOnStrategyParameters(indy1, partners); this.mutationMixer.getSelectedMutators()[i].crossoverOnStrategyParameters(indy1, partners);
} }
} }
@ -212,11 +208,11 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
* @param d The mutation operators. * @param d The mutation operators.
*/ */
public void setMutators(PropertyMutationMixer d) { public void setMutators(PropertyMutationMixer d) {
this.m_Mutators = d; this.mutationMixer = d;
} }
public PropertyMutationMixer getMutators() { public PropertyMutationMixer getMutators() {
return this.m_Mutators; return this.mutationMixer;
} }
public String mutatorsTipText() { public String mutatorsTipText() {
@ -229,11 +225,11 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
* @param d The mutation operator. * @param d The mutation operator.
*/ */
public void setUseSelfAdaption(boolean d) { public void setUseSelfAdaption(boolean d) {
this.m_UseSelfAdaption = d; this.useSelfAdaption = d;
} }
public boolean getUseSelfAdaption() { public boolean getUseSelfAdaption() {
return this.m_UseSelfAdaption; return this.useSelfAdaption;
} }
public String useSelfAdaptionTipText() { public String useSelfAdaptionTipText() {
@ -249,11 +245,11 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
if (d < 0) { if (d < 0) {
d = 0; d = 0;
} }
this.m_LowerLimitChance = d; this.lowerLimitChance = d;
} }
public double getLowerLimitChance() { public double getLowerLimitChance() {
return this.m_LowerLimitChance; return this.lowerLimitChance;
} }
public String lowerLimitChanceTipText() { public String lowerLimitChanceTipText() {
@ -269,11 +265,11 @@ public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
if (d < 0) { if (d < 0) {
d = 0; d = 0;
} }
this.m_Tau1 = d; this.tau1 = d;
} }
public double getTau1() { public double getTau1() {
return this.m_Tau1; return this.tau1;
} }
public String tau1TipText() { public String tau1TipText() {

View File

@ -23,12 +23,12 @@ import java.util.ArrayList;
* between successive mutation steps. * between successive mutation steps.
*/ */
public class MutateESCorrVector implements InterfaceMutation, java.io.Serializable { public class MutateESCorrVector implements InterfaceMutation, java.io.Serializable {
protected double m_scalingDev = 0.05; protected double scalingDev = 0.05;
protected double m_initialVelocity = 0.02; protected double initialVelocity = 0.02;
protected double m_LowerLimitStepSize = 0.0000001; protected double lowerLimitStepSize = 0.0000001;
protected double m_UpperLimitStepSize = 0.5; protected double upperLimitStepSize = 0.5;
protected double m_rotationDev = 15.; protected double rotationDev = 15.;
protected boolean m_checkConstraints = true; protected boolean checkConstraints = true;
public static final String vectorKey = "MutateESCorrVectorVector"; public static final String vectorKey = "MutateESCorrVectorVector";
public static final boolean TRACE = false; public static final boolean TRACE = false;
@ -51,10 +51,10 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
} }
public MutateESCorrVector(MutateESCorrVector mutator) { public MutateESCorrVector(MutateESCorrVector mutator) {
this.m_scalingDev = mutator.m_scalingDev; this.scalingDev = mutator.scalingDev;
this.m_initialVelocity = mutator.m_initialVelocity; this.initialVelocity = mutator.initialVelocity;
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize; this.lowerLimitStepSize = mutator.lowerLimitStepSize;
this.m_rotationDev = mutator.m_rotationDev; this.rotationDev = mutator.rotationDev;
} }
/** /**
@ -77,13 +77,13 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
public boolean equals(Object mutator) { public boolean equals(Object mutator) {
if (mutator instanceof MutateESCorrVector) { if (mutator instanceof MutateESCorrVector) {
MutateESCorrVector mut = (MutateESCorrVector) mutator; MutateESCorrVector mut = (MutateESCorrVector) mutator;
if (this.m_scalingDev != mut.m_scalingDev) { if (this.scalingDev != mut.scalingDev) {
return false; return false;
} }
if (this.m_initialVelocity != m_initialVelocity) { if (this.initialVelocity != initialVelocity) {
return false; return false;
} }
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) { if (this.lowerLimitStepSize != mut.lowerLimitStepSize) {
return false; return false;
} }
return true; return true;
@ -100,7 +100,7 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
double[] initVelocity = calcInitialVel(m_initialVelocity, ((InterfaceESIndividual) individual).getDoubleRange()); double[] initVelocity = calcInitialVel(initialVelocity, ((InterfaceESIndividual) individual).getDoubleRange());
individual.putData(vectorKey, initVelocity); individual.putData(vectorKey, initVelocity);
} }
@ -139,22 +139,22 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
double[] vel = (double[]) individual.getData(vectorKey); double[] vel = (double[]) individual.getData(vectorKey);
// mutate the velocity vector and write it back // mutate the velocity vector and write it back
if ((m_scalingDev > 0) || (m_rotationDev > 0)) { if ((scalingDev > 0) || (rotationDev > 0)) {
// for (int i = 0; i < vel.length; i++) { // for (int i = 0; i < vel.length; i++) {
// vel[i] += ((range[i][1] -range[i][0])/2)*RNG.gaussianDouble(this.mutationStepSize); // vel[i] += ((range[i][1] -range[i][0])/2)*RNG.gaussianDouble(this.mutationStepSize);
// } // }
double rotateRad = m_rotationDev * (Math.PI / 360.) * RNG.gaussianDouble(1.); double rotateRad = rotationDev * (Math.PI / 360.) * RNG.gaussianDouble(1.);
// rotate with a gaussian distribution of deviation rotationDeg // rotate with a gaussian distribution of deviation rotationDeg
Mathematics.rotateAllAxes(vel, rotateRad, false); // rotate Mathematics.rotateAllAxes(vel, rotateRad, false); // rotate
double rScale = Math.exp(RNG.gaussianDouble(m_scalingDev)); double rScale = Math.exp(RNG.gaussianDouble(scalingDev));
if ((m_LowerLimitStepSize > 0) || (m_UpperLimitStepSize > 0)) { if ((lowerLimitStepSize > 0) || (upperLimitStepSize > 0)) {
double stepLen = Mathematics.norm(vel); double stepLen = Mathematics.norm(vel);
if (m_LowerLimitStepSize > 0) { if (lowerLimitStepSize > 0) {
rScale = Math.max(rScale, m_LowerLimitStepSize / stepLen); rScale = Math.max(rScale, lowerLimitStepSize / stepLen);
} }
if (m_UpperLimitStepSize > 0) { if (upperLimitStepSize > 0) {
rScale = Math.min(rScale, m_UpperLimitStepSize / stepLen); rScale = Math.min(rScale, upperLimitStepSize / stepLen);
} }
} }
@ -173,7 +173,7 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
Mathematics.vvAdd(genes, vel, genes); Mathematics.vvAdd(genes, vel, genes);
// check the range // check the range
if (m_checkConstraints) { if (checkConstraints) {
Mathematics.projectToRange(genes, range); Mathematics.projectToRange(genes, range);
} }
@ -195,11 +195,11 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) { public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) {
ArrayList<Double> tmpList = new ArrayList<Double>(); ArrayList<Double> tmpList = new ArrayList<Double>();
if (indy1.getMutationOperator() instanceof MutateESCorrVector) { if (indy1.getMutationOperator() instanceof MutateESCorrVector) {
tmpList.add(new Double(((MutateESCorrVector) indy1.getMutationOperator()).m_scalingDev)); tmpList.add(new Double(((MutateESCorrVector) indy1.getMutationOperator()).scalingDev));
} }
for (int i = 0; i < partners.size(); i++) { for (int i = 0; i < partners.size(); i++) {
if (((AbstractEAIndividual) partners.get(i)).getMutationOperator() instanceof MutateESCorrVector) { if (((AbstractEAIndividual) partners.get(i)).getMutationOperator() instanceof MutateESCorrVector) {
tmpList.add(new Double(((MutateESCorrVector) ((AbstractEAIndividual) partners.get(i)).getMutationOperator()).m_scalingDev)); tmpList.add(new Double(((MutateESCorrVector) ((AbstractEAIndividual) partners.get(i)).getMutationOperator()).scalingDev));
} }
} }
double[] list = new double[tmpList.size()]; double[] list = new double[tmpList.size()];
@ -210,7 +210,7 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
return; return;
} }
// discreete mutation for step size // discreete mutation for step size
this.m_scalingDev = list[RNG.randomInt(0, list.length - 1)]; this.scalingDev = list[RNG.randomInt(0, list.length - 1)];
} }
/** /**
@ -252,11 +252,11 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
* @param d The mutation operator. * @param d The mutation operator.
*/ */
public void setScalingDev(double d) { public void setScalingDev(double d) {
this.m_scalingDev = d; this.scalingDev = d;
} }
public double getScalingDev() { public double getScalingDev() {
return this.m_scalingDev; return this.scalingDev;
} }
public String scalingDevTipText() { public String scalingDevTipText() {
@ -272,11 +272,11 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
if (d < 0) { if (d < 0) {
d = 0; d = 0;
} }
this.m_LowerLimitStepSize = d; this.lowerLimitStepSize = d;
} }
public double getLowerLimitStepSize() { public double getLowerLimitStepSize() {
return this.m_LowerLimitStepSize; return this.lowerLimitStepSize;
} }
public String lowerLimitStepSizeTipText() { public String lowerLimitStepSizeTipText() {
@ -284,11 +284,11 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
} }
public double getRotationDev() { public double getRotationDev() {
return m_rotationDev; return rotationDev;
} }
public void setRotationDev(double rotationDeg) { public void setRotationDev(double rotationDeg) {
this.m_rotationDev = rotationDeg; this.rotationDev = rotationDeg;
} }
public String rotationDevTipText() { public String rotationDevTipText() {
@ -296,19 +296,19 @@ public class MutateESCorrVector implements InterfaceMutation, java.io.Serializab
} }
public double getInitialVelocity() { public double getInitialVelocity() {
return m_initialVelocity; return initialVelocity;
} }
public void setInitialVelocity(double velocity) { public void setInitialVelocity(double velocity) {
m_initialVelocity = velocity; initialVelocity = velocity;
} }
public double getUpperLimitStepSize() { public double getUpperLimitStepSize() {
return m_UpperLimitStepSize; return upperLimitStepSize;
} }
public void setUpperLimitStepSize(double upperLimitStepSize) { public void setUpperLimitStepSize(double upperLimitStepSize) {
m_UpperLimitStepSize = upperLimitStepSize; this.upperLimitStepSize = upperLimitStepSize;
} }
public String upperLimitStepSizeTipText() { public String upperLimitStepSizeTipText() {

View File

@ -132,70 +132,6 @@ public class MutateESCorrolated implements InterfaceMutation, java.io.Serializab
} }
} }
/**
* This method will mutate a given AbstractEAIndividual. If the individual
* doesn't implement InterfaceGAIndividual nothing happens.
*
* @param individual The individual that is to be mutated
*/
// public void mutate(AbstractEAIndividual individual) {
// if (individual instanceof InterfaceESIndividual) {
// double[] x = ((InterfaceESIndividual)individual).getDGenotype();
// double[] xCopy = ((InterfaceESIndividual)individual).getDGenotype();
// double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
// double tmpR = RNG.gaussianDouble(1);
// if (this.sigmas == null) {
// // init the Sigmas
// this.sigmas = new double[x.length];
// for (int i = 0; i < this.sigmas.length; i++) this.sigmas[i] = this.mutationStepSize;
// }
//
// //Mutate Sigmas
// for (int i = 0; i < x.length; i++) {
// this.sigmas[i] = this.sigmas[i] * Math.exp(this.tau1 * tmpR + this.tau2 * RNG.gaussianDouble(1));
// if (this.sigmas[i] < this.lowerLimitStepSize) this.sigmas[i] = this.lowerLimitStepSize;
// }
//
//// if (this.alphas == null) {
//// // init the Alphas
//// this.alphas = new double[(x.length*(x.length-1))/2];
//// for (int i = 0; i < this.alphas.length; i++) this.alphas[i] = 0.0;
//// }
//
//// //Mutate Alphas
//// for (int i = 0; i < this.alphas.length; i++) {
//// this.alphas[i] = this.alphas[i] + RNG.gaussianDouble(0.01);
//// if (this.alphas[i] < -m_PI/2) this.alphas[i] = -m_PI/2;
//// if (this.alphas[i] > m_PI/2) this.alphas[i] = m_PI/2;
//// }
//
// //Generate mutationvector in unitspace modified by sigmas
// for (int i = 0; i < x.length; i++) {
// xCopy[i] = RNG.gaussianDouble(this.sigmas[i]);
// }
//
// //modify genotype
// for (int i = 0; i < x.length; i++) {
// x[i] += ((range[i][1] -range[i][0])/2)*xCopy[i];
// if (range[i][0] > x[i]) x[i] = range[i][0];
// if (range[i][1] < x[i]) x[i] = range[i][1];
// }
//
// ((InterfaceESIndividual)individual).setDGenotype(x);
//
// //turn mutationvector with alphas
//// for (int i = 0; i < x.length-1; i++) {
//// for (int j = i+1; j < x.length; j++) {
//// double alpha=this.getAlpha(i,j, x.length);
//// double xX=java.lang.Math.cos(alpha)*xCopy[i]-java.lang.Math.sin(alpha)*xCopy[j];
//// double xY=java.lang.Math.sin(alpha)*xCopy[i]+java.lang.Math.cos(alpha)*xCopy[j];
//// xCopy[i]=xX;
//// xCopy[j]=xY;
//// }
//// }
//
// }
// }
@Override @Override
public void mutate(AbstractEAIndividual individual) { public void mutate(AbstractEAIndividual individual) {
if (individual instanceof InterfaceESIndividual) { if (individual instanceof InterfaceESIndividual) {

View File

@ -19,39 +19,39 @@ import eva2.tools.math.RNG;
public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java.io.Serializable { public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java.io.Serializable {
protected int m_D; protected int D;
protected double[] m_Z; protected double[] Z;
protected double m_SigmaGlobal = 1; protected double sigmaGlobal = 1;
protected double m_InitSigmaScalar = -1; protected double initSigmaScalar = -1;
protected double m_c; protected double c;
protected double cu; protected double cu;
protected double cov; protected double cov;
protected double Beta; protected double Beta;
protected double[] s_N; protected double[] s_N;
protected double[] m_PathS; protected double[] pathS;
protected double[] Bz; protected double[] Bz;
protected double xi_dach; protected double xi_dach;
protected Matrix m_C; protected Matrix C;
protected Matrix B; protected Matrix B;
protected boolean m_CheckConstraints = false; protected boolean checkConstraints = false;
protected int m_constraintMaxTries = 50; protected int constraintMaxTries = 50;
protected int m_Counter; protected int counter;
protected int m_frequency = 1; protected int frequency = 1;
protected double[] m_Eigenvalues; protected double[] eigenValues;
public MutateESCovarianceMatrixAdaption() { public MutateESCovarianceMatrixAdaption() {
} }
public MutateESCovarianceMatrixAdaption(MutateESCovarianceMatrixAdaption mutator) { public MutateESCovarianceMatrixAdaption(MutateESCovarianceMatrixAdaption mutator) {
this.m_Counter = mutator.m_Counter; this.counter = mutator.counter;
this.m_frequency = mutator.m_frequency; this.frequency = mutator.frequency;
this.m_InitSigmaScalar = mutator.m_InitSigmaScalar; this.initSigmaScalar = mutator.initSigmaScalar;
this.m_constraintMaxTries = mutator.m_constraintMaxTries; this.constraintMaxTries = mutator.constraintMaxTries;
this.m_CheckConstraints = mutator.m_CheckConstraints; this.checkConstraints = mutator.checkConstraints;
this.m_D = mutator.m_D; this.D = mutator.D;
this.m_SigmaGlobal = mutator.m_SigmaGlobal; this.sigmaGlobal = mutator.sigmaGlobal;
this.m_c = mutator.m_c; this.c = mutator.c;
this.cu = mutator.cu; this.cu = mutator.cu;
this.cov = mutator.cov; this.cov = mutator.cov;
this.Beta = mutator.Beta; this.Beta = mutator.Beta;
@ -59,23 +59,23 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
if (mutator.s_N != null) { if (mutator.s_N != null) {
this.s_N = (double[]) mutator.s_N.clone(); this.s_N = (double[]) mutator.s_N.clone();
} }
if (mutator.m_PathS != null) { if (mutator.pathS != null) {
this.m_PathS = (double[]) mutator.m_PathS.clone(); this.pathS = (double[]) mutator.pathS.clone();
} }
if (mutator.Bz != null) { if (mutator.Bz != null) {
this.Bz = (double[]) mutator.Bz.clone(); this.Bz = (double[]) mutator.Bz.clone();
} }
if (mutator.m_C != null) { if (mutator.C != null) {
this.m_C = (Matrix) mutator.m_C.clone(); this.C = (Matrix) mutator.C.clone();
} }
if (mutator.B != null) { if (mutator.B != null) {
this.B = (Matrix) mutator.B.clone(); this.B = (Matrix) mutator.B.clone();
} }
if (mutator.m_Z != null) { if (mutator.Z != null) {
this.m_Z = (double[]) mutator.m_Z.clone(); this.Z = (double[]) mutator.Z.clone();
} }
if (mutator.m_Eigenvalues != null) { if (mutator.eigenValues != null) {
this.m_Eigenvalues = (double[]) mutator.m_Eigenvalues.clone(); this.eigenValues = (double[]) mutator.eigenValues.clone();
} }
} }
@ -113,11 +113,11 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
MutateESCovarianceMatrixAdaption mut = (MutateESCovarianceMatrixAdaption) mutator; MutateESCovarianceMatrixAdaption mut = (MutateESCovarianceMatrixAdaption) mutator;
// i assume if the C Matrix is equal then the mutation operators are equal // i assume if the C Matrix is equal then the mutation operators are equal
try { try {
if (this.m_C == mut.m_C) { if (this.C == mut.C) {
return true; return true;
} }
double[][] c1 = this.m_C.getArray(); double[][] c1 = this.C.getArray();
double[][] c2 = mut.m_C.getArray(); double[][] c2 = mut.C.getArray();
if (c1 == c2) { if (c1 == c2) {
return true; return true;
} }
@ -151,32 +151,32 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
double[] x = ((InterfaceESIndividual) individual).getDGenotype(); double[] x = ((InterfaceESIndividual) individual).getDGenotype();
double[][] ranges = ((InterfaceESIndividual) individual).getDoubleRange(); double[][] ranges = ((InterfaceESIndividual) individual).getDoubleRange();
this.m_Counter = this.m_frequency; this.counter = this.frequency;
if (m_InitSigmaScalar > 0) { if (initSigmaScalar > 0) {
this.m_SigmaGlobal = this.m_InitSigmaScalar; this.sigmaGlobal = this.initSigmaScalar;
} else { } else {
double avgRange = Mathematics.getAvgRange(ranges); double avgRange = Mathematics.getAvgRange(ranges);
this.m_SigmaGlobal = 0.25 * avgRange; this.sigmaGlobal = 0.25 * avgRange;
} }
System.out.println("Init sigma: " + m_SigmaGlobal); System.out.println("Init sigma: " + sigmaGlobal);
this.m_D = x.length; this.D = x.length;
this.m_C = Matrix.identity(this.m_D, this.m_D); this.C = Matrix.identity(this.D, this.D);
EigenvalueDecomposition helper = new EigenvalueDecomposition(this.m_C); EigenvalueDecomposition helper = new EigenvalueDecomposition(this.C);
this.B = helper.getV(); this.B = helper.getV();
this.m_c = Math.sqrt(1.0 / (double) this.m_D); this.c = Math.sqrt(1.0 / (double) this.D);
this.cu = Math.sqrt((2.0 - this.m_c) / this.m_c); this.cu = Math.sqrt((2.0 - this.c) / this.c);
this.Beta = this.m_c; this.Beta = this.c;
this.cov = 2.0 / ((double) this.m_D * (double) this.m_D); this.cov = 2.0 / ((double) this.D * (double) this.D);
this.m_Z = new double[this.m_D]; this.Z = new double[this.D];
this.s_N = new double[this.m_D]; this.s_N = new double[this.D];
this.Bz = new double[this.m_D]; this.Bz = new double[this.D];
this.m_PathS = new double[this.m_D]; this.pathS = new double[this.D];
for (int i = 0; i < this.m_D; i++) { for (int i = 0; i < this.D; i++) {
this.s_N[i] = 0; this.s_N[i] = 0;
this.Bz[i] = 0; this.Bz[i] = 0;
this.m_PathS[i] = 0; this.pathS[i] = 0;
} }
this.xi_dach = Math.sqrt(this.m_D - 0.5); this.xi_dach = Math.sqrt(this.D - 0.5);
evaluateNewObjectX(x, ranges); evaluateNewObjectX(x, ranges);
} }
@ -223,36 +223,36 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
double Cij; double Cij;
double Bz_d; double Bz_d;
double pathLen = 0.0; double pathLen = 0.0;
for (int i = 0; i < this.m_D; i++) { for (int i = 0; i < this.D; i++) {
this.s_N[i] = (1.0 - this.m_c) * this.s_N[i] + this.m_c * this.cu * this.Bz[i]; this.s_N[i] = (1.0 - this.c) * this.s_N[i] + this.c * this.cu * this.Bz[i];
} }
// System.out.println("C bef:\n" + c.toString()); // System.out.println("C bef:\n" + c.toString());
// ADAPT COVARIANCE // ADAPT COVARIANCE
for (int i = 0; i < this.m_D; i++) { for (int i = 0; i < this.D; i++) {
for (int j = i; j < this.m_D; j++) { for (int j = i; j < this.D; j++) {
Cij = (1.0 - this.cov) * this.m_C.get(i, j) + this.cov * this.s_N[i] * this.s_N[j]; Cij = (1.0 - this.cov) * this.C.get(i, j) + this.cov * this.s_N[i] * this.s_N[j];
this.m_C.set(i, j, Cij); this.C.set(i, j, Cij);
this.m_C.set(j, i, Cij); this.C.set(j, i, Cij);
} }
} }
// System.out.println("C aft:\n" + c.toString()); // System.out.println("C aft:\n" + c.toString());
// ADAPT GLOBAL STEPSIZE // ADAPT GLOBAL STEPSIZE
for (int i = 0; i < this.m_D; i++) { for (int i = 0; i < this.D; i++) {
Bz_d = 0.0; Bz_d = 0.0;
for (int j = 0; j < this.m_D; j++) { for (int j = 0; j < this.D; j++) {
Bz_d += this.B.get(i, j) * this.m_Z[j]; Bz_d += this.B.get(i, j) * this.Z[j];
} }
this.m_PathS[i] = (1.0 - this.m_c) * this.m_PathS[i] + this.m_c * this.cu * Bz_d; this.pathS[i] = (1.0 - this.c) * this.pathS[i] + this.c * this.cu * Bz_d;
pathLen += this.m_PathS[i] * this.m_PathS[i]; pathLen += this.pathS[i] * this.pathS[i];
} }
this.m_SigmaGlobal *= Math.exp(this.Beta * this.m_c * (Math.sqrt(pathLen) - this.xi_dach)); this.sigmaGlobal *= Math.exp(this.Beta * this.c * (Math.sqrt(pathLen) - this.xi_dach));
} }
protected void evaluateNewObjectX(double[] x, double[][] range) { protected void evaluateNewObjectX(double[] x, double[][] range) {
// if (Double.isNaN((x[0]))) System.out.println("treffer in cma "+ x[0]); // if (Double.isNaN((x[0]))) System.out.println("treffer in cma "+ x[0]);
// if (Double.isNaN((c.get(0,0)))) System.out.println("treffer in cma"); // if (Double.isNaN((c.get(0,0)))) System.out.println("treffer in cma");
// for (int i=0;i<N;i++) { // evaluate new random values // for (int i=0;i<N;i++) { // evaluate new random values
// m_Z[i] = RNG.gaussianDouble(1.0); // Z[i] = RNG.gaussianDouble(1.0);
// } // }
// c = (c.plus(c.transpose()).times(0.5)); // MAKE C SYMMETRIC // c = (c.plus(c.transpose()).times(0.5)); // MAKE C SYMMETRIC
// EigenvalueDecomposition helper = new EigenvalueDecomposition(c); // EigenvalueDecomposition helper = new EigenvalueDecomposition(c);
@ -265,12 +265,12 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
// for (int i=0;i<N;i++) { // for (int i=0;i<N;i++) {
// Bz[i] = 0; // Bz[i] = 0;
// for (int j=0;j<N;j++) { // for (int j=0;j<N;j++) {
// Bz[i] = Bz[i] + Math.sqrt(Math.abs(Eigenvalues[j])) * B.get(i,j)*m_Z[j]; // Bz[i] = Bz[i] + Math.sqrt(Math.abs(Eigenvalues[j])) * B.get(i,j)*Z[j];
// } // }
// tmpD[i]=x[i]+m_SigmaScalar*Bz[i]; // here is the new value // tmpD[i]=x[i]+m_SigmaScalar*Bz[i]; // here is the new value
// } // }
// constraint = true; // constraint = true;
// if (this.m_CheckConstraints) { // if (this.checkConstraints) {
// for (int i=0;i<N;i++) { // for (int i=0;i<N;i++) {
// if ((tmpD[i]<range[i][0]) || (tmpD[i]>range[i][1])) constraint = false; // if ((tmpD[i]<range[i][0]) || (tmpD[i]>range[i][1])) constraint = false;
// } // }
@ -283,42 +283,42 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
// } // }
// for (int i = 0; i < N; i++) x[i] = tmpD[i]; // for (int i = 0; i < N; i++) x[i] = tmpD[i];
// conservation of mutation direction: // conservation of mutation direction:
//double[] oldZ = (double[]) this.m_Z.clone(); //double[] oldZ = (double[]) this.Z.clone();
double[] oldX = (double[]) x.clone(); double[] oldX = (double[]) x.clone();
for (int i = 0; i < this.m_D; i++) { for (int i = 0; i < this.D; i++) {
this.m_Z[i] = RNG.gaussianDouble(1.0); this.Z[i] = RNG.gaussianDouble(1.0);
} }
this.m_C = (this.m_C.plus(this.m_C.transpose()).times(0.5)); // MAKE C SYMMETRIC this.C = (this.C.plus(this.C.transpose()).times(0.5)); // MAKE C SYMMETRIC
this.m_Counter++; this.counter++;
if (this.m_Counter >= this.m_frequency) { if (this.counter >= this.frequency) {
EigenvalueDecomposition helper; EigenvalueDecomposition helper;
this.m_Counter = 0; this.counter = 0;
helper = new EigenvalueDecomposition(this.m_C); helper = new EigenvalueDecomposition(this.C);
this.B = helper.getV(); this.B = helper.getV();
this.m_Eigenvalues = helper.getRealEigenvalues(); this.eigenValues = helper.getRealEigenvalues();
} }
boolean isNewPosFeasible = false; boolean isNewPosFeasible = false;
int counter = 0; int counter = 0;
while (!isNewPosFeasible && counter < this.m_constraintMaxTries) { while (!isNewPosFeasible && counter < this.constraintMaxTries) {
for (int i = 0; i < this.m_D; i++) { for (int i = 0; i < this.D; i++) {
this.Bz[i] = 0; this.Bz[i] = 0;
for (int j = 0; j < this.m_D; j++) { for (int j = 0; j < this.D; j++) {
this.Bz[i] += Math.sqrt(Math.abs(this.m_Eigenvalues[j])) * this.B.get(i, j) * this.m_Z[j]; this.Bz[i] += Math.sqrt(Math.abs(this.eigenValues[j])) * this.B.get(i, j) * this.Z[j];
} }
x[i] += this.m_SigmaGlobal * this.Bz[i]; // here is the new value x[i] += this.sigmaGlobal * this.Bz[i]; // here is the new value
} }
isNewPosFeasible = true; isNewPosFeasible = true;
if (this.m_CheckConstraints == true) { if (this.checkConstraints == true) {
for (int i = 0; i < m_D; i++) { for (int i = 0; i < D; i++) {
if (x[i] < range[i][0] || x[i] > range[i][1]) { if (x[i] < range[i][0] || x[i] > range[i][1]) {
// undo the step and try new Z // undo the step and try new Z
for (int j = 0; j < this.m_D; j++) { for (int j = 0; j < this.D; j++) {
x[j] = oldX[j] - this.m_SigmaGlobal * this.Bz[j]; x[j] = oldX[j] - this.sigmaGlobal * this.Bz[j];
} }
this.m_SigmaGlobal *= 0.5; this.sigmaGlobal *= 0.5;
isNewPosFeasible = false; isNewPosFeasible = false;
counter++; counter++;
break; break;
@ -331,7 +331,7 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
// if (counter > 15) System.out.println(BeanInspector.toString(x)); // if (counter > 15) System.out.println(BeanInspector.toString(x));
// else System.out.println(); // else System.out.println();
} }
if (this.m_CheckConstraints && !isNewPosFeasible) { // use force if (this.checkConstraints && !isNewPosFeasible) { // use force
Mathematics.projectToRange(x, range); Mathematics.projectToRange(x, range);
// System.err.println("PROJECTING BY FORCE"); // System.err.println("PROJECTING BY FORCE");
} }
@ -375,11 +375,11 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
* @param bit The new representation for the inner constants. * @param bit The new representation for the inner constants.
*/ */
public void setCheckConstraints(boolean bit) { public void setCheckConstraints(boolean bit) {
this.m_CheckConstraints = bit; this.checkConstraints = bit;
} }
public boolean getCheckConstraints() { public boolean getCheckConstraints() {
return this.m_CheckConstraints; return this.checkConstraints;
} }
public String checkConstraintsTipText() { public String checkConstraintsTipText() {
@ -392,11 +392,11 @@ public class MutateESCovarianceMatrixAdaption implements InterfaceMutation, java
* @param d The initial sigma value. * @param d The initial sigma value.
*/ */
public void setInitSigmaScalar(double d) { public void setInitSigmaScalar(double d) {
this.m_InitSigmaScalar = d; this.initSigmaScalar = d;
} }
public double getInitSigmaScalar() { public double getInitSigmaScalar() {
return this.m_InitSigmaScalar; return this.initSigmaScalar;
} }
public String initSigmaScalarTipText() { public String initSigmaScalarTipText() {

View File

@ -9,12 +9,12 @@ import eva2.tools.math.Jama.Matrix;
public class MutateESCovarianceMatrixAdaptionPlus extends public class MutateESCovarianceMatrixAdaptionPlus extends
MutateESCovarianceMatrixAdaption implements InterfaceMutation, MutateESCovarianceMatrixAdaption implements InterfaceMutation,
InterfaceAdaptOperatorGenerational { InterfaceAdaptOperatorGenerational {
protected double m_psuccess; protected double psuccess;
protected double m_cp; protected double cp;
protected double m_psuccesstarget = 0.44; protected double psuccesstarget = 0.44;
protected double m_stepd; protected double stepd;
protected double m_pthresh; protected double pthresh;
protected int m_lambda = 1; protected int lambda = 1;
public MutateESCovarianceMatrixAdaptionPlus() { public MutateESCovarianceMatrixAdaptionPlus() {
super(); super();
@ -23,12 +23,12 @@ public class MutateESCovarianceMatrixAdaptionPlus extends
public MutateESCovarianceMatrixAdaptionPlus( public MutateESCovarianceMatrixAdaptionPlus(
MutateESCovarianceMatrixAdaptionPlus mutator) { MutateESCovarianceMatrixAdaptionPlus mutator) {
super(mutator); super(mutator);
m_psuccess = mutator.m_psuccess; psuccess = mutator.psuccess;
m_cp = mutator.m_cp; cp = mutator.cp;
m_psuccesstarget = mutator.m_psuccesstarget; psuccesstarget = mutator.psuccesstarget;
m_lambda = mutator.m_lambda; lambda = mutator.lambda;
m_pthresh = mutator.m_pthresh; pthresh = mutator.pthresh;
m_stepd = mutator.m_stepd; stepd = mutator.stepd;
} }
/** /**
@ -55,14 +55,14 @@ public class MutateESCovarianceMatrixAdaptionPlus extends
return; return;
} }
super.init(individual, opt); super.init(individual, opt);
m_psuccesstarget = 1.0 / (5 + Math.sqrt(m_lambda) / 2); psuccesstarget = 1.0 / (5 + Math.sqrt(lambda) / 2);
m_psuccess = m_psuccesstarget; psuccess = psuccesstarget;
m_stepd = 1.0 + m_D / (2.0 * m_lambda); stepd = 1.0 + D / (2.0 * lambda);
m_cp = m_psuccesstarget * m_lambda / (2 + m_psuccesstarget * m_lambda); cp = psuccesstarget * lambda / (2 + psuccesstarget * lambda);
m_c = 2.0 / (2.0 + m_D); c = 2.0 / (2.0 + D);
this.cov = 2.0 / (6.0 + Math.pow(m_D, 2)); // ATTN: differs from the this.cov = 2.0 / (6.0 + Math.pow(D, 2)); // ATTN: differs from the
// standard CMA-ES // standard CMA-ES
m_pthresh = 0.44; pthresh = 0.44;
} }
@ -82,8 +82,8 @@ public class MutateESCovarianceMatrixAdaptionPlus extends
*/ */
public void updateCovariance(AbstractEAIndividual child, public void updateCovariance(AbstractEAIndividual child,
AbstractEAIndividual parent) { AbstractEAIndividual parent) {
double[] step = new double[m_D]; double[] step = new double[D];
for (int i = 0; i < m_D; i++) { for (int i = 0; i < D; i++) {
step[i] = ((InterfaceESIndividual) parent).getDGenotype()[i] step[i] = ((InterfaceESIndividual) parent).getDGenotype()[i]
- ((InterfaceESIndividual) child).getDGenotype()[i]; - ((InterfaceESIndividual) child).getDGenotype()[i];
} }
@ -91,8 +91,8 @@ public class MutateESCovarianceMatrixAdaptionPlus extends
} }
public void updateCovariance() { public void updateCovariance() {
double[] step = new double[m_D]; double[] step = new double[D];
for (int i = 0; i < m_D; i++) { for (int i = 0; i < D; i++) {
step[i] = Bz[i]; step[i] = Bz[i];
} }
updateCovariance(step); updateCovariance(step);
@ -102,23 +102,23 @@ public class MutateESCovarianceMatrixAdaptionPlus extends
* @param step * @param step
*/ */
public void updateCovariance(double[] step) { public void updateCovariance(double[] step) {
for (int i = 0; i < m_D; i++) { for (int i = 0; i < D; i++) {
if (m_psuccess < m_pthresh) { if (psuccess < pthresh) {
m_PathS[i] = (1.0 - m_c) * m_PathS[i] pathS[i] = (1.0 - c) * pathS[i]
+ Math.sqrt(m_c * (2.0 - m_c)) * (step[i]) + Math.sqrt(c * (2.0 - c)) * (step[i])
/ m_SigmaGlobal; / sigmaGlobal;
} else { } else {
m_PathS[i] = (1.0 - m_c) * m_PathS[i]; pathS[i] = (1.0 - c) * pathS[i];
} }
} }
if (m_psuccess < m_pthresh) { if (psuccess < pthresh) {
m_C = m_C.multi((1.0 - cov)); C = C.multi((1.0 - cov));
m_C.plusEquals(Matrix.outer(m_PathS, m_PathS).multi(cov)); C.plusEquals(Matrix.outer(pathS, pathS).multi(cov));
} else { } else {
m_C = m_C.multi((1.0 - cov)).plus( C = C.multi((1.0 - cov)).plus(
(Matrix.outer(m_PathS, m_PathS).plus( (Matrix.outer(pathS, pathS).plus(
m_C.multi(m_c * (2.0 - m_c))).multi(cov))); C.multi(c * (2.0 - c))).multi(cov)));
} }
} }
@ -127,11 +127,11 @@ public class MutateESCovarianceMatrixAdaptionPlus extends
} }
public int getLambda() { public int getLambda() {
return m_lambda; return lambda;
} }
public void setLambda(int mLambda) { public void setLambda(int mLambda) {
m_lambda = mLambda; lambda = mLambda;
} }
@Override @Override
@ -203,13 +203,13 @@ public class MutateESCovarianceMatrixAdaptionPlus extends
} }
public double getPSuccess() { public double getPSuccess() {
return m_psuccess; return psuccess;
} }
public void updateStepSize(double psuccess) { public void updateStepSize(double psuccess) {
this.m_psuccess = (1 - m_cp) * m_psuccess + m_cp * psuccess; this.psuccess = (1 - cp) * this.psuccess + cp * psuccess;
m_SigmaGlobal *= Math.exp(1 / m_stepd * (m_psuccess - m_psuccesstarget) sigmaGlobal *= Math.exp(1 / stepd * (this.psuccess - psuccesstarget)
/ (1 - m_psuccesstarget)); / (1 - psuccesstarget));
} }
@Override @Override

View File

@ -205,10 +205,10 @@ public class MutateESMainVectorAdaption implements InterfaceMutation, java.io.Se
// boolean constraint = false; // boolean constraint = false;
// int counter = 0; // int counter = 0;
// while (constraint == false) { // while (constraint == false) {
// for (int i = 0; i < x.length; i++) x[i] = x[i] + m_SigmaScalar * (m_Z[i] + Z1 * w_v * m_main_v[i]); // for (int i = 0; i < x.length; i++) x[i] = x[i] + m_SigmaScalar * (Z[i] + Z1 * w_v * m_main_v[i]);
// constraint = true; // constraint = true;
// if (counter++ > 30) break; // if (counter++ > 30) break;
// if (m_CheckConstraints == true) { // if (checkConstraints == true) {
// for (int i = 0; i < x.length; i++) { // for (int i = 0; i < x.length; i++) {
// if (x[i] < range[i][0]) x[i] = range[i][0]; // if (x[i] < range[i][0]) x[i] = range[i][0];
// if (x[i] > range[i][1]) x[i] = range[i][1]; // if (x[i] > range[i][1]) x[i] = range[i][1];

View File

@ -109,7 +109,7 @@ public class MutateESPathLengthAdaption implements InterfaceMutation, java.io.Se
double[] x = ((InterfaceESIndividual) individual).getDGenotype(); double[] x = ((InterfaceESIndividual) individual).getDGenotype();
double[][] ranges = ((InterfaceESIndividual) individual).getDoubleRange(); double[][] ranges = ((InterfaceESIndividual) individual).getDoubleRange();
this.m_dim = x.length; this.m_dim = x.length;
// if (this.m_UsePath) this.m_c = Math.sqrt(1.0 / (double) this.m_dim); // if (this.m_UsePath) this.c = Math.sqrt(1.0 / (double) this.m_dim);
this.m_randZ = new double[this.m_dim]; this.m_randZ = new double[this.m_dim];
this.m_Path = new double[this.m_dim]; this.m_Path = new double[this.m_dim];

View File

@ -511,7 +511,7 @@ public class MutateESRankMuCMA implements InterfaceAdaptOperatorGenerational, In
params.mC = (params.mC.plus(params.mC.transpose()).times(0.5)); // MAKE C SYMMETRIC params.mC = (params.mC.plus(params.mC.transpose()).times(0.5)); // MAKE C SYMMETRIC
EigenvalueDecomposition helper; EigenvalueDecomposition helper;
// this.m_Counter = 0; // this.counter = 0;
helper = new EigenvalueDecomposition(params.mC); helper = new EigenvalueDecomposition(params.mC);
params.mB = helper.getV(); // Return the eigenvector matrix params.mB = helper.getV(); // Return the eigenvector matrix
params.eigenvalues = helper.getRealEigenvalues(); params.eigenvalues = helper.getRealEigenvalues();

View File

@ -15,14 +15,14 @@ import eva2.tools.math.RNG;
*/ */
public class MutateGIInsertDelete implements InterfaceMutation, java.io.Serializable { public class MutateGIInsertDelete implements InterfaceMutation, java.io.Serializable {
int m_MaxLengthOfInsDel = 2; int maxLengthOfInsDel = 2;
public MutateGIInsertDelete() { public MutateGIInsertDelete() {
} }
public MutateGIInsertDelete(MutateGIInsertDelete mutator) { public MutateGIInsertDelete(MutateGIInsertDelete mutator) {
this.m_MaxLengthOfInsDel = mutator.m_MaxLengthOfInsDel; this.maxLengthOfInsDel = mutator.maxLengthOfInsDel;
} }
/** /**
@ -45,7 +45,7 @@ public class MutateGIInsertDelete implements InterfaceMutation, java.io.Serializ
public boolean equals(Object mutator) { public boolean equals(Object mutator) {
if (mutator instanceof MutateGIInsertDelete) { if (mutator instanceof MutateGIInsertDelete) {
MutateGIInsertDelete mut = (MutateGIInsertDelete) mutator; MutateGIInsertDelete mut = (MutateGIInsertDelete) mutator;
if (this.m_MaxLengthOfInsDel != mut.m_MaxLengthOfInsDel) { if (this.maxLengthOfInsDel != mut.maxLengthOfInsDel) {
return false; return false;
} }
return true; return true;
@ -92,7 +92,7 @@ public class MutateGIInsertDelete implements InterfaceMutation, java.io.Serializ
int[][] newRange; int[][] newRange;
int length, position; int length, position;
//this.pintInt("Before ", x); //this.pintInt("Before ", x);
length = RNG.randomInt(1, this.m_MaxLengthOfInsDel); length = RNG.randomInt(1, this.maxLengthOfInsDel);
boolean insert = RNG.flipCoin(0.5); boolean insert = RNG.flipCoin(0.5);
if ((!insert) && (length >= x.length - 1)) { if ((!insert) && (length >= x.length - 1)) {
insert = true; insert = true;
@ -184,11 +184,11 @@ public class MutateGIInsertDelete implements InterfaceMutation, java.io.Serializ
* @param n The max length of invert * @param n The max length of invert
*/ */
public void setMaxLengthOfInsDel(int n) { public void setMaxLengthOfInsDel(int n) {
this.m_MaxLengthOfInsDel = n; this.maxLengthOfInsDel = n;
} }
public int getMaxLengthOfInsDel() { public int getMaxLengthOfInsDel() {
return this.m_MaxLengthOfInsDel; return this.maxLengthOfInsDel;
} }
public String maxLengthOfInsDelTipText() { public String maxLengthOfInsDelTipText() {

View File

@ -15,14 +15,14 @@ import eva2.tools.math.RNG;
*/ */
public class MutateGIInvert implements InterfaceMutation, java.io.Serializable { public class MutateGIInvert implements InterfaceMutation, java.io.Serializable {
int m_MaxLengthOfInvert = 2; int maxLengthOfInvert = 2;
public MutateGIInvert() { public MutateGIInvert() {
} }
public MutateGIInvert(MutateGIInvert mutator) { public MutateGIInvert(MutateGIInvert mutator) {
this.m_MaxLengthOfInvert = mutator.m_MaxLengthOfInvert; this.maxLengthOfInvert = mutator.maxLengthOfInvert;
} }
/** /**
@ -45,7 +45,7 @@ public class MutateGIInvert implements InterfaceMutation, java.io.Serializable {
public boolean equals(Object mutator) { public boolean equals(Object mutator) {
if (mutator instanceof MutateGIInvert) { if (mutator instanceof MutateGIInvert) {
MutateGIInvert mut = (MutateGIInvert) mutator; MutateGIInvert mut = (MutateGIInvert) mutator;
if (this.m_MaxLengthOfInvert != mut.m_MaxLengthOfInvert) { if (this.maxLengthOfInvert != mut.maxLengthOfInvert) {
return false; return false;
} }
return true; return true;
@ -77,7 +77,7 @@ public class MutateGIInvert implements InterfaceMutation, java.io.Serializable {
int[] x = ((InterfaceGIIndividual) individual).getIGenotype(); int[] x = ((InterfaceGIIndividual) individual).getIGenotype();
int range, center, index = 0; int range, center, index = 0;
//this.pintInt("Before ", x); //this.pintInt("Before ", x);
range = RNG.randomInt(1, this.m_MaxLengthOfInvert); range = RNG.randomInt(1, this.maxLengthOfInvert);
if (2 * range >= x.length) { if (2 * range >= x.length) {
return; return;
} }
@ -154,11 +154,11 @@ public class MutateGIInvert implements InterfaceMutation, java.io.Serializable {
* @param n The max length of invert * @param n The max length of invert
*/ */
public void setMaxLengthOfInvert(int n) { public void setMaxLengthOfInvert(int n) {
this.m_MaxLengthOfInvert = n; this.maxLengthOfInvert = n;
} }
public int getMaxLengthOfInvert() { public int getMaxLengthOfInvert() {
return this.m_MaxLengthOfInvert; return this.maxLengthOfInvert;
} }
public String maxLengthOfInvertTipText() { public String maxLengthOfInvertTipText() {

View File

@ -15,14 +15,14 @@ import eva2.tools.math.RNG;
*/ */
public class MutateGINominal implements InterfaceMutation, java.io.Serializable { public class MutateGINominal implements InterfaceMutation, java.io.Serializable {
int m_NumberOfMutations = 2; int numberOfMutations = 2;
public MutateGINominal() { public MutateGINominal() {
} }
public MutateGINominal(MutateGINominal mutator) { public MutateGINominal(MutateGINominal mutator) {
this.m_NumberOfMutations = mutator.m_NumberOfMutations; this.numberOfMutations = mutator.numberOfMutations;
} }
/** /**
@ -45,7 +45,7 @@ public class MutateGINominal implements InterfaceMutation, java.io.Serializable
public boolean equals(Object mutator) { public boolean equals(Object mutator) {
if (mutator instanceof MutateGINominal) { if (mutator instanceof MutateGINominal) {
MutateGINominal mut = (MutateGINominal) mutator; MutateGINominal mut = (MutateGINominal) mutator;
if (this.m_NumberOfMutations != mut.m_NumberOfMutations) { if (this.numberOfMutations != mut.numberOfMutations) {
return false; return false;
} }
return true; return true;
@ -77,7 +77,7 @@ public class MutateGINominal implements InterfaceMutation, java.io.Serializable
int[] x = ((InterfaceGIIndividual) individual).getIGenotype(); int[] x = ((InterfaceGIIndividual) individual).getIGenotype();
int[][] range = ((InterfaceGIIndividual) individual).getIntRange(); int[][] range = ((InterfaceGIIndividual) individual).getIntRange();
int mutInd = 0; int mutInd = 0;
for (int k = 0; k < this.m_NumberOfMutations; k++) { for (int k = 0; k < this.numberOfMutations; k++) {
try { try {
mutInd = RNG.randomInt(0, x.length - 1); mutInd = RNG.randomInt(0, x.length - 1);
} catch (java.lang.ArithmeticException e) { } catch (java.lang.ArithmeticException e) {
@ -140,11 +140,11 @@ public class MutateGINominal implements InterfaceMutation, java.io.Serializable
* @param n The number of mutations * @param n The number of mutations
*/ */
public void setNumberOfMutations(int n) { public void setNumberOfMutations(int n) {
this.m_NumberOfMutations = n; this.numberOfMutations = n;
} }
public int getNumberOfMutations() { public int getNumberOfMutations() {
return this.m_NumberOfMutations; return this.numberOfMutations;
} }
public String numberOfMutationsTipText() { public String numberOfMutationsTipText() {

View File

@ -15,16 +15,16 @@ import eva2.tools.math.RNG;
*/ */
public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable { public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable {
double m_StepSize = 0.1; double stepSize = 0.1;
int m_NumberOfMutations = 2; int numberOfMutations = 2;
public MutateGIOrdinal() { public MutateGIOrdinal() {
} }
public MutateGIOrdinal(MutateGIOrdinal mutator) { public MutateGIOrdinal(MutateGIOrdinal mutator) {
this.m_StepSize = mutator.m_StepSize; this.stepSize = mutator.stepSize;
this.m_NumberOfMutations = mutator.m_NumberOfMutations; this.numberOfMutations = mutator.numberOfMutations;
} }
/** /**
@ -47,10 +47,10 @@ public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable
public boolean equals(Object mutator) { public boolean equals(Object mutator) {
if (mutator instanceof MutateGIOrdinal) { if (mutator instanceof MutateGIOrdinal) {
MutateGIOrdinal mut = (MutateGIOrdinal) mutator; MutateGIOrdinal mut = (MutateGIOrdinal) mutator;
if (this.m_StepSize != mut.m_StepSize) { if (this.stepSize != mut.stepSize) {
return false; return false;
} }
if (this.m_NumberOfMutations != mut.m_NumberOfMutations) { if (this.numberOfMutations != mut.numberOfMutations) {
return false; return false;
} }
return true; return true;
@ -83,9 +83,9 @@ public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable
int[][] range = ((InterfaceGIIndividual) individual).getIntRange(); int[][] range = ((InterfaceGIIndividual) individual).getIntRange();
int mutInd, mut; int mutInd, mut;
double mutate; double mutate;
for (int k = 0; k < this.m_NumberOfMutations; k++) { for (int k = 0; k < this.numberOfMutations; k++) {
mutInd = RNG.randomInt(0, x.length - 1); mutInd = RNG.randomInt(0, x.length - 1);
mutate = RNG.gaussianDouble(this.m_StepSize); mutate = RNG.gaussianDouble(this.stepSize);
mutate *= (range[mutInd][1] - range[mutInd][1]); mutate *= (range[mutInd][1] - range[mutInd][1]);
mut = (int) Math.round(mutate); mut = (int) Math.round(mutate);
if (mut == 0) { if (mut == 0) {
@ -158,11 +158,11 @@ public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable
* @param n The step size * @param n The step size
*/ */
public void setStepSize(double n) { public void setStepSize(double n) {
this.m_StepSize = n; this.stepSize = n;
} }
public double getStepSize() { public double getStepSize() {
return this.m_StepSize; return this.stepSize;
} }
public String stepSizeTipText() { public String stepSizeTipText() {
@ -175,11 +175,11 @@ public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable
* @param n The number of mutations * @param n The number of mutations
*/ */
public void setNumberOfMutations(int n) { public void setNumberOfMutations(int n) {
this.m_NumberOfMutations = n; this.numberOfMutations = n;
} }
public int getNumberOfMutations() { public int getNumberOfMutations() {
return this.m_NumberOfMutations; return this.numberOfMutations;
} }
public String numberOfMutationsTipText() { public String numberOfMutationsTipText() {

View File

@ -16,8 +16,8 @@ import eva2.tools.math.RNG;
*/ */
public class MutateGITranslocate implements InterfaceMutation, java.io.Serializable { public class MutateGITranslocate implements InterfaceMutation, java.io.Serializable {
int m_MaxLengthOfTranslocate = 4; int maxLengthOfTranslocate = 4;
int m_maxTransLocDistance = -1; int maxTransLocDistance = -1;
public MutateGITranslocate() { public MutateGITranslocate() {
} }
@ -34,7 +34,7 @@ public class MutateGITranslocate implements InterfaceMutation, java.io.Serializa
} }
public MutateGITranslocate(MutateGITranslocate mutator) { public MutateGITranslocate(MutateGITranslocate mutator) {
this.m_MaxLengthOfTranslocate = mutator.m_MaxLengthOfTranslocate; this.maxLengthOfTranslocate = mutator.maxLengthOfTranslocate;
} }
/** /**
@ -57,7 +57,7 @@ public class MutateGITranslocate implements InterfaceMutation, java.io.Serializa
public boolean equals(Object mutator) { public boolean equals(Object mutator) {
if (mutator instanceof MutateGITranslocate) { if (mutator instanceof MutateGITranslocate) {
MutateGITranslocate mut = (MutateGITranslocate) mutator; MutateGITranslocate mut = (MutateGITranslocate) mutator;
if (this.m_MaxLengthOfTranslocate != mut.m_MaxLengthOfTranslocate) { if (this.maxLengthOfTranslocate != mut.maxLengthOfTranslocate) {
return false; return false;
} }
return true; return true;
@ -88,16 +88,16 @@ public class MutateGITranslocate implements InterfaceMutation, java.io.Serializa
if (individual instanceof InterfaceGIIndividual) { if (individual instanceof InterfaceGIIndividual) {
int[] x = ((InterfaceGIIndividual) individual).getIGenotype(); int[] x = ((InterfaceGIIndividual) individual).getIGenotype();
int from, to, length; int from, to, length;
length = RNG.randomInt(1, this.m_MaxLengthOfTranslocate); length = RNG.randomInt(1, this.maxLengthOfTranslocate);
if (x.length < length + 2) { if (x.length < length + 2) {
return; return;
} }
from = RNG.randomInt(0, x.length - 1 - length); from = RNG.randomInt(0, x.length - 1 - length);
if (m_maxTransLocDistance <= 0) { if (maxTransLocDistance <= 0) {
to = RNG.randomInt(0, x.length - 1 - length); to = RNG.randomInt(0, x.length - 1 - length);
} else { } else {
int minTo = Math.max(0, from - m_maxTransLocDistance); int minTo = Math.max(0, from - maxTransLocDistance);
int maxTo = Math.min(x.length - 1 - length, from + m_maxTransLocDistance); int maxTo = Math.min(x.length - 1 - length, from + maxTransLocDistance);
// System.out.println("min/max-to: " + minTo + ", " + maxTo); // System.out.println("min/max-to: " + minTo + ", " + maxTo);
to = RNG.randomInt(minTo, maxTo); to = RNG.randomInt(minTo, maxTo);
// System.out.println("to is " + to); // System.out.println("to is " + to);
@ -198,11 +198,11 @@ public class MutateGITranslocate implements InterfaceMutation, java.io.Serializa
* @param n The max length of invert * @param n The max length of invert
*/ */
public void setMaxLengthOfTranslocate(int n) { public void setMaxLengthOfTranslocate(int n) {
this.m_MaxLengthOfTranslocate = n; this.maxLengthOfTranslocate = n;
} }
public int getMaxLengthOfTranslocate() { public int getMaxLengthOfTranslocate() {
return this.m_MaxLengthOfTranslocate; return this.maxLengthOfTranslocate;
} }
public String maxLengthOfTranslocateTipText() { public String maxLengthOfTranslocateTipText() {
@ -215,11 +215,11 @@ public class MutateGITranslocate implements InterfaceMutation, java.io.Serializa
* @param n The max length of invert * @param n The max length of invert
*/ */
public void setMaxTranslocationDist(int n) { public void setMaxTranslocationDist(int n) {
this.m_maxTransLocDistance = n; this.maxTransLocDistance = n;
} }
public int getMaxTranslocationDist() { public int getMaxTranslocationDist() {
return this.m_maxTransLocDistance; return this.maxTransLocDistance;
} }
public String maxTranslocationDistTipText() { public String maxTranslocationDistTipText() {

View File

@ -16,20 +16,20 @@ import eva2.tools.math.RNG;
* To change this template use Options | File Templates. * To change this template use Options | File Templates.
*/ */
public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable { public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable {
protected double m_MutationStep = 1; protected double mutationStep = 1;
protected double m_Tau1 = 0.15; protected double tau1 = 0.15;
protected double m_Tau2 = 0.15; protected double tau2 = 0.15;
protected double m_LowerLimitStepSize = 0.0000005; protected double lowerLimitStepSize = 0.0000005;
public MutateGPAdaptive() { public MutateGPAdaptive() {
} }
public MutateGPAdaptive(MutateGPAdaptive mutator) { public MutateGPAdaptive(MutateGPAdaptive mutator) {
this.m_MutationStep = mutator.m_MutationStep; this.mutationStep = mutator.mutationStep;
this.m_Tau1 = mutator.m_Tau1; this.tau1 = mutator.tau1;
this.m_Tau2 = mutator.m_Tau2; this.tau2 = mutator.tau2;
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize; this.lowerLimitStepSize = mutator.lowerLimitStepSize;
} }
/** /**
@ -52,16 +52,16 @@ public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable
public boolean equals(Object mutator) { public boolean equals(Object mutator) {
if (mutator instanceof MutateGPAdaptive) { if (mutator instanceof MutateGPAdaptive) {
MutateGPAdaptive mut = (MutateGPAdaptive) mutator; MutateGPAdaptive mut = (MutateGPAdaptive) mutator;
if (this.m_MutationStep != mut.m_MutationStep) { if (this.mutationStep != mut.mutationStep) {
return false; return false;
} }
if (this.m_Tau1 != mut.m_Tau1) { if (this.tau1 != mut.tau1) {
return false; return false;
} }
if (this.m_Tau2 != mut.m_Tau2) { if (this.tau2 != mut.tau2) {
return false; return false;
} }
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) { if (this.lowerLimitStepSize != mut.lowerLimitStepSize) {
return false; return false;
} }
return true; return true;
@ -91,14 +91,14 @@ public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable
public void mutate(AbstractEAIndividual individual) { public void mutate(AbstractEAIndividual individual) {
//System.out.println("Before Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor()); //System.out.println("Before Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor());
if (individual instanceof InterfaceGPIndividual) { if (individual instanceof InterfaceGPIndividual) {
this.m_MutationStep *= Math.exp(this.m_Tau1 * RNG.gaussianDouble(1) + this.m_Tau2 * RNG.gaussianDouble(1)); this.mutationStep *= Math.exp(this.tau1 * RNG.gaussianDouble(1) + this.tau2 * RNG.gaussianDouble(1));
if (this.m_MutationStep < this.m_LowerLimitStepSize) { if (this.mutationStep < this.lowerLimitStepSize) {
this.m_MutationStep = this.m_LowerLimitStepSize; this.mutationStep = this.lowerLimitStepSize;
} }
if (this.m_MutationStep > 1) { if (this.mutationStep > 1) {
this.m_MutationStep = 1; this.mutationStep = 1;
} }
if (RNG.flipCoin(this.m_MutationStep)) { if (RNG.flipCoin(this.mutationStep)) {
((IndividualInterface) individual).defaultMutate(); ((IndividualInterface) individual).defaultMutate();
} }
} }
@ -157,13 +157,13 @@ public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable
*/ */
public void setMutationStep(double d) { public void setMutationStep(double d) {
if (d < 0) { if (d < 0) {
d = this.m_LowerLimitStepSize; d = this.lowerLimitStepSize;
} }
this.m_MutationStep = d; this.mutationStep = d;
} }
public double getMutationStepSize() { public double getMutationStepSize() {
return this.m_MutationStep; return this.mutationStep;
} }
public String mutationStepSizeTipText() { public String mutationStepSizeTipText() {
@ -179,11 +179,11 @@ public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable
if (d < 0) { if (d < 0) {
d = 0; d = 0;
} }
this.m_LowerLimitStepSize = d; this.lowerLimitStepSize = d;
} }
public double getLowerLimitStepSize() { public double getLowerLimitStepSize() {
return this.m_LowerLimitStepSize; return this.lowerLimitStepSize;
} }
public String lowerLimitStepSizeTipText() { public String lowerLimitStepSizeTipText() {
@ -199,11 +199,11 @@ public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable
if (d < 0) { if (d < 0) {
d = 0; d = 0;
} }
this.m_Tau1 = d; this.tau1 = d;
} }
public double getTau1() { public double getTau1() {
return this.m_Tau1; return this.tau1;
} }
public String tau1TipText() { public String tau1TipText() {
@ -219,11 +219,11 @@ public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable
if (d < 0) { if (d < 0) {
d = 0; d = 0;
} }
this.m_Tau2 = d; this.tau2 = d;
} }
public double getTau2() { public double getTau2() {
return this.m_Tau2; return this.tau2;
} }
public String tau2TipText() { public String tau2TipText() {

View File

@ -9,42 +9,42 @@ package eva2.optimization.operator.mutation;
*/ */
public class PropertyMutationMixer implements java.io.Serializable { public class PropertyMutationMixer implements java.io.Serializable {
public InterfaceMutation[] m_AvailableTargets; public InterfaceMutation[] availableTargets;
public InterfaceMutation[] m_SelectedTargets; public InterfaceMutation[] selectedTargets;
public double[] m_Weights; public double[] weights;
public String m_DescriptiveString = "No Description given."; public String descriptiveString = "No Description given.";
public String m_WeightsLabel = "-"; public String weightsLabel = "-";
public boolean m_NormalizationEnabled = true; public boolean normalizationEnabled = true;
public PropertyMutationMixer(InterfaceMutation[] d, boolean selectAllOrNone) { public PropertyMutationMixer(InterfaceMutation[] d, boolean selectAllOrNone) {
this.m_Weights = new double[d.length]; this.weights = new double[d.length];
for (int i = 0; i < d.length; i++) { for (int i = 0; i < d.length; i++) {
this.m_Weights[i] = 1 / ((double) d.length); this.weights[i] = 1 / ((double) d.length);
} }
this.m_AvailableTargets = d; this.availableTargets = d;
if (selectAllOrNone) { if (selectAllOrNone) {
this.m_SelectedTargets = d.clone(); this.selectedTargets = d.clone();
} else { } else {
this.m_SelectedTargets = null; this.selectedTargets = null;
} }
} }
public PropertyMutationMixer(PropertyMutationMixer d) { public PropertyMutationMixer(PropertyMutationMixer d) {
this.m_DescriptiveString = d.m_DescriptiveString; this.descriptiveString = d.descriptiveString;
this.m_WeightsLabel = d.m_WeightsLabel; this.weightsLabel = d.weightsLabel;
this.m_NormalizationEnabled = d.m_NormalizationEnabled; this.normalizationEnabled = d.normalizationEnabled;
this.m_AvailableTargets = new InterfaceMutation[d.m_AvailableTargets.length]; this.availableTargets = new InterfaceMutation[d.availableTargets.length];
for (int i = 0; i < this.m_AvailableTargets.length; i++) { for (int i = 0; i < this.availableTargets.length; i++) {
//this.m_AvailableTargets[i] = (InterfaceMutation)d.m_AvailableTargets[i].clone(); //this.availableTargets[i] = (InterfaceMutation)d.availableTargets[i].clone();
this.m_AvailableTargets[i] = d.m_AvailableTargets[i]; this.availableTargets[i] = d.availableTargets[i];
} }
this.m_SelectedTargets = new InterfaceMutation[d.m_SelectedTargets.length]; this.selectedTargets = new InterfaceMutation[d.selectedTargets.length];
for (int i = 0; i < this.m_SelectedTargets.length; i++) { for (int i = 0; i < this.selectedTargets.length; i++) {
this.m_SelectedTargets[i] = (InterfaceMutation) d.m_SelectedTargets[i].clone(); this.selectedTargets[i] = (InterfaceMutation) d.selectedTargets[i].clone();
} }
if (d.m_Weights != null) { if (d.weights != null) {
this.m_Weights = new double[d.m_Weights.length]; this.weights = new double[d.weights.length];
System.arraycopy(d.m_Weights, 0, this.m_Weights, 0, this.m_Weights.length); System.arraycopy(d.weights, 0, this.weights, 0, this.weights.length);
} }
} }
@ -59,32 +59,32 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @param d The InterfaceOptimizationTarget[] * @param d The InterfaceOptimizationTarget[]
*/ */
public void setSelectedMutators(InterfaceMutation[] d) { public void setSelectedMutators(InterfaceMutation[] d) {
this.m_SelectedTargets = d; this.selectedTargets = d;
if (this.m_Weights == null) { if (this.weights == null) {
this.m_Weights = new double[d.length]; this.weights = new double[d.length];
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
this.m_Weights[i] = 1 / ((double) d.length); this.weights[i] = 1 / ((double) d.length);
} }
return; return;
} }
if (d.length == this.m_Weights.length) { if (d.length == this.weights.length) {
return; return;
} }
if (d.length > this.m_Weights.length) { if (d.length > this.weights.length) {
double[] newWeights = new double[d.length]; double[] newWeights = new double[d.length];
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
newWeights[i] = this.m_Weights[i]; newWeights[i] = this.weights[i];
} }
this.m_Weights = newWeights; this.weights = newWeights;
} else { } else {
double[] newWeights = new double[d.length]; double[] newWeights = new double[d.length];
for (int i = 0; i < d.length; i++) { for (int i = 0; i < d.length; i++) {
newWeights[i] = this.m_Weights[i]; newWeights[i] = this.weights[i];
} }
this.m_Weights = newWeights; this.weights = newWeights;
} }
} }
@ -94,7 +94,7 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @return The InterfaceOptimizationTarget[]. * @return The InterfaceOptimizationTarget[].
*/ */
public InterfaceMutation[] getSelectedMutators() { public InterfaceMutation[] getSelectedMutators() {
return this.m_SelectedTargets; return this.selectedTargets;
} }
/** /**
@ -103,7 +103,7 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @return The InterfaceOptimizationTarget[]. * @return The InterfaceOptimizationTarget[].
*/ */
public InterfaceMutation[] getAvailableMutators() { public InterfaceMutation[] getAvailableMutators() {
return this.m_AvailableTargets; return this.availableTargets;
} }
/** /**
@ -112,13 +112,13 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @return the weights * @return the weights
*/ */
public double[] getWeights() { public double[] getWeights() {
return this.m_Weights; return this.weights;
} }
public void setWeights(double[] d) { public void setWeights(double[] d) {
this.m_Weights = d; this.weights = d;
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
this.m_Weights[i] = Math.abs(this.m_Weights[i]); this.weights[i] = Math.abs(this.weights[i]);
} }
} }
@ -128,11 +128,11 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @return the string * @return the string
*/ */
public String getDescriptiveString() { public String getDescriptiveString() {
return this.m_DescriptiveString; return this.descriptiveString;
} }
public void setDescriptiveString(String d) { public void setDescriptiveString(String d) {
this.m_DescriptiveString = d; this.descriptiveString = d;
} }
/** /**
@ -141,21 +141,21 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @return the string * @return the string
*/ */
public String getWeigthsLabel() { public String getWeigthsLabel() {
return this.m_WeightsLabel; return this.weightsLabel;
} }
public void setWeightsLabel(String d) { public void setWeightsLabel(String d) {
this.m_WeightsLabel = d; this.weightsLabel = d;
} }
public void normalizeWeights() { public void normalizeWeights() {
double sum = 0; double sum = 0;
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
sum += this.m_Weights[i]; sum += this.weights[i];
} }
if (sum > 0) { if (sum > 0) {
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
this.m_Weights[i] /= sum; this.weights[i] /= sum;
} }
} }
} }
@ -166,22 +166,22 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @param index The index of the target to be removed. * @param index The index of the target to be removed.
*/ */
public void removeMutator(int index) { public void removeMutator(int index) {
if ((index < 0) || (index >= this.m_SelectedTargets.length)) { if ((index < 0) || (index >= this.selectedTargets.length)) {
return; return;
} }
InterfaceMutation[] newList = new InterfaceMutation[this.m_SelectedTargets.length - 1]; InterfaceMutation[] newList = new InterfaceMutation[this.selectedTargets.length - 1];
double[] newWeights = new double[this.m_Weights.length - 1]; double[] newWeights = new double[this.weights.length - 1];
int j = 0; int j = 0;
for (int i = 0; i < this.m_SelectedTargets.length; i++) { for (int i = 0; i < this.selectedTargets.length; i++) {
if (index != i) { if (index != i) {
newList[j] = this.m_SelectedTargets[i]; newList[j] = this.selectedTargets[i];
newWeights[j] = this.m_Weights[i]; newWeights[j] = this.weights[i];
j++; j++;
} }
} }
this.m_SelectedTargets = newList; this.selectedTargets = newList;
this.m_Weights = newWeights; this.weights = newWeights;
} }
/** /**
@ -190,15 +190,15 @@ public class PropertyMutationMixer implements java.io.Serializable {
* @param optTarget * @param optTarget
*/ */
public void addMutator(InterfaceMutation optTarget) { public void addMutator(InterfaceMutation optTarget) {
InterfaceMutation[] newList = new InterfaceMutation[this.m_SelectedTargets.length + 1]; InterfaceMutation[] newList = new InterfaceMutation[this.selectedTargets.length + 1];
double[] newWeights = new double[this.m_Weights.length + 1]; double[] newWeights = new double[this.weights.length + 1];
for (int i = 0; i < this.m_SelectedTargets.length; i++) { for (int i = 0; i < this.selectedTargets.length; i++) {
newList[i] = this.m_SelectedTargets[i]; newList[i] = this.selectedTargets[i];
newWeights[i] = this.m_Weights[i]; newWeights[i] = this.weights[i];
} }
newList[this.m_SelectedTargets.length] = optTarget; newList[this.selectedTargets.length] = optTarget;
newWeights[this.m_SelectedTargets.length] = 1.0; newWeights[this.selectedTargets.length] = 1.0;
this.m_SelectedTargets = newList; this.selectedTargets = newList;
this.m_Weights = newWeights; this.weights = newWeights;
} }
} }

View File

@ -30,73 +30,73 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
/** /**
* Handles property change notification * Handles property change notification
*/ */
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this); private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
/** /**
* The label for when we can't edit that type * The label for when we can't edit that type
*/ */
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER); private JLabel label = new JLabel("Can't edit", SwingConstants.CENTER);
/** /**
* The FilePath that is to be edited * The FilePath that is to be edited
*/ */
private PropertyMutationMixer m_MutatorsWithWeights; private PropertyMutationMixer mutatorsWithWeights;
/** /**
* The gaphix stuff * The gaphix stuff
*/ */
private JComponent m_Editor; private JComponent editorComponent;
private JPanel m_TargetList; private JPanel targetListPanel;
private JTextField[] m_Weights; private JTextField[] weights;
private JComponent[] m_Targets; private JComponent[] targets;
private JButton[] m_Delete; private JButton[] deleteButtons;
private JScrollPane m_ScrollTargets; private JScrollPane scrolltargetPanel;
private GeneralOptimizationEditorProperty[] m_Editors; private GeneralOptimizationEditorProperty[] editors;
private GeneralGEOFaker m_Component; private GeneralGEOFaker component;
private PropertyChangeListener m_self; private PropertyChangeListener self;
public PropertyMutationMixerEditor() { public PropertyMutationMixerEditor() {
m_self = this; self = this;
} }
/** /**
* This method will init the CustomEditor Panel * This method will init the CustomEditor Panel
*/ */
private void initCustomEditor() { private void initCustomEditor() {
m_self = this; self = this;
this.m_Editor = new JPanel(); this.editorComponent = new JPanel();
this.m_Editor.setPreferredSize(new Dimension(450, 200)); this.editorComponent.setPreferredSize(new Dimension(450, 200));
this.m_Editor.setMinimumSize(new Dimension(450, 200)); this.editorComponent.setMinimumSize(new Dimension(450, 200));
// init the editors // init the editors
InterfaceMutation[] list = this.m_MutatorsWithWeights.getSelectedMutators(); InterfaceMutation[] list = this.mutatorsWithWeights.getSelectedMutators();
this.m_Editors = new GeneralOptimizationEditorProperty[list.length]; this.editors = new GeneralOptimizationEditorProperty[list.length];
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
this.m_Editors[i] = new GeneralOptimizationEditorProperty(); this.editors[i] = new GeneralOptimizationEditorProperty();
this.m_Editors[i].name = list[i].getStringRepresentation(); this.editors[i].name = list[i].getStringRepresentation();
try { try {
this.m_Editors[i].value = list[i]; this.editors[i].value = list[i];
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(this.m_Editors[i].value.getClass()); this.editors[i].editor = PropertyEditorProvider.findEditor(this.editors[i].value.getClass());
if (this.m_Editors[i].editor == null) { if (this.editors[i].editor == null) {
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(InterfaceMutation.class); this.editors[i].editor = PropertyEditorProvider.findEditor(InterfaceMutation.class);
} }
if (this.m_Editors[i].editor instanceof GenericObjectEditor) { if (this.editors[i].editor instanceof GenericObjectEditor) {
((GenericObjectEditor) this.m_Editors[i].editor).setClassType(InterfaceMutation.class); ((GenericObjectEditor) this.editors[i].editor).setClassType(InterfaceMutation.class);
} }
this.m_Editors[i].editor.setValue(this.m_Editors[i].value); this.editors[i].editor.setValue(this.editors[i].value);
this.m_Editors[i].editor.addPropertyChangeListener(this); this.editors[i].editor.addPropertyChangeListener(this);
AbstractObjectEditor.findViewFor(this.m_Editors[i]); AbstractObjectEditor.findViewFor(this.editors[i]);
if (this.m_Editors[i].view != null) { if (this.editors[i].view != null) {
this.m_Editors[i].view.repaint(); this.editors[i].view.repaint();
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Darn can't read the value..."); System.out.println("Darn can't read the value...");
} }
} }
this.m_TargetList = new JPanel(); this.targetListPanel = new JPanel();
this.updateTargetList(); this.updateTargetList();
this.m_ScrollTargets = new JScrollPane(this.m_TargetList); this.scrolltargetPanel = new JScrollPane(this.targetListPanel);
this.m_Editor.setLayout(new BorderLayout()); this.editorComponent.setLayout(new BorderLayout());
this.m_Editor.add(this.m_ScrollTargets, BorderLayout.CENTER); this.editorComponent.add(this.scrolltargetPanel, BorderLayout.CENTER);
// The Button Panel // The Button Panel
JPanel buttonPanel = new JPanel(); JPanel buttonPanel = new JPanel();
@ -109,7 +109,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
buttonPanel.add(normButton); buttonPanel.add(normButton);
buttonPanel.add(addButton); buttonPanel.add(addButton);
this.m_Editor.add(buttonPanel, BorderLayout.SOUTH); this.editorComponent.add(buttonPanel, BorderLayout.SOUTH);
// Some description would be nice // Some description would be nice
JTextArea jt = new JTextArea(); JTextArea jt = new JTextArea();
@ -117,7 +117,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
jt.setEditable(false); jt.setEditable(false);
jt.setLineWrap(true); jt.setLineWrap(true);
jt.setWrapStyleWord(true); jt.setWrapStyleWord(true);
jt.setText(this.m_MutatorsWithWeights.getDescriptiveString()); jt.setText(this.mutatorsWithWeights.getDescriptiveString());
jt.setBackground(getBackground()); jt.setBackground(getBackground());
JPanel jp = new JPanel(); JPanel jp = new JPanel();
jp.setBorder(BorderFactory.createCompoundBorder( jp.setBorder(BorderFactory.createCompoundBorder(
@ -134,7 +134,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
jp.add(p2, BorderLayout.EAST); jp.add(p2, BorderLayout.EAST);
GridBagConstraints gbConstraints = new GridBagConstraints(); GridBagConstraints gbConstraints = new GridBagConstraints();
this.m_Editor.add(jp, BorderLayout.NORTH); this.editorComponent.add(jp, BorderLayout.NORTH);
this.updateEditor(); this.updateEditor();
} }
@ -145,15 +145,15 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
private void updateTargetList() { private void updateTargetList() {
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes; byte[] bytes;
InterfaceMutation[] list = this.m_MutatorsWithWeights.getSelectedMutators(); InterfaceMutation[] list = this.mutatorsWithWeights.getSelectedMutators();
double[] weights = this.m_MutatorsWithWeights.getWeights(); double[] weights = this.mutatorsWithWeights.getWeights();
this.m_TargetList.removeAll(); this.targetListPanel.removeAll();
this.m_TargetList.setLayout(new GridBagLayout()); this.targetListPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
this.m_Weights = new JTextField[list.length]; this.weights = new JTextField[list.length];
this.m_Targets = new JComponent[list.length]; this.targets = new JComponent[list.length];
this.m_Delete = new JButton[list.length]; this.deleteButtons = new JButton[list.length];
String[] cups = new String[8]; String[] cups = new String[8];
for (int i = 0; i < cups.length; i++) { for (int i = 0; i < cups.length; i++) {
cups[i] = "" + (i + 1); cups[i] = "" + (i + 1);
@ -163,52 +163,52 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0; gbc.gridx = 0;
gbc.weightx = 2; gbc.weightx = 2;
this.m_TargetList.add(new JLabel(this.m_MutatorsWithWeights.getWeigthsLabel()), gbc); this.targetListPanel.add(new JLabel(this.mutatorsWithWeights.getWeigthsLabel()), gbc);
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 1; gbc.gridx = 1;
gbc.weightx = 10; gbc.weightx = 10;
this.m_TargetList.add(new JLabel("Target"), gbc); this.targetListPanel.add(new JLabel("Target"), gbc);
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 2; gbc.gridx = 2;
gbc.weightx = 1; gbc.weightx = 1;
this.m_TargetList.add(new JLabel("Remove"), gbc); this.targetListPanel.add(new JLabel("Remove"), gbc);
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
// the weight // the weight
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0; gbc.gridx = 0;
gbc.weightx = 2; gbc.weightx = 2;
this.m_Weights[i] = new JTextField("" + weights[i]); this.weights[i] = new JTextField("" + weights[i]);
this.m_Weights[i].addKeyListener(this.readDoubleArrayAction); this.weights[i].addKeyListener(this.readDoubleArrayAction);
this.m_TargetList.add(this.m_Weights[i], gbc); this.targetListPanel.add(this.weights[i], gbc);
// the status indicator // the status indicator
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 1; gbc.gridx = 1;
gbc.weightx = 10; gbc.weightx = 10;
this.m_Targets[i] = this.m_Editors[i].view; this.targets[i] = this.editors[i].view;
this.m_TargetList.add(this.m_Targets[i], gbc); this.targetListPanel.add(this.targets[i], gbc);
// The delete button // The delete button
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 2; gbc.gridx = 2;
gbc.weightx = 1; gbc.weightx = 1;
bytes = loader.getBytesFromResourceLocation("images/Sub24.gif", true); bytes = loader.getBytesFromResourceLocation("images/Sub24.gif", true);
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.deleteButtons[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
this.m_Delete[i].addActionListener(deleteTarget); this.deleteButtons[i].addActionListener(deleteTarget);
this.m_TargetList.add(this.m_Delete[i], gbc); this.targetListPanel.add(this.deleteButtons[i], gbc);
} }
this.m_TargetList.repaint(); this.targetListPanel.repaint();
this.m_TargetList.validate(); this.targetListPanel.validate();
if (this.m_ScrollTargets != null) { if (this.scrolltargetPanel != null) {
this.m_ScrollTargets.validate(); this.scrolltargetPanel.validate();
this.m_ScrollTargets.repaint(); this.scrolltargetPanel.repaint();
} }
if (this.m_Editor != null) { if (this.editorComponent != null) {
this.m_Editor.validate(); this.editorComponent.validate();
this.m_Editor.repaint(); this.editorComponent.repaint();
} }
} }
@ -228,13 +228,13 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
ActionListener addTarget = new ActionListener() { ActionListener addTarget = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
m_MutatorsWithWeights.addMutator((InterfaceMutation) m_MutatorsWithWeights.getAvailableMutators()[0].clone()); mutatorsWithWeights.addMutator((InterfaceMutation) mutatorsWithWeights.getAvailableMutators()[0].clone());
int l = m_MutatorsWithWeights.getSelectedMutators().length; int l = mutatorsWithWeights.getSelectedMutators().length;
GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l]; GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l];
for (int i = 0; i < m_Editors.length; i++) { for (int i = 0; i < editors.length; i++) {
newEdit[i] = m_Editors[i]; newEdit[i] = editors[i];
} }
InterfaceMutation[] list = m_MutatorsWithWeights.getSelectedMutators(); InterfaceMutation[] list = mutatorsWithWeights.getSelectedMutators();
l--; l--;
newEdit[l] = new GeneralOptimizationEditorProperty(); newEdit[l] = new GeneralOptimizationEditorProperty();
newEdit[l].name = list[l].getStringRepresentation(); newEdit[l].name = list[l].getStringRepresentation();
@ -248,7 +248,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
((GenericObjectEditor) newEdit[l].editor).setClassType(InterfaceMutation.class); ((GenericObjectEditor) newEdit[l].editor).setClassType(InterfaceMutation.class);
} }
newEdit[l].editor.setValue(newEdit[l].value); newEdit[l].editor.setValue(newEdit[l].value);
newEdit[l].editor.addPropertyChangeListener(m_self); newEdit[l].editor.addPropertyChangeListener(self);
AbstractObjectEditor.findViewFor(newEdit[l]); AbstractObjectEditor.findViewFor(newEdit[l]);
if (newEdit[l].view != null) { if (newEdit[l].view != null) {
newEdit[l].view.repaint(); newEdit[l].view.repaint();
@ -256,7 +256,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
} catch (Exception e) { } catch (Exception e) {
System.out.println("Darn can't read the value..."); System.out.println("Darn can't read the value...");
} }
m_Editors = newEdit; editors = newEdit;
updateTargetList(); updateTargetList();
} }
}; };
@ -267,17 +267,17 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
ActionListener deleteTarget = new ActionListener() { ActionListener deleteTarget = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
int l = m_MutatorsWithWeights.getSelectedMutators().length, j = 0; int l = mutatorsWithWeights.getSelectedMutators().length, j = 0;
GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l - 1]; GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l - 1];
for (int i = 0; i < m_Delete.length; i++) { for (int i = 0; i < deleteButtons.length; i++) {
if (event.getSource().equals(m_Delete[i])) { if (event.getSource().equals(deleteButtons[i])) {
m_MutatorsWithWeights.removeMutator(i); mutatorsWithWeights.removeMutator(i);
} else { } else {
newEdit[j] = m_Editors[i]; newEdit[j] = editors[i];
j++; j++;
} }
} }
m_Editors = newEdit; editors = newEdit;
updateTargetList(); updateTargetList();
} }
}; };
@ -288,7 +288,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
ActionListener normalizeWeights = new ActionListener() { ActionListener normalizeWeights = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
m_MutatorsWithWeights.normalizeWeights(); mutatorsWithWeights.normalizeWeights();
updateTargetList(); updateTargetList();
} }
}; };
@ -307,18 +307,18 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
@Override @Override
public void keyReleased(KeyEvent event) { public void keyReleased(KeyEvent event) {
double[] newW = m_MutatorsWithWeights.getWeights(); double[] newW = mutatorsWithWeights.getWeights();
for (int i = 0; i < newW.length; i++) { for (int i = 0; i < newW.length; i++) {
try { try {
double d = 0; double d = 0;
d = new Double(m_Weights[i].getText()).doubleValue(); d = new Double(weights[i].getText()).doubleValue();
newW[i] = d; newW[i] = d;
} catch (Exception e) { } catch (Exception e) {
} }
} }
m_MutatorsWithWeights.setWeights(newW); mutatorsWithWeights.setWeights(newW);
} }
}; };
@ -326,13 +326,13 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
* The object may have changed update the editor. * The object may have changed update the editor.
*/ */
private void updateEditor() { private void updateEditor() {
if (this.m_Editor != null) { if (this.editorComponent != null) {
this.m_TargetList.validate(); this.targetListPanel.validate();
this.m_TargetList.repaint(); this.targetListPanel.repaint();
this.m_ScrollTargets.validate(); this.scrolltargetPanel.validate();
this.m_ScrollTargets.repaint(); this.scrolltargetPanel.repaint();
this.m_Editor.validate(); this.editorComponent.validate();
this.m_Editor.repaint(); this.editorComponent.repaint();
} }
} }
@ -344,7 +344,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
@Override @Override
public void setValue(Object o) { public void setValue(Object o) {
if (o instanceof PropertyMutationMixer) { if (o instanceof PropertyMutationMixer) {
this.m_MutatorsWithWeights = (PropertyMutationMixer) o; this.mutatorsWithWeights = (PropertyMutationMixer) o;
this.updateEditor(); this.updateEditor();
} }
} }
@ -356,7 +356,7 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
*/ */
@Override @Override
public Object getValue() { public Object getValue() {
return this.m_MutatorsWithWeights; return this.mutatorsWithWeights;
} }
@Override @Override
@ -447,11 +447,11 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
*/ */
@Override @Override
public Component getCustomEditor() { public Component getCustomEditor() {
if (this.m_Component == null) { if (this.component == null) {
this.initCustomEditor(); this.initCustomEditor();
this.m_Component = new GeneralGEOFaker((PropertyEditor) this, (JPanel) this.m_Editor); this.component = new GeneralGEOFaker((PropertyEditor) this, (JPanel) this.editorComponent);
} }
return this.m_Component; return this.component;
} }
/** /**
@ -469,12 +469,12 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
@Override @Override
public void addPropertyChangeListener(PropertyChangeListener l) { public void addPropertyChangeListener(PropertyChangeListener l) {
m_Support.addPropertyChangeListener(l); propertyChangeSupport.addPropertyChangeListener(l);
} }
@Override @Override
public void removePropertyChangeListener(PropertyChangeListener l) { public void removePropertyChangeListener(PropertyChangeListener l) {
m_Support.removePropertyChangeListener(l); propertyChangeSupport.removePropertyChangeListener(l);
} }
/** /**
@ -487,35 +487,35 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
Object newVal = evt.getNewValue(); Object newVal = evt.getNewValue();
Object oldVal = evt.getOldValue(); Object oldVal = evt.getOldValue();
InterfaceMutation[] list = this.m_MutatorsWithWeights.getSelectedMutators(); InterfaceMutation[] list = this.mutatorsWithWeights.getSelectedMutators();
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
if (oldVal.equals(list[i])) { if (oldVal.equals(list[i])) {
list[i] = (InterfaceMutation) newVal; list[i] = (InterfaceMutation) newVal;
this.m_Editors[i].name = list[i].getStringRepresentation(); this.editors[i].name = list[i].getStringRepresentation();
try { try {
this.m_Editors[i].value = list[i]; this.editors[i].value = list[i];
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(this.m_Editors[i].value.getClass()); this.editors[i].editor = PropertyEditorProvider.findEditor(this.editors[i].value.getClass());
if (this.m_Editors[i].editor == null) { if (this.editors[i].editor == null) {
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(InterfaceMutation.class); this.editors[i].editor = PropertyEditorProvider.findEditor(InterfaceMutation.class);
} }
if (this.m_Editors[i].editor instanceof GenericObjectEditor) { if (this.editors[i].editor instanceof GenericObjectEditor) {
((GenericObjectEditor) this.m_Editors[i].editor).setClassType(InterfaceMutation.class); ((GenericObjectEditor) this.editors[i].editor).setClassType(InterfaceMutation.class);
} }
this.m_Editors[i].editor.setValue(this.m_Editors[i].value); this.editors[i].editor.setValue(this.editors[i].value);
this.m_Editors[i].editor.addPropertyChangeListener(this); this.editors[i].editor.addPropertyChangeListener(this);
AbstractObjectEditor.findViewFor(this.m_Editors[i]); AbstractObjectEditor.findViewFor(this.editors[i]);
if (this.m_Editors[i].view != null) { if (this.editors[i].view != null) {
this.m_Editors[i].view.repaint(); this.editors[i].view.repaint();
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Darn can't read the value..."); System.out.println("Darn can't read the value...");
} }
this.m_Targets[i] = this.m_Editors[i].view; this.targets[i] = this.editors[i].view;
i = list.length; i = list.length;
} }
} }
//this.m_OptimizationTargets.setSelectedTargets(list); //this.m_OptimizationTargets.setSelectedTargets(list);
this.updateCenterComponent(evt); // Let our panel update before guys downstream this.updateCenterComponent(evt); // Let our panel update before guys downstream
m_Support.firePropertyChange("", m_MutatorsWithWeights, m_MutatorsWithWeights); propertyChangeSupport.firePropertyChange("", mutatorsWithWeights, mutatorsWithWeights);
} }
} }

View File

@ -80,7 +80,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
/** /**
* Best n Individuals in the history. * Best n Individuals in the history.
*/ */
private transient LinkedList<AbstractEAIndividual> m_History = new LinkedList<AbstractEAIndividual>(); private transient LinkedList<AbstractEAIndividual> historyList = new LinkedList<AbstractEAIndividual>();
/** /**
* Remember when the last sorted queue was prepared. * Remember when the last sorted queue was prepared.
@ -190,8 +190,8 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
if (population.populationArchive != null) { if (population.populationArchive != null) {
this.populationArchive = (Population) population.populationArchive.clone(); this.populationArchive = (Population) population.populationArchive.clone();
} }
if (population.m_History != null) { if (population.historyList != null) {
this.m_History = (LinkedList<AbstractEAIndividual>) population.m_History.clone(); this.historyList = (LinkedList<AbstractEAIndividual>) population.historyList.clone();
} }
if (population.additionalPopData != null) { if (population.additionalPopData != null) {
this.additionalPopData = (HashMap<String, Object>) additionalPopData.clone(); this.additionalPopData = (HashMap<String, Object>) additionalPopData.clone();
@ -364,7 +364,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
* been inited by a problem * been inited by a problem
*/ */
public void init() { public void init() {
this.m_History = new LinkedList<AbstractEAIndividual>(); this.historyList = new LinkedList<AbstractEAIndividual>();
this.generationCount = 0; this.generationCount = 0;
this.functionCallCount = 0; this.functionCallCount = 0;
double[] popSeed = null; double[] popSeed = null;
@ -453,7 +453,7 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
/** /**
* This method inits the population. Function and generation counters are * This method inits the population. Function and generation counters are
* reset and m_Size default Individuals are created and initialized by the * reset and size default Individuals are created and initialized by the
* GAIndividual default init() method. * GAIndividual default init() method.
*/ */
public void defaultInit(AbstractEAIndividual template) { public void defaultInit(AbstractEAIndividual template) {
@ -591,18 +591,18 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
public int getHistoryLength() { public int getHistoryLength() {
if (historyMaxLen != 0) { if (historyMaxLen != 0) {
return m_History.size(); return historyList.size();
} else { } else {
return 0; return 0;
} }
} }
public LinkedList<AbstractEAIndividual> getHistory() { public LinkedList<AbstractEAIndividual> getHistory() {
return m_History; return historyList;
} }
public void SetHistory(LinkedList<AbstractEAIndividual> theHist) { public void SetHistory(LinkedList<AbstractEAIndividual> theHist) {
m_History = theHist; historyList = theHist;
} }
/** /**
@ -709,11 +709,11 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
*/ */
public void incrGeneration() { public void incrGeneration() {
if (isUsingHistory() && (this.size() >= 1)) { if (isUsingHistory() && (this.size() >= 1)) {
if (historyMaxLen > 0 && (m_History.size() >= historyMaxLen)) { if (historyMaxLen > 0 && (historyList.size() >= historyMaxLen)) {
// oldest one must be replaced.. should be the one in front // oldest one must be replaced.. should be the one in front
m_History.removeFirst(); historyList.removeFirst();
} }
this.m_History.add((AbstractEAIndividual) this.getBestEAIndividual().clone()); this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
} }
for (int i = 0; i < size(); i++) { for (int i = 0; i < size(); i++) {
((AbstractEAIndividual) get(i)).incrAge(); ((AbstractEAIndividual) get(i)).incrAge();
@ -2508,8 +2508,8 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
} }
public void clearHistory() { public void clearHistory() {
if (m_History != null) { if (historyList != null) {
m_History.clear(); historyList.clear();
} }
} }

View File

@ -680,7 +680,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
@Override @Override
public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) { public void addPopulationChangedEventListener(InterfacePopulationChangedEventListener ea) {
if (this.populationChangedEventListeners == null) { if (this.populationChangedEventListeners == null) {
this.populationChangedEventListeners = new Vector<InterfacePopulationChangedEventListener>(); this.populationChangedEventListeners = new Vector<>();
} }
this.populationChangedEventListeners.add(ea); this.populationChangedEventListeners.add(ea);
} }
@ -689,7 +689,6 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
public boolean removePopulationChangedEventListener( public boolean removePopulationChangedEventListener(
InterfacePopulationChangedEventListener ea) { InterfacePopulationChangedEventListener ea) {
if (populationChangedEventListeners != null && populationChangedEventListeners.removeElement(ea)) { if (populationChangedEventListeners != null && populationChangedEventListeners.removeElement(ea)) {
return true; return true;
} else { } else {
return false; return false;