Removed m_ notation from classes in eva2.optimization.individuals
This commit is contained in:
parent
53b5111df7
commit
41f58bb2f9
@ -17,34 +17,34 @@ import java.util.BitSet;
|
||||
@eva2.util.annotation.Description(value = "This is an ES individual adopted to optimize binary values.")
|
||||
public class ESIndividualBinaryData extends AbstractEAIndividual implements InterfaceESIndividual, InterfaceDataTypeBinary, java.io.Serializable {
|
||||
|
||||
private BitSet m_Phenotype = new BitSet();
|
||||
private double[] m_Genotype;
|
||||
private boolean m_UseHardSwitch = false;
|
||||
private double[][] m_Range;
|
||||
private BitSet phenotype = new BitSet();
|
||||
private double[] genotype;
|
||||
private boolean useHardSwitch = false;
|
||||
private double[][] initializationRange;
|
||||
|
||||
public ESIndividualBinaryData() {
|
||||
this.mutationProbability = 1.0;
|
||||
this.mutationOperator = new MutateESGlobal();
|
||||
this.crossoverProbability = 0.5;
|
||||
this.crossoverOperator = new CrossoverESDefault();
|
||||
this.m_Genotype = new double[1];
|
||||
this.m_Range = new double[1][2];
|
||||
this.m_Range[0][0] = 0;
|
||||
this.m_Range[0][1] = 1;
|
||||
this.genotype = new double[1];
|
||||
this.initializationRange = new double[1][2];
|
||||
this.initializationRange[0][0] = 0;
|
||||
this.initializationRange[0][1] = 1;
|
||||
}
|
||||
|
||||
public ESIndividualBinaryData(ESIndividualBinaryData individual) {
|
||||
if (individual.m_Phenotype != null) {
|
||||
this.m_Phenotype = (BitSet) individual.m_Phenotype.clone();
|
||||
if (individual.phenotype != null) {
|
||||
this.phenotype = (BitSet) individual.phenotype.clone();
|
||||
}
|
||||
this.m_Genotype = new double[individual.m_Genotype.length];
|
||||
this.m_Range = new double[individual.m_Genotype.length][2];
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
this.m_Genotype[i] = individual.m_Genotype[i];
|
||||
this.m_Range[i][0] = individual.m_Range[i][0];
|
||||
this.m_Range[i][1] = individual.m_Range[i][1];
|
||||
this.genotype = new double[individual.genotype.length];
|
||||
this.initializationRange = new double[individual.genotype.length][2];
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
this.genotype[i] = individual.genotype[i];
|
||||
this.initializationRange[i][0] = individual.initializationRange[i][0];
|
||||
this.initializationRange[i][1] = individual.initializationRange[i][1];
|
||||
}
|
||||
this.m_UseHardSwitch = individual.m_UseHardSwitch;
|
||||
this.useHardSwitch = individual.useHardSwitch;
|
||||
|
||||
// cloning the members of AbstractEAIndividual
|
||||
this.age = individual.age;
|
||||
@ -78,20 +78,20 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof ESIndividualBinaryData) {
|
||||
ESIndividualBinaryData indy = (ESIndividualBinaryData) individual;
|
||||
if ((this.m_Genotype == null) || (indy.m_Genotype == null)) {
|
||||
if ((this.genotype == null) || (indy.genotype == null)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.m_Range == null) || (indy.m_Range == null)) {
|
||||
if ((this.initializationRange == null) || (indy.initializationRange == null)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
if (this.m_Genotype[i] != indy.m_Genotype[i]) {
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
if (this.genotype[i] != indy.genotype[i]) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range[i][0] != indy.m_Range[i][0]) {
|
||||
if (this.initializationRange[i][0] != indy.initializationRange[i][0]) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range[i][1] != indy.m_Range[i][1]) {
|
||||
if (this.initializationRange[i][1] != indy.initializationRange[i][1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -111,11 +111,11 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setBinaryDataLength(int length) {
|
||||
this.m_Genotype = new double[length];
|
||||
this.m_Range = new double[length][2];
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
this.m_Range[i][0] = 0;
|
||||
this.m_Range[i][1] = 1;
|
||||
this.genotype = new double[length];
|
||||
this.initializationRange = new double[length][2];
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
this.initializationRange[i][0] = 0;
|
||||
this.initializationRange[i][1] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.m_Genotype.length;
|
||||
return this.genotype.length;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,26 +136,26 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBinaryData() {
|
||||
if (this.m_UseHardSwitch) {
|
||||
if (this.useHardSwitch) {
|
||||
// In this case it is only tested if the genotyp is bigger than 0.5
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
if (this.m_Genotype[i] > 0.5) {
|
||||
this.m_Phenotype.set(i);
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
if (this.genotype[i] > 0.5) {
|
||||
this.phenotype.set(i);
|
||||
} else {
|
||||
this.m_Phenotype.clear(i);
|
||||
this.phenotype.clear(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// in this case the value of the genotype is interpreted as a probability
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
if (RNG.flipCoin(this.m_Genotype[i])) {
|
||||
this.m_Phenotype.set(i);
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
if (RNG.flipCoin(this.genotype[i])) {
|
||||
this.phenotype.set(i);
|
||||
} else {
|
||||
this.m_Phenotype.clear(i);
|
||||
this.phenotype.clear(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +166,7 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBinaryDataWithoutUpdate() {
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,7 +176,7 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setBinaryPhenotype(BitSet binaryData) {
|
||||
this.m_Phenotype = binaryData;
|
||||
this.phenotype = binaryData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,26 +188,23 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
@Override
|
||||
public void setBinaryGenotype(BitSet binaryData) {
|
||||
this.setBinaryPhenotype(binaryData);
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
if (this.m_UseHardSwitch) {
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
if (this.useHardSwitch) {
|
||||
if (binaryData.get(i)) {
|
||||
this.m_Genotype[i] = RNG.randomDouble(0.55, 1.0);
|
||||
this.genotype[i] = RNG.randomDouble(0.55, 1.0);
|
||||
} else {
|
||||
this.m_Genotype[i] = RNG.randomDouble(0.0, 0.45);
|
||||
this.genotype[i] = RNG.randomDouble(0.0, 0.45);
|
||||
}
|
||||
} else {
|
||||
if (binaryData.get(i)) {
|
||||
this.m_Genotype[i] = 0.9;
|
||||
this.genotype[i] = 0.9;
|
||||
} else {
|
||||
this.m_Genotype[i] = 0.1;
|
||||
this.genotype[i] = 0.1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* AbstractEAIndividual methods
|
||||
*/
|
||||
/**
|
||||
* This method will init the individual with a given value for the
|
||||
* phenotype.
|
||||
@ -248,17 +245,13 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
}
|
||||
result += "})\n Value: ";
|
||||
result += "[";
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
result += this.m_Genotype[i] + "; ";
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
result += this.genotype[i] + "; ";
|
||||
}
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* InterfaceESIndividual methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method will allow the user to read the ES 'genotype'
|
||||
*
|
||||
@ -266,7 +259,7 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public double[] getDGenotype() {
|
||||
return this.m_Genotype;
|
||||
return this.genotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,34 +269,26 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setDGenotype(double[] b) {
|
||||
this.m_Genotype = b;
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
if (this.m_Genotype[i] < this.m_Range[i][0]) {
|
||||
this.m_Genotype[i] = this.m_Range[1][0];
|
||||
this.genotype = b;
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
if (this.genotype[i] < this.initializationRange[i][0]) {
|
||||
this.genotype[i] = this.initializationRange[1][0];
|
||||
}
|
||||
if (this.m_Genotype[i] > this.m_Range[i][1]) {
|
||||
this.m_Genotype[i] = this.m_Range[1][1];
|
||||
if (this.genotype[i] > this.initializationRange[i][1]) {
|
||||
this.genotype[i] = this.initializationRange[1][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /** This method will set the range of the double attributes. If range.length
|
||||
// * does not equal doubledata.length only range[i] will be used to set all
|
||||
// * ranges.
|
||||
// * @param range The new range for the double data.
|
||||
// */
|
||||
// public void setDoubleRange(double[][] range) {
|
||||
// this.m_Range = range;
|
||||
// }
|
||||
|
||||
/**
|
||||
* This method will return the range for all double attributes.
|
||||
*
|
||||
* @return The range array.
|
||||
* @return The initializationRange array.
|
||||
*/
|
||||
@Override
|
||||
public double[][] getDoubleRange() {
|
||||
return this.m_Range;
|
||||
return this.initializationRange;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,15 +296,15 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
ESIndividualDoubleData.defaultMutate(m_Genotype, m_Range);
|
||||
ESIndividualDoubleData.defaultMutate(genotype, initializationRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
if ((prob != null) && (prob instanceof InterfaceHasInitRange) && (((InterfaceHasInitRange) prob).getInitRange() != null)) {
|
||||
ESIndividualDoubleData.defaultInit(m_Genotype, (double[][]) ((InterfaceHasInitRange) prob).getInitRange());
|
||||
ESIndividualDoubleData.defaultInit(genotype, (double[][]) ((InterfaceHasInitRange) prob).getInitRange());
|
||||
} else {
|
||||
ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
|
||||
ESIndividualDoubleData.defaultInit(genotype, initializationRange);
|
||||
}
|
||||
}
|
||||
/**********************************************************************************************************************
|
||||
@ -343,11 +328,11 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
* @param b the Switch.
|
||||
*/
|
||||
public void setToggleInterpretation(boolean b) {
|
||||
this.m_UseHardSwitch = b;
|
||||
this.useHardSwitch = b;
|
||||
}
|
||||
|
||||
public boolean getToggleInterpretation() {
|
||||
return this.m_UseHardSwitch;
|
||||
return this.useHardSwitch;
|
||||
}
|
||||
|
||||
public String toggleInterpretationTipText() {
|
||||
|
@ -137,14 +137,6 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
this.genotype = newDesPa;
|
||||
this.range = newRange;
|
||||
this.phenotype = null; // mark as invalid
|
||||
|
||||
// changed 28.08.03 by request of Spieth
|
||||
// this.m_DecisionParameters = new double[length];
|
||||
// this.range = new double[length][2];
|
||||
// for (int i = 0; i < this.range.length; i++) {
|
||||
// this.range[i][0] = -10;
|
||||
// this.range[i][1] = 10;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,9 +15,9 @@ import eva2.util.annotation.Description;
|
||||
@Description(value = "This is an ES individual suited to optimize permutations.")
|
||||
public class ESIndividualPermutationData extends AbstractEAIndividual implements InterfaceESIndividual, InterfaceDataTypePermutation, java.io.Serializable {
|
||||
|
||||
private double[][] m_Genotype;
|
||||
private int[][] m_Phenotype;
|
||||
private double[][][] m_Range;
|
||||
private double[][] genotype;
|
||||
private int[][] phenotype;
|
||||
private double[][][] initializationRange;
|
||||
private int[] firstindex;
|
||||
|
||||
|
||||
@ -26,34 +26,34 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
this.mutationOperator = new MutateESGlobal();
|
||||
this.crossoverProbability = 0.5;
|
||||
this.crossoverOperator = new CrossoverESDefault();
|
||||
this.m_Genotype = new double[1][1];
|
||||
this.m_Range = new double[1][1][2];
|
||||
this.m_Range[0][0][0] = 0;
|
||||
this.m_Range[0][0][1] = 1;
|
||||
this.genotype = new double[1][1];
|
||||
this.initializationRange = new double[1][1][2];
|
||||
this.initializationRange[0][0][0] = 0;
|
||||
this.initializationRange[0][0][1] = 1;
|
||||
this.firstindex = new int[]{0};
|
||||
}
|
||||
|
||||
public ESIndividualPermutationData(ESIndividualPermutationData individual) {
|
||||
if (individual.m_Phenotype != null) {
|
||||
this.m_Phenotype = new int[individual.m_Phenotype.length][];
|
||||
for (int i = 0; i < m_Phenotype.length; i++) {
|
||||
this.m_Phenotype[i] = new int[individual.m_Phenotype[i].length];
|
||||
System.arraycopy(individual.m_Phenotype[i], 0, this.m_Phenotype[i], 0, this.m_Phenotype[i].length);
|
||||
if (individual.phenotype != null) {
|
||||
this.phenotype = new int[individual.phenotype.length][];
|
||||
for (int i = 0; i < phenotype.length; i++) {
|
||||
this.phenotype[i] = new int[individual.phenotype[i].length];
|
||||
System.arraycopy(individual.phenotype[i], 0, this.phenotype[i], 0, this.phenotype[i].length);
|
||||
}
|
||||
}
|
||||
|
||||
this.firstindex = individual.firstindex;
|
||||
this.m_Genotype = new double[individual.m_Genotype.length][];
|
||||
this.m_Range = new double[individual.m_Genotype.length][][];
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
this.genotype = new double[individual.genotype.length][];
|
||||
this.initializationRange = new double[individual.genotype.length][][];
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
// if (individual.phenotype != null) {
|
||||
|
||||
this.m_Genotype[i] = new double[individual.m_Genotype[i].length];
|
||||
this.m_Range[i] = new double[individual.m_Genotype[i].length][2];
|
||||
for (int j = 0; j < this.m_Genotype[i].length; j++) {
|
||||
this.m_Genotype[i][j] = individual.m_Genotype[i][j];
|
||||
this.m_Range[i][j][0] = individual.m_Range[i][j][0];
|
||||
this.m_Range[i][j][1] = individual.m_Range[i][j][1];
|
||||
this.genotype[i] = new double[individual.genotype[i].length];
|
||||
this.initializationRange[i] = new double[individual.genotype[i].length][2];
|
||||
for (int j = 0; j < this.genotype[i].length; j++) {
|
||||
this.genotype[i][j] = individual.genotype[i][j];
|
||||
this.initializationRange[i][j][0] = individual.initializationRange[i][j][0];
|
||||
this.initializationRange[i][j][1] = individual.initializationRange[i][j][1];
|
||||
// }
|
||||
}
|
||||
}
|
||||
@ -91,23 +91,23 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof ESIndividualPermutationData) {
|
||||
ESIndividualPermutationData indy = (ESIndividualPermutationData) individual;
|
||||
if ((this.m_Genotype == null) || (indy.m_Genotype == null)) {
|
||||
if ((this.genotype == null) || (indy.genotype == null)) {
|
||||
return false;
|
||||
}
|
||||
if ((this.m_Range == null) || (indy.m_Range == null)) {
|
||||
if ((this.initializationRange == null) || (indy.initializationRange == null)) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range.length != indy.m_Range.length) {
|
||||
if (this.initializationRange.length != indy.initializationRange.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
if (this.m_Genotype[i] != indy.m_Genotype[i]) {
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
if (this.genotype[i] != indy.genotype[i]) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range[i][0] != indy.m_Range[i][0]) {
|
||||
if (this.initializationRange[i][0] != indy.initializationRange[i][0]) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range[i][1] != indy.m_Range[i][1]) {
|
||||
if (this.initializationRange[i][1] != indy.initializationRange[i][1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -125,40 +125,40 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
@Override
|
||||
public void setPermutationDataLength(int[] length) {
|
||||
|
||||
this.m_Genotype = new double[length.length][];
|
||||
this.m_Range = new double[length.length][][];
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
this.m_Genotype[i] = new double[length[i]];
|
||||
this.genotype = new double[length.length][];
|
||||
this.initializationRange = new double[length.length][][];
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
this.genotype[i] = new double[length[i]];
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
|
||||
this.m_Range[i] = new double[length[i]][2];
|
||||
for (int j = 0; j < this.m_Range[i].length; j++) {
|
||||
this.m_Range[i][j][0] = 0;
|
||||
this.m_Range[i][j][1] = 1;
|
||||
this.initializationRange[i] = new double[length[i]][2];
|
||||
for (int j = 0; j < this.initializationRange[i].length; j++) {
|
||||
this.initializationRange[i][j][0] = 0;
|
||||
this.initializationRange[i][j][1] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] sizePermutation() {
|
||||
int[] res = new int[m_Genotype.length];
|
||||
for (int i = 0; i < m_Genotype.length; i++) {
|
||||
res[i] = m_Genotype[i].length;
|
||||
int[] res = new int[genotype.length];
|
||||
for (int i = 0; i < genotype.length; i++) {
|
||||
res[i] = genotype[i].length;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermutationPhenotype(int[][] perm) {
|
||||
this.m_Phenotype = perm;
|
||||
this.m_Range = new double[perm.length][][];
|
||||
this.phenotype = perm;
|
||||
this.initializationRange = new double[perm.length][][];
|
||||
for (int i = 0; i < perm.length; i++) {
|
||||
this.m_Range[i] = new double[perm[i].length][2];
|
||||
for (int j = 0; j < this.m_Range[i].length; j++) {
|
||||
this.m_Range[i][j][0] = 0;
|
||||
this.m_Range[i][j][1] = 1;
|
||||
this.initializationRange[i] = new double[perm[i].length][2];
|
||||
for (int j = 0; j < this.initializationRange[i].length; j++) {
|
||||
this.initializationRange[i][j][0] = 0;
|
||||
this.initializationRange[i][j][1] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,12 +168,12 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
public void setPermutationGenotype(int[][] perm) {
|
||||
this.setPermutationPhenotype(perm);
|
||||
|
||||
this.m_Genotype = new double[perm.length][];
|
||||
this.m_Range = new double[perm.length][][];
|
||||
this.genotype = new double[perm.length][];
|
||||
this.initializationRange = new double[perm.length][][];
|
||||
for (int p = 0; p < perm.length; p++) {
|
||||
int biggest = Integer.MIN_VALUE;
|
||||
int smallest = Integer.MAX_VALUE;
|
||||
this.m_Range[p] = new double[perm[p].length][2];
|
||||
this.initializationRange[p] = new double[perm[p].length][2];
|
||||
for (int i = 0; i < perm[p].length; i++) {
|
||||
if (perm[p][i] > biggest) {
|
||||
biggest = perm[p][i];
|
||||
@ -181,11 +181,11 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
if (perm[p][i] < smallest) {
|
||||
smallest = perm[p][i];
|
||||
}
|
||||
this.m_Range[p][i][0] = 0;
|
||||
this.m_Range[p][i][1] = 1;
|
||||
this.initializationRange[p][i][0] = 0;
|
||||
this.initializationRange[p][i][1] = 1;
|
||||
}
|
||||
for (int i = 0; i < this.m_Genotype[p].length; i++) {
|
||||
this.m_Genotype[p][i] = (perm[p][i] - smallest) / (double) biggest;
|
||||
for (int i = 0; i < this.genotype[p].length; i++) {
|
||||
this.genotype[p][i] = (perm[p][i] - smallest) / (double) biggest;
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,31 +194,31 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
|
||||
@Override
|
||||
public int[][] getPermutationData() {
|
||||
this.m_Phenotype = new int[this.m_Genotype.length][];
|
||||
for (int p = 0; p < m_Genotype.length; p++) {
|
||||
this.m_Phenotype[p] = new int[m_Genotype[p].length];
|
||||
this.phenotype = new int[this.genotype.length][];
|
||||
for (int p = 0; p < genotype.length; p++) {
|
||||
this.phenotype[p] = new int[genotype[p].length];
|
||||
boolean notValid = true;
|
||||
while (notValid) {
|
||||
notValid = false;
|
||||
for (int i = 0; i < this.m_Genotype[p].length; i++) {
|
||||
for (int j = 0; j < this.m_Genotype[p].length; j++) {
|
||||
if ((i != j) && (this.m_Genotype[p][i] == this.m_Genotype[p][j])) {
|
||||
for (int i = 0; i < this.genotype[p].length; i++) {
|
||||
for (int j = 0; j < this.genotype[p].length; j++) {
|
||||
if ((i != j) && (this.genotype[p][i] == this.genotype[p][j])) {
|
||||
notValid = true;
|
||||
this.m_Genotype[p][j] = RNG.randomDouble(0, 1);
|
||||
this.genotype[p][j] = RNG.randomDouble(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (int i = 0; i < this.m_Genotype[p].length; i++) {
|
||||
for (int j = 0; j < this.m_Genotype[p].length; j++) {
|
||||
if (this.m_Genotype[p][i] > this.m_Genotype[p][j]) {
|
||||
this.m_Phenotype[p][i]++;
|
||||
for (int i = 0; i < this.genotype[p].length; i++) {
|
||||
for (int j = 0; j < this.genotype[p].length; j++) {
|
||||
if (this.genotype[p][i] > this.genotype[p][j]) {
|
||||
this.phenotype[p][i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,7 +229,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
*/
|
||||
@Override
|
||||
public int[][] getPermutationDataWithoutUpdate() {
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
public int[] getFirstindex() {
|
||||
@ -256,7 +256,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
||||
if (obj instanceof int[][]) {
|
||||
int[][] bs = (int[][]) obj;
|
||||
if (bs.length != this.m_Genotype.length) {
|
||||
if (bs.length != this.genotype.length) {
|
||||
System.out.println("Init value and requested length doesn't match!");
|
||||
}
|
||||
this.setPermutationGenotype(bs);
|
||||
@ -288,8 +288,8 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
}
|
||||
result += "})\n Value: ";
|
||||
result += "[";
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
result += this.m_Genotype[i] + "; ";
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
result += this.genotype[i] + "; ";
|
||||
}
|
||||
result += "]";
|
||||
return result;
|
||||
@ -305,7 +305,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
*/
|
||||
@Override
|
||||
public double[] getDGenotype() {
|
||||
return mapMatrixToVector(m_Genotype);
|
||||
return mapMatrixToVector(genotype);
|
||||
}
|
||||
|
||||
|
||||
@ -346,14 +346,14 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
*/
|
||||
@Override
|
||||
public void setDGenotype(double[] b) {
|
||||
this.m_Genotype = mapVectorToMatrix(b, this.sizePermutation());
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
for (int j = 0; j < this.m_Genotype[i].length; j++) {
|
||||
if (this.m_Genotype[i][j] < this.m_Range[i][j][0]) {
|
||||
this.m_Genotype[i][j] = this.m_Range[i][j][0];
|
||||
this.genotype = mapVectorToMatrix(b, this.sizePermutation());
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
for (int j = 0; j < this.genotype[i].length; j++) {
|
||||
if (this.genotype[i][j] < this.initializationRange[i][j][0]) {
|
||||
this.genotype[i][j] = this.initializationRange[i][j][0];
|
||||
}
|
||||
if (this.m_Genotype[i][j] > this.m_Range[i][j][1]) {
|
||||
this.m_Genotype[i][j] = this.m_Range[i][j][1];
|
||||
if (this.genotype[i][j] > this.initializationRange[i][j][1]) {
|
||||
this.genotype[i][j] = this.initializationRange[i][j][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -366,20 +366,20 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
*/
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
for (int i = 0; i < m_Genotype.length; i++) {
|
||||
ESIndividualDoubleData.defaultMutate(m_Genotype[i], m_Range[i]);
|
||||
for (int i = 0; i < genotype.length; i++) {
|
||||
ESIndividualDoubleData.defaultMutate(genotype[i], initializationRange[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
double[][][] range = m_Range;
|
||||
double[][][] range = initializationRange;
|
||||
if ((prob != null) && (prob instanceof InterfaceHasInitRange) && (((InterfaceHasInitRange) prob).getInitRange() != null)) {
|
||||
range = (double[][][]) ((InterfaceHasInitRange) prob).getInitRange();
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
ESIndividualDoubleData.defaultInit(m_Genotype[i], range[i]);
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
ESIndividualDoubleData.defaultInit(genotype[i], range[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,15 +391,15 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
@Override
|
||||
public double[][] getDoubleRange() {
|
||||
int sumentries = 0;
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
sumentries += this.m_Range[i].length;
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
sumentries += this.initializationRange[i].length;
|
||||
}
|
||||
double[][] res = new double[sumentries][2];
|
||||
int counter = 0;
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
for (int j = 0; j < this.m_Range[i].length; j++) {
|
||||
res[counter][0] = this.m_Range[i][j][0];
|
||||
res[counter][1] = this.m_Range[i][j][1];
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
for (int j = 0; j < this.initializationRange[i].length; j++) {
|
||||
res[counter][0] = this.initializationRange[i][j][0];
|
||||
res[counter][1] = this.initializationRange[i][j][1];
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
@ -15,19 +15,19 @@ import java.util.BitSet;
|
||||
@Description(value = "This is a mixed data type combining a BitSet and a real-valued vector.")
|
||||
public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual implements InterfaceDataTypeBinary, InterfaceDataTypeDouble, java.io.Serializable {
|
||||
|
||||
private InterfaceDataTypeDouble m_Numbers = new ESIndividualDoubleData();
|
||||
private InterfaceDataTypeBinary m_BitSet = new GAIndividualBinaryData();
|
||||
private InterfaceDataTypeDouble doubleIndividual = new ESIndividualDoubleData();
|
||||
private InterfaceDataTypeBinary binaryIndividual = new GAIndividualBinaryData();
|
||||
|
||||
public GAESIndividualBinaryDoubleData() {
|
||||
this.mutationProbability = 1.0;
|
||||
this.crossoverProbability = 1.0;
|
||||
this.m_Numbers = new GAIndividualDoubleData();
|
||||
this.m_BitSet = new GAIndividualBinaryData();
|
||||
this.doubleIndividual = new GAIndividualDoubleData();
|
||||
this.binaryIndividual = new GAIndividualBinaryData();
|
||||
}
|
||||
|
||||
public GAESIndividualBinaryDoubleData(GAESIndividualBinaryDoubleData individual) {
|
||||
this.m_Numbers = (InterfaceDataTypeDouble) ((AbstractEAIndividual) individual.getNumbers()).clone();
|
||||
this.m_BitSet = (InterfaceDataTypeBinary) ((AbstractEAIndividual) individual.getBitSet()).clone();
|
||||
this.doubleIndividual = (InterfaceDataTypeDouble) ((AbstractEAIndividual) individual.getNumbers()).clone();
|
||||
this.binaryIndividual = (InterfaceDataTypeBinary) ((AbstractEAIndividual) individual.getBitSet()).clone();
|
||||
|
||||
// cloning the members of AbstractEAIndividual
|
||||
this.age = individual.age;
|
||||
@ -61,10 +61,10 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof GAESIndividualBinaryDoubleData) {
|
||||
GAESIndividualBinaryDoubleData indy = (GAESIndividualBinaryDoubleData) individual;
|
||||
if (!((AbstractEAIndividual) this.m_Numbers).equalGenotypes((AbstractEAIndividual) indy.m_Numbers)) {
|
||||
if (!((AbstractEAIndividual) this.doubleIndividual).equalGenotypes((AbstractEAIndividual) indy.doubleIndividual)) {
|
||||
return false;
|
||||
}
|
||||
if (!((AbstractEAIndividual) this.m_BitSet).equalGenotypes((AbstractEAIndividual) indy.m_BitSet)) {
|
||||
if (!((AbstractEAIndividual) this.binaryIndividual).equalGenotypes((AbstractEAIndividual) indy.binaryIndividual)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -80,14 +80,14 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void init(InterfaceOptimizationProblem opt) {
|
||||
((AbstractEAIndividual) this.m_Numbers).init(opt);
|
||||
((AbstractEAIndividual) this.m_BitSet).init(opt);
|
||||
((AbstractEAIndividual) this.doubleIndividual).init(opt);
|
||||
((AbstractEAIndividual) this.binaryIndividual).init(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
((AbstractEAIndividual) this.m_Numbers).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.m_BitSet).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.doubleIndividual).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.binaryIndividual).defaultInit(prob);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,15 +101,15 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
||||
if (obj instanceof Object[]) {
|
||||
if (((Object[]) obj)[0] instanceof double[]) {
|
||||
((AbstractEAIndividual) this.m_Numbers).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.m_BitSet).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.doubleIndividual).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.binaryIndividual).initByValue(((Object[]) obj)[1], opt);
|
||||
} else {
|
||||
((AbstractEAIndividual) this.m_Numbers).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.m_BitSet).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.doubleIndividual).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.binaryIndividual).initByValue(((Object[]) obj)[0], opt);
|
||||
}
|
||||
} else {
|
||||
((AbstractEAIndividual) this.m_Numbers).init(opt);
|
||||
((AbstractEAIndividual) this.m_BitSet).init(opt);
|
||||
((AbstractEAIndividual) this.doubleIndividual).init(opt);
|
||||
((AbstractEAIndividual) this.binaryIndividual).init(opt);
|
||||
System.out.println("Initial value for GAESIndividualDoubleData is not suitable!");
|
||||
}
|
||||
}
|
||||
@ -120,17 +120,17 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
@Override
|
||||
public void mutate() {
|
||||
if (RNG.flipCoin(this.mutationProbability)) {
|
||||
((AbstractEAIndividual) this.m_Numbers).mutate();
|
||||
((AbstractEAIndividual) this.doubleIndividual).mutate();
|
||||
}
|
||||
if (RNG.flipCoin(this.mutationProbability)) {
|
||||
((AbstractEAIndividual) this.m_BitSet).mutate();
|
||||
((AbstractEAIndividual) this.binaryIndividual).mutate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
((AbstractEAIndividual) this.m_Numbers).defaultMutate();
|
||||
((AbstractEAIndividual) this.m_BitSet).defaultMutate();
|
||||
((AbstractEAIndividual) this.doubleIndividual).defaultMutate();
|
||||
((AbstractEAIndividual) this.binaryIndividual).defaultMutate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +173,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
((GAESIndividualBinaryDoubleData) result[i]).setBitSet((InterfaceDataTypeBinary) resBin[i]);
|
||||
}
|
||||
|
||||
// result = ((AbstractEAIndividual)this.m_Numbers).mateWith(partners);
|
||||
// result = ((AbstractEAIndividual)this.doubleIndividual).mateWith(partners);
|
||||
// AbstractEAIndividual dad = (AbstractEAIndividual)result[0];
|
||||
// Population tpartners = new Population();
|
||||
// for (int i = 1; i < result.length; i++) tpartners.add(result[i]);
|
||||
@ -206,8 +206,8 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
String result = "This is a hybrid Individual:\n";
|
||||
result += "The Numbers Part:\n" + ((AbstractEAIndividual) this.m_Numbers).getStringRepresentation();
|
||||
result += "\nThe Binarys Part:\n" + ((AbstractEAIndividual) this.m_BitSet).getStringRepresentation();
|
||||
result += "The Numbers Part:\n" + ((AbstractEAIndividual) this.doubleIndividual).getStringRepresentation();
|
||||
result += "\nThe Binarys Part:\n" + ((AbstractEAIndividual) this.binaryIndividual).getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -221,8 +221,8 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void setDoubleDataLength(int length) {
|
||||
this.m_Numbers.setDoubleDataLength(length);
|
||||
this.m_BitSet.setBinaryDataLength(length);
|
||||
this.doubleIndividual.setDoubleDataLength(length);
|
||||
this.binaryIndividual.setBinaryDataLength(length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +232,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.m_Numbers.size();
|
||||
return this.doubleIndividual.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,7 +244,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void setDoubleRange(double[][] range) {
|
||||
this.m_Numbers.setDoubleRange(range);
|
||||
this.doubleIndividual.setDoubleRange(range);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,7 +254,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public double[][] getDoubleRange() {
|
||||
return this.m_Numbers.getDoubleRange();
|
||||
return this.doubleIndividual.getDoubleRange();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +264,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public double[] getDoubleData() {
|
||||
return this.m_Numbers.getDoubleData();
|
||||
return this.doubleIndividual.getDoubleData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -275,7 +275,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public double[] getDoubleDataWithoutUpdate() {
|
||||
return this.m_Numbers.getDoubleDataWithoutUpdate();
|
||||
return this.doubleIndividual.getDoubleDataWithoutUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,7 +286,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void setDoublePhenotype(double[] doubleData) {
|
||||
this.m_Numbers.setDoublePhenotype(doubleData);
|
||||
this.doubleIndividual.setDoublePhenotype(doubleData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,7 +298,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void setDoubleGenotype(double[] doubleData) {
|
||||
this.m_Numbers.setDoubleGenotype(doubleData);
|
||||
this.doubleIndividual.setDoubleGenotype(doubleData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,8 +311,8 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void setBinaryDataLength(int length) {
|
||||
this.m_Numbers.setDoubleDataLength(length);
|
||||
this.m_BitSet.setBinaryDataLength(length);
|
||||
this.doubleIndividual.setDoubleDataLength(length);
|
||||
this.binaryIndividual.setBinaryDataLength(length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,7 +321,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
* @return The number of bits stored
|
||||
*/
|
||||
public int GetBinaryDataLength() {
|
||||
return this.m_BitSet.size();
|
||||
return this.binaryIndividual.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -331,7 +331,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBinaryData() {
|
||||
return this.m_BitSet.getBinaryData();
|
||||
return this.binaryIndividual.getBinaryData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,7 +342,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBinaryDataWithoutUpdate() {
|
||||
return this.m_BitSet.getBinaryDataWithoutUpdate();
|
||||
return this.binaryIndividual.getBinaryDataWithoutUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -353,7 +353,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void setBinaryPhenotype(BitSet binaryData) {
|
||||
this.m_BitSet.setBinaryPhenotype(binaryData);
|
||||
this.binaryIndividual.setBinaryPhenotype(binaryData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -365,7 +365,7 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
*/
|
||||
@Override
|
||||
public void setBinaryGenotype(BitSet binaryData) {
|
||||
this.m_BitSet.setBinaryGenotype(binaryData);
|
||||
this.binaryIndividual.setBinaryGenotype(binaryData);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
@ -388,11 +388,11 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
* @param Numbers The new representation for the inner constants.
|
||||
*/
|
||||
public void setNumbers(InterfaceDataTypeDouble Numbers) {
|
||||
this.m_Numbers = Numbers;
|
||||
this.doubleIndividual = Numbers;
|
||||
}
|
||||
|
||||
public InterfaceDataTypeDouble getNumbers() {
|
||||
return this.m_Numbers;
|
||||
return this.doubleIndividual;
|
||||
}
|
||||
|
||||
public String numbersTipText() {
|
||||
@ -405,11 +405,11 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
||||
* @param BitSet The new representation for the inner constants.
|
||||
*/
|
||||
public void setBitSet(InterfaceDataTypeBinary BitSet) {
|
||||
this.m_BitSet = BitSet;
|
||||
this.binaryIndividual = BitSet;
|
||||
}
|
||||
|
||||
public InterfaceDataTypeBinary getBitSet() {
|
||||
return this.m_BitSet;
|
||||
return this.binaryIndividual;
|
||||
}
|
||||
|
||||
public String bitSetTipText() {
|
||||
|
@ -17,17 +17,17 @@ import java.util.BitSet;
|
||||
@Description(value = "This is a GA individual suited to optimize binary values.")
|
||||
public class GAIndividualBinaryData extends AbstractEAIndividual implements InterfaceDataTypeBinary, InterfaceGAIndividual, java.io.Serializable {
|
||||
|
||||
protected BitSet m_Genotype = new BitSet();
|
||||
protected BitSet m_Phenotype = new BitSet();
|
||||
protected int m_GenotypeLength;
|
||||
protected BitSet genotype = new BitSet();
|
||||
protected BitSet phenotype = new BitSet();
|
||||
protected int genotypeLength;
|
||||
|
||||
public GAIndividualBinaryData() {
|
||||
this.mutationProbability = 0.1;
|
||||
this.mutationOperator = new MutateGANBit();
|
||||
this.crossoverProbability = 1.0;
|
||||
this.crossoverOperator = new CrossoverGAGINPoint();
|
||||
this.m_GenotypeLength = 20;
|
||||
this.m_Genotype = new BitSet();
|
||||
this.genotypeLength = 20;
|
||||
this.genotype = new BitSet();
|
||||
}
|
||||
|
||||
public GAIndividualBinaryData(int genotypeLen) {
|
||||
@ -36,12 +36,12 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
}
|
||||
|
||||
public GAIndividualBinaryData(GAIndividualBinaryData individual) {
|
||||
if (individual.m_Phenotype != null) {
|
||||
this.m_Phenotype = (BitSet) individual.m_Phenotype.clone();
|
||||
if (individual.phenotype != null) {
|
||||
this.phenotype = (BitSet) individual.phenotype.clone();
|
||||
}
|
||||
this.m_GenotypeLength = individual.m_GenotypeLength;
|
||||
if (individual.m_Genotype != null) {
|
||||
this.m_Genotype = (BitSet) individual.m_Genotype.clone();
|
||||
this.genotypeLength = individual.genotypeLength;
|
||||
if (individual.genotype != null) {
|
||||
this.genotype = (BitSet) individual.genotype.clone();
|
||||
}
|
||||
|
||||
// cloning the members of AbstractEAIndividual
|
||||
@ -76,13 +76,13 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof GAIndividualBinaryData) {
|
||||
GAIndividualBinaryData indy = (GAIndividualBinaryData) individual;
|
||||
if (this.m_GenotypeLength != indy.m_GenotypeLength) {
|
||||
if (this.genotypeLength != indy.genotypeLength) {
|
||||
return false;
|
||||
}
|
||||
if ((this.m_Genotype == null) || (indy.m_Genotype == null)) {
|
||||
if ((this.genotype == null) || (indy.genotype == null)) {
|
||||
return false;
|
||||
}
|
||||
if (!this.m_Genotype.equals(indy.m_Genotype)) {
|
||||
if (!this.genotype.equals(indy.genotype)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -99,8 +99,8 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
public double defaultEvaulateAsMiniBits() {
|
||||
double result = 0;
|
||||
for (int i = 0; i < this.m_GenotypeLength; i++) {
|
||||
if (this.m_Genotype.get(i)) {
|
||||
for (int i = 0; i < this.genotypeLength; i++) {
|
||||
if (this.genotype.get(i)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
@ -162,11 +162,11 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
}
|
||||
result += "})\n Value: ";
|
||||
result += "{";
|
||||
for (int i = 0; i < this.m_GenotypeLength; i++) {
|
||||
for (int i = 0; i < this.genotypeLength; i++) {
|
||||
if (i % 8 == 0) {
|
||||
result += "|";
|
||||
}
|
||||
if (this.m_Genotype.get(i)) {
|
||||
if (this.genotype.get(i)) {
|
||||
result += "1";
|
||||
} else {
|
||||
result += "0";
|
||||
@ -184,7 +184,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBGenotype() {
|
||||
return this.m_Genotype;
|
||||
return this.genotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,7 +195,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setBGenotype(BitSet binaryData) {
|
||||
this.m_Genotype = binaryData;
|
||||
this.genotype = binaryData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,16 +207,16 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public int getGenotypeLength() {
|
||||
return this.m_GenotypeLength;
|
||||
return this.genotypeLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
for (int i = 0; i < this.m_GenotypeLength; i++) {
|
||||
for (int i = 0; i < this.genotypeLength; i++) {
|
||||
if (RNG.flipCoin(0.5)) {
|
||||
this.m_Genotype.set(i);
|
||||
this.genotype.set(i);
|
||||
} else {
|
||||
this.m_Genotype.clear(i);
|
||||
this.genotype.clear(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,12 +226,12 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
int mutationIndex = RNG.randomInt(0, this.m_GenotypeLength);
|
||||
int mutationIndex = RNG.randomInt(0, this.genotypeLength);
|
||||
//if (mutationIndex > 28) System.out.println("Mutate: " + this.getSolutionRepresentationFor());
|
||||
if (this.m_Genotype.get(mutationIndex)) {
|
||||
this.m_Genotype.clear(mutationIndex);
|
||||
if (this.genotype.get(mutationIndex)) {
|
||||
this.genotype.clear(mutationIndex);
|
||||
} else {
|
||||
this.m_Genotype.set(mutationIndex);
|
||||
this.genotype.set(mutationIndex);
|
||||
}
|
||||
//if (mutationIndex > 28) System.out.println(this.getSolutionRepresentationFor());
|
||||
}
|
||||
@ -246,7 +246,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setBinaryDataLength(int length) {
|
||||
this.m_GenotypeLength = length;
|
||||
this.genotypeLength = length;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,7 +256,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.m_GenotypeLength;
|
||||
return this.genotypeLength;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -266,8 +266,8 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBinaryData() {
|
||||
this.m_Phenotype = (BitSet) this.m_Genotype.clone();
|
||||
return this.m_Phenotype;
|
||||
this.phenotype = (BitSet) this.genotype.clone();
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -278,7 +278,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBinaryDataWithoutUpdate() {
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -288,7 +288,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setBinaryPhenotype(BitSet binaryData) {
|
||||
this.m_Phenotype = binaryData;
|
||||
this.phenotype = binaryData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -300,7 +300,7 @@ public class GAIndividualBinaryData extends AbstractEAIndividual implements Inte
|
||||
@Override
|
||||
public void setBinaryGenotype(BitSet binaryData) {
|
||||
this.setBinaryPhenotype(binaryData);
|
||||
this.m_Genotype = (BitSet) binaryData.clone();
|
||||
this.genotype = (BitSet) binaryData.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,36 +20,36 @@ import java.util.BitSet;
|
||||
@Description(value = "This is a GA individual suited to optimize double values.")
|
||||
public class GAIndividualDoubleData extends AbstractEAIndividual implements InterfaceGAIndividual, InterfaceDataTypeDouble, java.io.Serializable {
|
||||
|
||||
private double[] m_Phenotype;
|
||||
private double[][] m_Range;
|
||||
private double[] phenotype;
|
||||
private double[][] initializationRange;
|
||||
protected BitSet genotype;
|
||||
protected int genotypeLength;
|
||||
private int m_Precision = 32;
|
||||
private InterfaceGADoubleCoding m_DoubleCoding = new GAStandardCodingDouble();
|
||||
private int precision = 32;
|
||||
private InterfaceGADoubleCoding doubleCoding = new GAStandardCodingDouble();
|
||||
|
||||
public GAIndividualDoubleData() {
|
||||
this.mutationProbability = 0.1;
|
||||
this.mutationOperator = new MutateGAUniform();
|
||||
this.crossoverProbability = 0.7;
|
||||
this.crossoverOperator = new CrossoverGAGINPoint();
|
||||
this.m_Range = new double[1][2];
|
||||
this.m_Range[0][0] = -10;
|
||||
this.m_Range[0][1] = 10;
|
||||
this.genotypeLength = this.m_Precision;
|
||||
this.initializationRange = new double[1][2];
|
||||
this.initializationRange[0][0] = -10;
|
||||
this.initializationRange[0][1] = 10;
|
||||
this.genotypeLength = this.precision;
|
||||
this.genotype = new BitSet();
|
||||
}
|
||||
|
||||
public GAIndividualDoubleData(GAIndividualDoubleData individual) {
|
||||
if (individual.m_Phenotype != null) {
|
||||
this.m_Phenotype = new double[individual.m_Phenotype.length];
|
||||
System.arraycopy(individual.m_Phenotype, 0, this.m_Phenotype, 0, this.m_Phenotype.length);
|
||||
if (individual.phenotype != null) {
|
||||
this.phenotype = new double[individual.phenotype.length];
|
||||
System.arraycopy(individual.phenotype, 0, this.phenotype, 0, this.phenotype.length);
|
||||
}
|
||||
this.genotypeLength = individual.genotypeLength;
|
||||
this.genotype = (BitSet) individual.genotype.clone();
|
||||
this.m_Range = new double[individual.m_Range.length][2];
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
this.m_Range[i][0] = individual.m_Range[i][0];
|
||||
this.m_Range[i][1] = individual.m_Range[i][1];
|
||||
this.initializationRange = new double[individual.initializationRange.length][2];
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
this.initializationRange[i][0] = individual.initializationRange[i][0];
|
||||
this.initializationRange[i][1] = individual.initializationRange[i][1];
|
||||
}
|
||||
|
||||
// cloning the members of AbstractEAIndividual
|
||||
@ -62,8 +62,8 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
for (int i = 0; i < this.selectionProbability.length; i++) {
|
||||
this.selectionProbability[i] = individual.selectionProbability[i];
|
||||
}
|
||||
this.m_Precision = individual.m_Precision;
|
||||
this.m_DoubleCoding = individual.m_DoubleCoding;
|
||||
this.precision = individual.precision;
|
||||
this.doubleCoding = individual.doubleCoding;
|
||||
this.fitness = new double[individual.fitness.length];
|
||||
for (int i = 0; i < this.fitness.length; i++) {
|
||||
this.fitness[i] = individual.fitness[i];
|
||||
@ -96,11 +96,11 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
if (!this.genotype.equals(indy.genotype)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
if (this.m_Range[i][0] != indy.m_Range[i][0]) {
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
if (this.initializationRange[i][0] != indy.initializationRange[i][0]) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range[i][1] != indy.m_Range[i][1]) {
|
||||
if (this.initializationRange[i][1] != indy.initializationRange[i][1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -124,26 +124,18 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
double[][] newRange = new double[length][2];
|
||||
|
||||
// copy the old values for the decision parameters and the range
|
||||
for (int i = 0; ((i < newDesPa.length) && (i < this.m_Range.length)); i++) {
|
||||
newRange[i][0] = this.m_Range[i][0];
|
||||
newRange[i][1] = this.m_Range[i][1];
|
||||
for (int i = 0; ((i < newDesPa.length) && (i < this.initializationRange.length)); i++) {
|
||||
newRange[i][0] = this.initializationRange[i][0];
|
||||
newRange[i][1] = this.initializationRange[i][1];
|
||||
}
|
||||
|
||||
// if the new length is bigger than the last value fills the extra elements
|
||||
for (int i = this.m_Range.length; (i < newDesPa.length); i++) {
|
||||
newRange[i][0] = this.m_Range[this.m_Range.length - 1][0];
|
||||
newRange[i][1] = this.m_Range[this.m_Range.length - 1][1];
|
||||
for (int i = this.initializationRange.length; (i < newDesPa.length); i++) {
|
||||
newRange[i][0] = this.initializationRange[this.initializationRange.length - 1][0];
|
||||
newRange[i][1] = this.initializationRange[this.initializationRange.length - 1][1];
|
||||
}
|
||||
this.m_Range = newRange;
|
||||
this.genotypeLength = length * this.m_Precision;
|
||||
|
||||
// changed 28.08.03 by request of Spieth
|
||||
// this.m_DecisionParameters = new double[length];
|
||||
// this.m_Range = new double[length][2];
|
||||
// for (int i = 0; i < this.m_Range.length; i++) {
|
||||
// this.m_Range[i][0] = -10;
|
||||
// this.m_Range[i][1] = 10;
|
||||
// }
|
||||
this.initializationRange = newRange;
|
||||
this.genotypeLength = length * this.precision;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,7 +145,7 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.m_Range.length;
|
||||
return this.initializationRange.length;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,13 +157,13 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setDoubleRange(double[][] range) {
|
||||
if (range.length != this.m_Range.length) {
|
||||
if (range.length != this.initializationRange.length) {
|
||||
System.out.println("Warning: Trying to set a range of length " + range.length + " to a vector of length "
|
||||
+ this.m_Range.length + "!\n Use method setDoubleDataLength first!");
|
||||
+ this.initializationRange.length + "!\n Use method setDoubleDataLength first!");
|
||||
}
|
||||
for (int i = 0; ((i < this.m_Range.length) && (i < range.length)); i++) {
|
||||
this.m_Range[i][0] = range[i][0];
|
||||
this.m_Range[i][1] = range[i][1];
|
||||
for (int i = 0; ((i < this.initializationRange.length) && (i < range.length)); i++) {
|
||||
this.initializationRange[i][0] = range[i][0];
|
||||
this.initializationRange[i][1] = range[i][1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +174,7 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public double[][] getDoubleRange() {
|
||||
return this.m_Range;
|
||||
return this.initializationRange;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,13 +185,13 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
@Override
|
||||
public double[] getDoubleData() {
|
||||
int[] locus = new int[2];
|
||||
this.m_Phenotype = new double[this.m_Range.length];
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
locus[0] = i * this.m_Precision;
|
||||
locus[1] = this.m_Precision;
|
||||
this.m_Phenotype[i] = this.m_DoubleCoding.decodeValue(this.genotype, this.m_Range[i], locus, false);
|
||||
this.phenotype = new double[this.initializationRange.length];
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
locus[0] = i * this.precision;
|
||||
locus[1] = this.precision;
|
||||
this.phenotype[i] = this.doubleCoding.decodeValue(this.genotype, this.initializationRange[i], locus, false);
|
||||
}
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,7 +202,7 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public double[] getDoubleDataWithoutUpdate() {
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +213,7 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
*/
|
||||
@Override
|
||||
public void setDoublePhenotype(double[] doubleData) {
|
||||
this.m_Phenotype = doubleData;
|
||||
this.phenotype = doubleData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,9 +227,9 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
this.setDoublePhenotype(doubleData);
|
||||
int[] locus = new int[2];
|
||||
for (int i = 0; i < doubleData.length; i++) {
|
||||
locus[0] = i * this.m_Precision;
|
||||
locus[1] = this.m_Precision;
|
||||
this.m_DoubleCoding.codeValue(doubleData[i], this.m_Range[i], this.genotype, locus);
|
||||
locus[0] = i * this.precision;
|
||||
locus[1] = this.precision;
|
||||
this.doubleCoding.codeValue(doubleData[i], this.initializationRange[i], this.genotype, locus);
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +248,7 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
||||
if (obj instanceof double[]) {
|
||||
double[] bs = (double[]) obj;
|
||||
if (bs.length != this.m_Range.length) {
|
||||
if (bs.length != this.initializationRange.length) {
|
||||
System.out.println("Init value and requested length doesn't match!");
|
||||
}
|
||||
this.setDoubleGenotype(bs);
|
||||
@ -386,11 +378,11 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
* @param coding The used genotype coding method
|
||||
*/
|
||||
public void setGACoding(InterfaceGADoubleCoding coding) {
|
||||
this.m_DoubleCoding = coding;
|
||||
this.doubleCoding = coding;
|
||||
}
|
||||
|
||||
public InterfaceGADoubleCoding getGACoding() {
|
||||
return this.m_DoubleCoding;
|
||||
return this.doubleCoding;
|
||||
}
|
||||
|
||||
public String gADoubleCodingTipText() {
|
||||
@ -404,11 +396,11 @@ public class GAIndividualDoubleData extends AbstractEAIndividual implements Inte
|
||||
* @param precision The number of multiruns that are to be performed
|
||||
*/
|
||||
public void setPrecision(int precision) {
|
||||
this.m_Precision = precision;
|
||||
this.precision = precision;
|
||||
}
|
||||
|
||||
public int getPrecision() {
|
||||
return this.m_Precision;
|
||||
return this.precision;
|
||||
}
|
||||
|
||||
public String precisionTipText() {
|
||||
|
@ -8,28 +8,23 @@ import eva2.optimization.problems.InterfaceOptimizationProblem;
|
||||
import eva2.tools.math.RNG;
|
||||
|
||||
/**
|
||||
* This individual combines a real-valued phenotype with a tree-based phenotype.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 08.04.2003
|
||||
* Time: 10:04:44
|
||||
* To change this template use Options | File Templates.
|
||||
*
|
||||
*/
|
||||
public class GAPIndividualProgramData extends AbstractEAIndividual implements InterfaceDataTypeProgram, InterfaceDataTypeDouble, java.io.Serializable {
|
||||
|
||||
private InterfaceDataTypeDouble m_Numbers = new ESIndividualDoubleData();
|
||||
private InterfaceDataTypeProgram m_Program = new GPIndividualProgramData();
|
||||
private InterfaceDataTypeDouble numberData = new ESIndividualDoubleData();
|
||||
private InterfaceDataTypeProgram programData = new GPIndividualProgramData();
|
||||
|
||||
public GAPIndividualProgramData() {
|
||||
this.mutationProbability = 1.0;
|
||||
this.crossoverProbability = 1.0;
|
||||
this.m_Numbers = new GAIndividualDoubleData();
|
||||
this.m_Program = new GPIndividualProgramData();
|
||||
this.numberData = new GAIndividualDoubleData();
|
||||
this.programData = new GPIndividualProgramData();
|
||||
}
|
||||
|
||||
public GAPIndividualProgramData(GAPIndividualProgramData individual) {
|
||||
this.m_Numbers = (InterfaceDataTypeDouble) ((AbstractEAIndividual) individual.getNumbers()).clone();
|
||||
this.m_Program = (InterfaceDataTypeProgram) ((AbstractEAIndividual) individual.getProgramRepresentation()).clone();
|
||||
this.numberData = (InterfaceDataTypeDouble) ((AbstractEAIndividual) individual.getNumbers()).clone();
|
||||
this.programData = (InterfaceDataTypeProgram) ((AbstractEAIndividual) individual.getProgramRepresentation()).clone();
|
||||
|
||||
// cloning the members of AbstractEAIndividual
|
||||
this.age = individual.age;
|
||||
@ -63,10 +58,10 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof GAPIndividualProgramData) {
|
||||
GAPIndividualProgramData indy = (GAPIndividualProgramData) individual;
|
||||
if (!((AbstractEAIndividual) this.m_Numbers).equalGenotypes((AbstractEAIndividual) indy.m_Numbers)) {
|
||||
if (!((AbstractEAIndividual) this.numberData).equalGenotypes((AbstractEAIndividual) indy.numberData)) {
|
||||
return false;
|
||||
}
|
||||
if (!((AbstractEAIndividual) this.m_Program).equalGenotypes((AbstractEAIndividual) indy.m_Program)) {
|
||||
if (!((AbstractEAIndividual) this.programData).equalGenotypes((AbstractEAIndividual) indy.programData)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -82,14 +77,14 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void init(InterfaceOptimizationProblem opt) {
|
||||
((AbstractEAIndividual) this.m_Numbers).init(opt);
|
||||
((AbstractEAIndividual) this.m_Program).init(opt);
|
||||
((AbstractEAIndividual) this.numberData).init(opt);
|
||||
((AbstractEAIndividual) this.programData).init(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
((AbstractEAIndividual) this.m_Numbers).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.m_Program).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.numberData).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.programData).defaultInit(prob);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,15 +98,15 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
||||
if (obj instanceof Object[]) {
|
||||
if (((Object[]) obj)[0] instanceof double[]) {
|
||||
((AbstractEAIndividual) this.m_Numbers).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.m_Program).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.numberData).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.programData).initByValue(((Object[]) obj)[1], opt);
|
||||
} else {
|
||||
((AbstractEAIndividual) this.m_Numbers).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.m_Program).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.numberData).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.programData).initByValue(((Object[]) obj)[0], opt);
|
||||
}
|
||||
} else {
|
||||
((AbstractEAIndividual) this.m_Numbers).init(opt);
|
||||
((AbstractEAIndividual) this.m_Program).init(opt);
|
||||
((AbstractEAIndividual) this.numberData).init(opt);
|
||||
((AbstractEAIndividual) this.programData).init(opt);
|
||||
System.out.println("Initial value for GAPIndividualDoubleData is not suitable!");
|
||||
}
|
||||
}
|
||||
@ -122,17 +117,17 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
@Override
|
||||
public void mutate() {
|
||||
if (RNG.flipCoin(this.mutationProbability)) {
|
||||
((AbstractEAIndividual) this.m_Numbers).mutate();
|
||||
((AbstractEAIndividual) this.numberData).mutate();
|
||||
}
|
||||
if (RNG.flipCoin(this.mutationProbability)) {
|
||||
((AbstractEAIndividual) this.m_Program).mutate();
|
||||
((AbstractEAIndividual) this.programData).mutate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
((AbstractEAIndividual) this.m_Numbers).defaultMutate();
|
||||
((AbstractEAIndividual) this.m_Program).defaultMutate();
|
||||
((AbstractEAIndividual) this.numberData).defaultMutate();
|
||||
((AbstractEAIndividual) this.programData).defaultMutate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,8 +188,8 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
String result = "This is a hybrid Individual:\n";
|
||||
result += "The Numbers Part:\n" + ((AbstractEAIndividual) this.m_Numbers).getStringRepresentation();
|
||||
result += "\nThe Binarys Part:\n" + ((AbstractEAIndividual) this.m_Program).getStringRepresentation();
|
||||
result += "The Numbers Part:\n" + ((AbstractEAIndividual) this.numberData).getStringRepresentation();
|
||||
result += "\nThe Binarys Part:\n" + ((AbstractEAIndividual) this.programData).getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -208,7 +203,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void setDoubleDataLength(int length) {
|
||||
this.m_Numbers.setDoubleDataLength(length);
|
||||
this.numberData.setDoubleDataLength(length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,7 +213,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.m_Numbers.size();
|
||||
return this.numberData.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,7 +225,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void setDoubleRange(double[][] range) {
|
||||
this.m_Numbers.setDoubleRange(range);
|
||||
this.numberData.setDoubleRange(range);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,7 +235,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public double[][] getDoubleRange() {
|
||||
return this.m_Numbers.getDoubleRange();
|
||||
return this.numberData.getDoubleRange();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,7 +245,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public double[] getDoubleData() {
|
||||
return this.m_Numbers.getDoubleData();
|
||||
return this.numberData.getDoubleData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,7 +256,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public double[] getDoubleDataWithoutUpdate() {
|
||||
return this.m_Numbers.getDoubleDataWithoutUpdate();
|
||||
return this.numberData.getDoubleDataWithoutUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,7 +267,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void setDoublePhenotype(double[] doubleData) {
|
||||
this.m_Numbers.setDoublePhenotype(doubleData);
|
||||
this.numberData.setDoublePhenotype(doubleData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -283,7 +278,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void setDoubleGenotype(double[] doubleData) {
|
||||
this.m_Numbers.setDoubleGenotype(doubleData);
|
||||
this.numberData.setDoubleGenotype(doubleData);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
@ -296,7 +291,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void setProgramDataLength(int length) {
|
||||
this.m_Program.setProgramDataLength(length);
|
||||
this.programData.setProgramDataLength(length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,7 +301,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public InterfaceProgram[] getProgramData() {
|
||||
return this.m_Program.getProgramData();
|
||||
return this.programData.getProgramData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -317,7 +312,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public InterfaceProgram[] getProgramDataWithoutUpdate() {
|
||||
return this.m_Program.getProgramDataWithoutUpdate();
|
||||
return this.programData.getProgramDataWithoutUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,7 +322,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void SetProgramPhenotype(InterfaceProgram[] program) {
|
||||
this.m_Program.SetProgramPhenotype(program);
|
||||
this.programData.SetProgramPhenotype(program);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -337,7 +332,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void SetProgramGenotype(InterfaceProgram[] program) {
|
||||
this.m_Program.SetProgramGenotype(program);
|
||||
this.programData.SetProgramGenotype(program);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -347,7 +342,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public void SetFunctionArea(Object[] area) {
|
||||
this.m_Program.SetFunctionArea(area);
|
||||
this.programData.SetFunctionArea(area);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -357,7 +352,7 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
*/
|
||||
@Override
|
||||
public Object[] getFunctionArea() {
|
||||
return this.m_Program.getFunctionArea();
|
||||
return this.programData.getFunctionArea();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
@ -380,11 +375,11 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
* @param Numbers The new representation for the inner constants.
|
||||
*/
|
||||
public void setNumbers(InterfaceDataTypeDouble Numbers) {
|
||||
this.m_Numbers = Numbers;
|
||||
this.numberData = Numbers;
|
||||
}
|
||||
|
||||
public InterfaceDataTypeDouble getNumbers() {
|
||||
return this.m_Numbers;
|
||||
return this.numberData;
|
||||
}
|
||||
|
||||
public String numbersTipText() {
|
||||
@ -397,11 +392,11 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
||||
* @param program The new representation for the program.
|
||||
*/
|
||||
public void setProgramRepresentation(InterfaceDataTypeProgram program) {
|
||||
this.m_Program = program;
|
||||
this.programData = program;
|
||||
}
|
||||
|
||||
public InterfaceDataTypeProgram getProgramRepresentation() {
|
||||
return this.m_Program;
|
||||
return this.programData;
|
||||
}
|
||||
|
||||
public String programRepresentationTipText() {
|
||||
|
@ -21,25 +21,25 @@ import java.util.BitSet;
|
||||
@Description(value = "This is a GE individual suited to optimize programs.")
|
||||
public class GEIndividualProgramData extends AbstractEAIndividual implements InterfaceGAIndividual, InterfaceDataTypeProgram, java.io.Serializable {
|
||||
|
||||
protected GPArea[] m_Area;
|
||||
protected double m_InitFullGrowRatio = 0.5;
|
||||
protected int m_InitDepth = 5;
|
||||
protected int m_TargetDepth = 10;
|
||||
protected boolean m_CheckTargetDepth = true;
|
||||
protected GPArea[] gpAreas;
|
||||
protected double initFullGrowRatio = 0.5;
|
||||
protected int initDepth = 5;
|
||||
protected int targetDepth = 10;
|
||||
protected boolean checkTargetDepth = true;
|
||||
|
||||
protected BitSet m_Genotype;
|
||||
protected AbstractGPNode[] m_Phenotype;
|
||||
protected int m_GenotypeLengthPerProgram = 240; // this is the overall length
|
||||
protected int m_MaxNumberOfNodes = 80;
|
||||
protected int m_NumberOfBitPerInt = 6;
|
||||
protected int m_CurrentIndex = 0;
|
||||
protected int m_CurrentNumberOfNodes = 0;
|
||||
protected Object[][] m_Rules;
|
||||
protected BitSet genotype;
|
||||
protected AbstractGPNode[] phenotype;
|
||||
protected int genotypeLengthPerProgram = 240; // this is the overall length
|
||||
protected int maxNumberOfNodes = 80;
|
||||
protected int numberOfBitPerInt = 6;
|
||||
protected int currentIndex = 0;
|
||||
protected int currentNumberOfNodes = 0;
|
||||
protected Object[][] rules;
|
||||
|
||||
public GEIndividualProgramData() {
|
||||
this.m_Area = new GPArea[1];
|
||||
this.m_GenotypeLengthPerProgram = 240;
|
||||
this.m_Genotype = new BitSet();
|
||||
this.gpAreas = new GPArea[1];
|
||||
this.genotypeLengthPerProgram = 240;
|
||||
this.genotype = new BitSet();
|
||||
this.mutationOperator = new MutateDefault();
|
||||
this.crossoverOperator = new CrossoverGADefault();
|
||||
this.mutationProbability = 0.5;
|
||||
@ -47,46 +47,46 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
}
|
||||
|
||||
public GEIndividualProgramData(GEIndividualProgramData individual) {
|
||||
if (individual.m_Phenotype != null) {
|
||||
this.m_Phenotype = new AbstractGPNode[individual.m_Phenotype.length];
|
||||
for (int i = 0; i < individual.m_Phenotype.length; i++) {
|
||||
this.m_Phenotype[i] = (AbstractGPNode) individual.m_Phenotype[i].clone();
|
||||
if (individual.phenotype != null) {
|
||||
this.phenotype = new AbstractGPNode[individual.phenotype.length];
|
||||
for (int i = 0; i < individual.phenotype.length; i++) {
|
||||
this.phenotype[i] = (AbstractGPNode) individual.phenotype[i].clone();
|
||||
}
|
||||
}
|
||||
this.m_GenotypeLengthPerProgram = individual.m_GenotypeLengthPerProgram;
|
||||
this.m_MaxNumberOfNodes = individual.m_MaxNumberOfNodes;
|
||||
this.m_NumberOfBitPerInt = individual.m_NumberOfBitPerInt;
|
||||
this.m_CurrentIndex = individual.m_CurrentIndex;
|
||||
if (individual.m_Genotype != null) {
|
||||
this.m_Genotype = (BitSet) individual.m_Genotype.clone();
|
||||
this.genotypeLengthPerProgram = individual.genotypeLengthPerProgram;
|
||||
this.maxNumberOfNodes = individual.maxNumberOfNodes;
|
||||
this.numberOfBitPerInt = individual.numberOfBitPerInt;
|
||||
this.currentIndex = individual.currentIndex;
|
||||
if (individual.genotype != null) {
|
||||
this.genotype = (BitSet) individual.genotype.clone();
|
||||
}
|
||||
if (individual.m_Area != null) {
|
||||
this.m_Area = new GPArea[individual.m_Area.length];
|
||||
for (int i = 0; i < this.m_Area.length; i++) {
|
||||
this.m_Area[i] = (GPArea) individual.m_Area[i].clone();
|
||||
if (individual.gpAreas != null) {
|
||||
this.gpAreas = new GPArea[individual.gpAreas.length];
|
||||
for (int i = 0; i < this.gpAreas.length; i++) {
|
||||
this.gpAreas[i] = (GPArea) individual.gpAreas[i].clone();
|
||||
}
|
||||
}
|
||||
// User : "Copy the rules set!"
|
||||
// GEIndividualProgramData : "Naay! I wanna go playing with my friends... !"
|
||||
if (individual.m_Rules != null) {
|
||||
this.m_Rules = new Object[individual.m_Rules.length][];
|
||||
for (int t = 0; t < this.m_Rules.length; t++) {
|
||||
this.m_Rules[t] = new Object[individual.m_Rules[t].length];
|
||||
int[][] copyRulz, orgRulz = (int[][]) individual.m_Rules[t][0];
|
||||
if (individual.rules != null) {
|
||||
this.rules = new Object[individual.rules.length][];
|
||||
for (int t = 0; t < this.rules.length; t++) {
|
||||
this.rules[t] = new Object[individual.rules[t].length];
|
||||
int[][] copyRulz, orgRulz = (int[][]) individual.rules[t][0];
|
||||
copyRulz = new int[orgRulz.length][];
|
||||
for (int i = 0; i < copyRulz.length; i++) {
|
||||
copyRulz[i] = new int[orgRulz[i].length];
|
||||
System.arraycopy(orgRulz[i], 0, copyRulz[i], 0, orgRulz[i].length);
|
||||
}
|
||||
this.m_Rules[t][0] = copyRulz;
|
||||
this.rules[t][0] = copyRulz;
|
||||
AbstractGPNode[] copyNode, orgNode;
|
||||
for (int i = 1; i < this.m_Rules[t].length; i++) {
|
||||
orgNode = (AbstractGPNode[]) individual.m_Rules[t][i];
|
||||
for (int i = 1; i < this.rules[t].length; i++) {
|
||||
orgNode = (AbstractGPNode[]) individual.rules[t][i];
|
||||
copyNode = new AbstractGPNode[orgNode.length];
|
||||
for (int j = 0; j < orgNode.length; j++) {
|
||||
copyNode[j] = (AbstractGPNode) orgNode[j].clone();
|
||||
}
|
||||
this.m_Rules[t][i] = copyNode;
|
||||
this.rules[t][i] = copyNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,19 +122,19 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof GEIndividualProgramData) {
|
||||
GEIndividualProgramData indy = (GEIndividualProgramData) individual;
|
||||
if (this.m_GenotypeLengthPerProgram != indy.m_GenotypeLengthPerProgram) {
|
||||
if (this.genotypeLengthPerProgram != indy.genotypeLengthPerProgram) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_MaxNumberOfNodes != indy.m_MaxNumberOfNodes) {
|
||||
if (this.maxNumberOfNodes != indy.maxNumberOfNodes) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_NumberOfBitPerInt != indy.m_NumberOfBitPerInt) {
|
||||
if (this.numberOfBitPerInt != indy.numberOfBitPerInt) {
|
||||
return false;
|
||||
}
|
||||
if ((this.m_Genotype == null) || (indy.m_Genotype == null)) {
|
||||
if ((this.genotype == null) || (indy.genotype == null)) {
|
||||
return false;
|
||||
}
|
||||
if (!this.m_Genotype.equals(indy.m_Genotype)) {
|
||||
if (!this.genotype.equals(indy.genotype)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -147,18 +147,18 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
* This method compiles the area
|
||||
*/
|
||||
private void compileArea() {
|
||||
if (this.m_Area == null) {
|
||||
this.m_Rules = null;
|
||||
if (this.gpAreas == null) {
|
||||
this.rules = null;
|
||||
return;
|
||||
}
|
||||
//this.m_Rules = new Object[this.gpArea.length][];
|
||||
for (int t = 0; t < this.m_Area.length; t++) {
|
||||
//this.rules = new Object[this.gpArea.length][];
|
||||
for (int t = 0; t < this.gpAreas.length; t++) {
|
||||
// first lets find out what kind of elements are available
|
||||
int arity, maxArity = 0;
|
||||
|
||||
// first find out the max arity in the GPArea
|
||||
this.m_Area[t].compileReducedList();
|
||||
ArrayList area = this.m_Area[t].getReducedList();
|
||||
this.gpAreas[t].compileReducedList();
|
||||
ArrayList area = this.gpAreas[t].getReducedList();
|
||||
for (int i = 0; i < area.size(); i++) {
|
||||
arity = ((AbstractGPNode) area.get(i)).getArity();
|
||||
if (arity > maxArity) {
|
||||
@ -175,7 +175,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
directList[((AbstractGPNode) area.get(i)).getArity()].add(area.get(i));
|
||||
}
|
||||
// Now write the rules
|
||||
this.m_Rules[t] = new Object[maxArity + 2];
|
||||
this.rules[t] = new Object[maxArity + 2];
|
||||
// the first rule describes how to decode an <expr>
|
||||
int numberOfRules = 0, index = 0;
|
||||
int[] tmpRule;
|
||||
@ -210,7 +210,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
index++;
|
||||
}
|
||||
}
|
||||
this.m_Rules[t][0] = trueExpr;
|
||||
this.rules[t][0] = trueExpr;
|
||||
|
||||
// now the rules that define <var>, <op1>, <op2>, ....
|
||||
AbstractGPNode[] tmpListOfGPNodes;
|
||||
@ -219,7 +219,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
for (int j = 0; j < directList[i].size(); j++) {
|
||||
tmpListOfGPNodes[j] = (AbstractGPNode) directList[i].get(j);
|
||||
}
|
||||
this.m_Rules[t][i + 1] = tmpListOfGPNodes;
|
||||
this.rules[t][i + 1] = tmpListOfGPNodes;
|
||||
}
|
||||
// this should be the complete rules set
|
||||
//this.printRuleSet();
|
||||
@ -232,17 +232,17 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
private void printRuleSet() {
|
||||
String result = "";
|
||||
AbstractGPNode[] tmpNodes;
|
||||
for (int t = 0; t < this.m_Area.length; t++) {
|
||||
for (int t = 0; t < this.gpAreas.length; t++) {
|
||||
// first the Non-Terminals
|
||||
result += "N \t := \t{";
|
||||
for (int i = 0; i < this.m_Rules[t].length; i++) {
|
||||
for (int i = 0; i < this.rules[t].length; i++) {
|
||||
if (i == 0) {
|
||||
result += "expr, ";
|
||||
} else {
|
||||
if (i == 1) {
|
||||
result += "var, ";
|
||||
} else {
|
||||
if (((AbstractGPNode[]) this.m_Rules[t][i]).length > 0) {
|
||||
if (((AbstractGPNode[]) this.rules[t][i]).length > 0) {
|
||||
result += "op" + (i - 1) + ", ";
|
||||
}
|
||||
}
|
||||
@ -251,8 +251,8 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
result += "}\n";
|
||||
// then the Ternimnals
|
||||
result += "T \t := \t{";
|
||||
this.m_Area[t].compileReducedList();
|
||||
ArrayList area = this.m_Area[t].getReducedList();
|
||||
this.gpAreas[t].compileReducedList();
|
||||
ArrayList area = this.gpAreas[t].getReducedList();
|
||||
for (int i = 0; i < area.size(); i++) {
|
||||
result += ((AbstractGPNode) area.get(i)).getStringRepresentation() + ", ";
|
||||
}
|
||||
@ -261,12 +261,12 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
result += "S \t := \t<expr>\n\n";
|
||||
|
||||
// now the rules
|
||||
for (int i = 0; i < this.m_Rules[t].length; i++) {
|
||||
for (int i = 0; i < this.rules[t].length; i++) {
|
||||
if (i == 0) {
|
||||
// the first rules
|
||||
result += "0. \t := \t<expr> \t::\t";
|
||||
System.out.println("i: " + i);
|
||||
int[][] rulz = (int[][]) this.m_Rules[t][i];
|
||||
int[][] rulz = (int[][]) this.rules[t][i];
|
||||
for (int j = 0; j < rulz.length; j++) {
|
||||
result += this.getRuleString(rulz[j]) + "\n";
|
||||
if ((j + 1) < rulz.length) {
|
||||
@ -277,14 +277,14 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
// now the rules for the terminals
|
||||
if (i == 1) {
|
||||
// These are the GP-Terminals
|
||||
tmpNodes = (AbstractGPNode[]) this.m_Rules[t][i];
|
||||
tmpNodes = (AbstractGPNode[]) this.rules[t][i];
|
||||
result += "1. \t := \t<var> \t::\t" + tmpNodes[0].getStringRepresentation() + "\n";
|
||||
for (int j = 1; j < tmpNodes.length; j++) {
|
||||
result += "\t \t \t \t \t \t" + tmpNodes[j].getStringRepresentation() + "\n";
|
||||
}
|
||||
} else {
|
||||
// These are the GP-Functions
|
||||
tmpNodes = (AbstractGPNode[]) this.m_Rules[t][i];
|
||||
tmpNodes = (AbstractGPNode[]) this.rules[t][i];
|
||||
if (tmpNodes.length > 0) {
|
||||
result += i + ". \t := \t<op" + (i - 1) + "> \t::\t" + tmpNodes[0].getStringRepresentation() + "\n";
|
||||
for (int j = 1; j < tmpNodes.length; j++) {
|
||||
@ -310,11 +310,11 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
private String getBitSetString() {
|
||||
String result = "";
|
||||
result += "{";
|
||||
for (int i = 0; i < this.m_GenotypeLengthPerProgram * this.m_Area.length; i++) {
|
||||
if (i % this.m_NumberOfBitPerInt == 0) {
|
||||
for (int i = 0; i < this.genotypeLengthPerProgram * this.gpAreas.length; i++) {
|
||||
if (i % this.numberOfBitPerInt == 0) {
|
||||
result += " ";
|
||||
}
|
||||
if (this.m_Genotype.get(i)) {
|
||||
if (this.genotype.get(i)) {
|
||||
result += "1";
|
||||
} else {
|
||||
result += "0";
|
||||
@ -356,59 +356,59 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public void setProgramDataLength(int length) {
|
||||
GPArea[] oldArea = this.m_Area;
|
||||
Object[][] oldRulz = this.m_Rules;
|
||||
GPArea[] oldArea = this.gpAreas;
|
||||
Object[][] oldRulz = this.rules;
|
||||
|
||||
this.m_Area = new GPArea[length];
|
||||
for (int t = 0; ((t < this.m_Area.length) && (t < oldArea.length)); t++) {
|
||||
this.m_Area[t] = oldArea[t];
|
||||
this.gpAreas = new GPArea[length];
|
||||
for (int t = 0; ((t < this.gpAreas.length) && (t < oldArea.length)); t++) {
|
||||
this.gpAreas[t] = oldArea[t];
|
||||
}
|
||||
for (int t = oldArea.length; t < this.m_Area.length; t++) {
|
||||
this.m_Area[t] = oldArea[oldArea.length - 1];
|
||||
for (int t = oldArea.length; t < this.gpAreas.length; t++) {
|
||||
this.gpAreas[t] = oldArea[oldArea.length - 1];
|
||||
}
|
||||
this.m_Rules = new Object[length][];
|
||||
this.rules = new Object[length][];
|
||||
if (oldRulz == null) {
|
||||
return;
|
||||
}
|
||||
for (int t = 0; ((t < this.m_Area.length) && (t < oldArea.length)); t++) {
|
||||
for (int t = 0; ((t < this.gpAreas.length) && (t < oldArea.length)); t++) {
|
||||
if (oldRulz[t] != null) {
|
||||
this.m_Rules[t] = new Object[oldRulz[t].length];
|
||||
this.rules[t] = new Object[oldRulz[t].length];
|
||||
int[][] copyRulz, orgRulz = (int[][]) oldRulz[t][0];
|
||||
copyRulz = new int[orgRulz.length][];
|
||||
for (int i = 0; i < copyRulz.length; i++) {
|
||||
copyRulz[i] = new int[orgRulz[i].length];
|
||||
System.arraycopy(orgRulz[i], 0, copyRulz[i], 0, orgRulz[i].length);
|
||||
}
|
||||
this.m_Rules[t][0] = copyRulz;
|
||||
this.rules[t][0] = copyRulz;
|
||||
AbstractGPNode[] copyNode, orgNode;
|
||||
for (int i = 1; i < this.m_Rules[t].length; i++) {
|
||||
for (int i = 1; i < this.rules[t].length; i++) {
|
||||
orgNode = (AbstractGPNode[]) oldRulz[t][i];
|
||||
copyNode = new AbstractGPNode[orgNode.length];
|
||||
for (int j = 0; j < orgNode.length; j++) {
|
||||
copyNode[j] = (AbstractGPNode) orgNode[j].clone();
|
||||
}
|
||||
this.m_Rules[t][i] = copyNode;
|
||||
this.rules[t][i] = copyNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int t = oldArea.length; t < this.m_Area.length; t++) {
|
||||
for (int t = oldArea.length; t < this.gpAreas.length; t++) {
|
||||
if (oldRulz[oldArea.length - 1] != null) {
|
||||
this.m_Rules[t] = new Object[oldRulz[oldArea.length - 1].length];
|
||||
this.rules[t] = new Object[oldRulz[oldArea.length - 1].length];
|
||||
int[][] copyRulz, orgRulz = (int[][]) oldRulz[oldArea.length - 1][0];
|
||||
copyRulz = new int[orgRulz.length][];
|
||||
for (int i = 0; i < copyRulz.length; i++) {
|
||||
copyRulz[i] = new int[orgRulz[i].length];
|
||||
System.arraycopy(orgRulz[i], 0, copyRulz[i], 0, orgRulz[i].length);
|
||||
}
|
||||
this.m_Rules[t][0] = copyRulz;
|
||||
this.rules[t][0] = copyRulz;
|
||||
AbstractGPNode[] copyNode, orgNode;
|
||||
for (int i = 1; i < this.m_Rules[t].length; i++) {
|
||||
for (int i = 1; i < this.rules[t].length; i++) {
|
||||
orgNode = (AbstractGPNode[]) oldRulz[oldArea.length - 1][i];
|
||||
copyNode = new AbstractGPNode[orgNode.length];
|
||||
for (int j = 0; j < orgNode.length; j++) {
|
||||
copyNode[j] = (AbstractGPNode) orgNode[j].clone();
|
||||
}
|
||||
this.m_Rules[t][i] = copyNode;
|
||||
this.rules[t][i] = copyNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -426,13 +426,13 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
private int decodeNextInt(int t) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < this.m_NumberOfBitPerInt; i++) {
|
||||
if (this.m_Genotype.get(this.m_CurrentIndex + (t * this.m_GenotypeLengthPerProgram))) {
|
||||
for (int i = 0; i < this.numberOfBitPerInt; i++) {
|
||||
if (this.genotype.get(this.currentIndex + (t * this.genotypeLengthPerProgram))) {
|
||||
result += Math.pow(2, i);
|
||||
}
|
||||
this.m_CurrentIndex++;
|
||||
if (this.m_CurrentIndex >= (t + 1) * this.m_GenotypeLengthPerProgram) {
|
||||
this.m_CurrentIndex = t * this.m_GenotypeLengthPerProgram;
|
||||
this.currentIndex++;
|
||||
if (this.currentIndex >= (t + 1) * this.genotypeLengthPerProgram) {
|
||||
this.currentIndex = t * this.genotypeLengthPerProgram;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -452,12 +452,12 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
// System.out.println("Decoding mode: " + mode);
|
||||
|
||||
if (mode == 0) {
|
||||
int[][] rulz = (int[][]) this.m_Rules[t][0];
|
||||
int[][] rulz = (int[][]) this.rules[t][0];
|
||||
int[] myRule = rulz[value % rulz.length];
|
||||
// System.out.print("Value % rulz : "+ value +" % " + rulz.length + " = " +(value%rulz.length));
|
||||
// System.out.println(" => my rule " + this.getRuleString(myRule));
|
||||
this.m_CurrentNumberOfNodes += myRule.length;
|
||||
if ((this.m_CurrentNumberOfNodes + myRule.length) > this.m_MaxNumberOfNodes) {
|
||||
this.currentNumberOfNodes += myRule.length;
|
||||
if ((this.currentNumberOfNodes + myRule.length) > this.maxNumberOfNodes) {
|
||||
// no i have to limit the number of nodes
|
||||
myRule = rulz[0];
|
||||
// System.out.println("Limiting to "+ this.getRuleString(myRule));
|
||||
@ -468,7 +468,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
result.setNode(this.decodeGPNode(t, myRule[i + 1]), i);
|
||||
}
|
||||
} else {
|
||||
AbstractGPNode[] availableNodes = (AbstractGPNode[]) this.m_Rules[t][mode];
|
||||
AbstractGPNode[] availableNodes = (AbstractGPNode[]) this.rules[t][mode];
|
||||
// System.out.print("Choosing a terminal : "+ value +" % " + availableNodes.length + " = " +(value%availableNodes.length));
|
||||
// System.out.println(" => " +availableNodes[value % availableNodes.length].getStringRepresentation());
|
||||
result = (AbstractGPNode) availableNodes[value % availableNodes.length].clone();
|
||||
@ -486,34 +486,34 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
// if (true) {
|
||||
// String test ="GE decoding:\n";
|
||||
// test += this.getBitSetString() +"\n{";
|
||||
// this.m_CurrentIndex = 0;
|
||||
// for (int i = 0; i < this.m_MaxNumberOfNodes; i++) {
|
||||
// this.currentIndex = 0;
|
||||
// for (int i = 0; i < this.maxNumberOfNodes; i++) {
|
||||
// test += this.decodeNextInt();
|
||||
// if ((i + 1) < this.m_MaxNumberOfNodes) test += "; ";
|
||||
// if ((i + 1) < this.maxNumberOfNodes) test += "; ";
|
||||
// }
|
||||
// test += "}\n";
|
||||
// System.out.println(""+test);
|
||||
// }
|
||||
// lets decode the stuff!
|
||||
if (this.m_Rules == null) {
|
||||
if (this.rules == null) {
|
||||
this.compileArea();
|
||||
if (this.m_Rules == null) {
|
||||
if (this.rules == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
this.m_CurrentIndex = 0;
|
||||
this.m_CurrentNumberOfNodes = 0;
|
||||
this.currentIndex = 0;
|
||||
this.currentNumberOfNodes = 0;
|
||||
int mode = 0;
|
||||
this.m_Phenotype = new AbstractGPNode[this.m_Area.length];
|
||||
for (int t = 0; t < this.m_Area.length; t++) {
|
||||
this.phenotype = new AbstractGPNode[this.gpAreas.length];
|
||||
for (int t = 0; t < this.gpAreas.length; t++) {
|
||||
mode = 0;
|
||||
this.m_CurrentIndex = t * this.m_GenotypeLengthPerProgram;
|
||||
this.m_CurrentNumberOfNodes = 0;
|
||||
this.m_Phenotype[t] = this.decodeGPNode(t, mode);
|
||||
this.currentIndex = t * this.genotypeLengthPerProgram;
|
||||
this.currentNumberOfNodes = 0;
|
||||
this.phenotype[t] = this.decodeGPNode(t, mode);
|
||||
}
|
||||
// System.out.println("Decoded: ");
|
||||
// System.out.println(""+ result.getStringRepresentation());
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -524,7 +524,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public InterfaceProgram[] getProgramDataWithoutUpdate() {
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -535,9 +535,9 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
@Override
|
||||
public void SetProgramPhenotype(InterfaceProgram[] program) {
|
||||
if (program instanceof AbstractGPNode[]) {
|
||||
this.m_Phenotype = new AbstractGPNode[program.length];
|
||||
this.phenotype = new AbstractGPNode[program.length];
|
||||
for (int t = 0; t < program.length; t++) {
|
||||
this.m_Phenotype[t] = (AbstractGPNode) ((AbstractGPNode) program[t]).clone();
|
||||
this.phenotype[t] = (AbstractGPNode) ((AbstractGPNode) program[t]).clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -563,9 +563,9 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
@Override
|
||||
public void SetFunctionArea(Object[] area) {
|
||||
if (area instanceof GPArea[]) {
|
||||
this.m_Area = new GPArea[area.length];
|
||||
for (int t = 0; t < this.m_Area.length; t++) {
|
||||
this.m_Area[t] = (GPArea) area[t];
|
||||
this.gpAreas = new GPArea[area.length];
|
||||
for (int t = 0; t < this.gpAreas.length; t++) {
|
||||
this.gpAreas[t] = (GPArea) area[t];
|
||||
}
|
||||
this.compileArea();
|
||||
}
|
||||
@ -578,7 +578,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public Object[] getFunctionArea() {
|
||||
return this.m_Area;
|
||||
return this.gpAreas;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
@ -614,8 +614,8 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
String result = "";
|
||||
result += "GEIndividual coding program:\n";
|
||||
result += "{";
|
||||
for (int i = 0; i < this.m_GenotypeLengthPerProgram * this.m_Area.length; i++) {
|
||||
if (this.m_Genotype.get(i)) {
|
||||
for (int i = 0; i < this.genotypeLengthPerProgram * this.gpAreas.length; i++) {
|
||||
if (this.genotype.get(i)) {
|
||||
result += "1";
|
||||
} else {
|
||||
result += "0";
|
||||
@ -640,7 +640,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public BitSet getBGenotype() {
|
||||
return this.m_Genotype;
|
||||
return this.genotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -651,7 +651,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public void setBGenotype(BitSet binaryData) {
|
||||
this.m_Genotype = binaryData;
|
||||
this.genotype = binaryData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -663,16 +663,16 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public int getGenotypeLength() {
|
||||
return this.m_GenotypeLengthPerProgram * this.m_Area.length;
|
||||
return this.genotypeLengthPerProgram * this.gpAreas.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
for (int i = 0; i < this.m_GenotypeLengthPerProgram * this.m_Area.length; i++) {
|
||||
for (int i = 0; i < this.genotypeLengthPerProgram * this.gpAreas.length; i++) {
|
||||
if (RNG.flipCoin(0.5)) {
|
||||
this.m_Genotype.set(i);
|
||||
this.genotype.set(i);
|
||||
} else {
|
||||
this.m_Genotype.clear(i);
|
||||
this.genotype.clear(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -682,12 +682,12 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
int mutationIndex = RNG.randomInt(0, this.m_GenotypeLengthPerProgram * this.m_Area.length);
|
||||
int mutationIndex = RNG.randomInt(0, this.genotypeLengthPerProgram * this.gpAreas.length);
|
||||
//if (mutationIndex > 28) System.out.println("Mutate: " + this.getSolutionRepresentationFor());
|
||||
if (this.m_Genotype.get(mutationIndex)) {
|
||||
this.m_Genotype.clear(mutationIndex);
|
||||
if (this.genotype.get(mutationIndex)) {
|
||||
this.genotype.clear(mutationIndex);
|
||||
} else {
|
||||
this.m_Genotype.set(mutationIndex);
|
||||
this.genotype.set(mutationIndex);
|
||||
}
|
||||
//if (mutationIndex > 28) System.out.println(this.getSolutionRepresentationFor());
|
||||
}
|
||||
@ -709,11 +709,11 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
* @param size The length
|
||||
*/
|
||||
public void setGenotypeLengthPerProgram(int size) {
|
||||
this.m_GenotypeLengthPerProgram = size;
|
||||
this.genotypeLengthPerProgram = size;
|
||||
}
|
||||
|
||||
public int getGenotypeLengthPerProgram() {
|
||||
return this.m_GenotypeLengthPerProgram;
|
||||
return this.genotypeLengthPerProgram;
|
||||
}
|
||||
|
||||
public String genotypeLengthPerProgramTipText() {
|
||||
@ -727,11 +727,11 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
* @param nodes The maximum number of nodes
|
||||
*/
|
||||
public void setMaxNumberOfNodes(int nodes) {
|
||||
this.m_MaxNumberOfNodes = nodes;
|
||||
this.maxNumberOfNodes = nodes;
|
||||
}
|
||||
|
||||
public int getMaxNumberOfNodes() {
|
||||
return this.m_MaxNumberOfNodes;
|
||||
return this.maxNumberOfNodes;
|
||||
}
|
||||
|
||||
public String maxNumberOfNodesTipText() {
|
||||
@ -745,11 +745,11 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
* @param length The number of bits per int.
|
||||
*/
|
||||
public void setNumberOfBitPerInt(int length) {
|
||||
this.m_NumberOfBitPerInt = length;
|
||||
this.numberOfBitPerInt = length;
|
||||
}
|
||||
|
||||
public int getNumberOfBitPerInt() {
|
||||
return this.m_NumberOfBitPerInt;
|
||||
return this.numberOfBitPerInt;
|
||||
}
|
||||
|
||||
public String numberOfBitPerIntTipText() {
|
||||
|
@ -14,21 +14,21 @@ import eva2.util.annotation.Description;
|
||||
@Description(value = "This is a GI individual suited to optimize int values.")
|
||||
public class GIIndividualIntegerData extends AbstractEAIndividual implements InterfaceGIIndividual, InterfaceDataTypeInteger, java.io.Serializable {
|
||||
|
||||
private int[] m_Phenotype;
|
||||
private int[][] m_Range;
|
||||
protected int[] m_Genotype;
|
||||
private int[] phenotype;
|
||||
private int[][] initializationRange;
|
||||
protected int[] genotype;
|
||||
|
||||
public GIIndividualIntegerData() {
|
||||
this.mutationProbability = 0.2;
|
||||
this.mutationOperator = new MutateDefault();
|
||||
this.crossoverProbability = 0.7;
|
||||
this.crossoverOperator = new CrossoverGIDefault();
|
||||
this.m_Range = new int[10][2];
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
this.m_Range[i][0] = 0;
|
||||
this.m_Range[i][1] = 7;
|
||||
this.initializationRange = new int[10][2];
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
this.initializationRange[i][0] = 0;
|
||||
this.initializationRange[i][1] = 7;
|
||||
}
|
||||
this.m_Genotype = new int[10];
|
||||
this.genotype = new int[10];
|
||||
}
|
||||
|
||||
public GIIndividualIntegerData(int[][] theRange) {
|
||||
@ -37,19 +37,19 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
}
|
||||
|
||||
public GIIndividualIntegerData(GIIndividualIntegerData individual) {
|
||||
if (individual.m_Phenotype != null) {
|
||||
this.m_Phenotype = new int[individual.m_Phenotype.length];
|
||||
System.arraycopy(individual.m_Phenotype, 0, this.m_Phenotype, 0, this.m_Phenotype.length);
|
||||
if (individual.phenotype != null) {
|
||||
this.phenotype = new int[individual.phenotype.length];
|
||||
System.arraycopy(individual.phenotype, 0, this.phenotype, 0, this.phenotype.length);
|
||||
}
|
||||
if (individual.m_Genotype != null) {
|
||||
this.m_Genotype = new int[individual.m_Genotype.length];
|
||||
System.arraycopy(individual.m_Genotype, 0, this.m_Genotype, 0, this.m_Genotype.length);
|
||||
if (individual.genotype != null) {
|
||||
this.genotype = new int[individual.genotype.length];
|
||||
System.arraycopy(individual.genotype, 0, this.genotype, 0, this.genotype.length);
|
||||
|
||||
}
|
||||
this.m_Range = new int[individual.m_Range.length][2];
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
this.m_Range[i][0] = individual.m_Range[i][0];
|
||||
this.m_Range[i][1] = individual.m_Range[i][1];
|
||||
this.initializationRange = new int[individual.initializationRange.length][2];
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
this.initializationRange[i][0] = individual.initializationRange[i][0];
|
||||
this.initializationRange[i][1] = individual.initializationRange[i][1];
|
||||
}
|
||||
|
||||
// cloning the members of AbstractEAIndividual
|
||||
@ -85,20 +85,20 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof GIIndividualIntegerData) {
|
||||
GIIndividualIntegerData indy = (GIIndividualIntegerData) individual;
|
||||
if ((this.m_Genotype == null) || (indy.m_Genotype == null)) {
|
||||
if ((this.genotype == null) || (indy.genotype == null)) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Genotype.length != indy.m_Genotype.length) {
|
||||
if (this.genotype.length != indy.genotype.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
if (this.m_Genotype[i] != indy.m_Genotype[i]) {
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
if (this.genotype[i] != indy.genotype[i]) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range[i][0] != indy.m_Range[i][0]) {
|
||||
if (this.initializationRange[i][0] != indy.initializationRange[i][0]) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Range[i][1] != indy.m_Range[i][1]) {
|
||||
if (this.initializationRange[i][1] != indy.initializationRange[i][1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -122,20 +122,20 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
int[][] newRange = new int[length][2];
|
||||
|
||||
// copy the old values for the decision parameters and the range
|
||||
for (int i = 0; ((i < newDesPa.length) && (i < this.m_Genotype.length)); i++) {
|
||||
newDesPa[i] = this.m_Genotype[i];
|
||||
newRange[i][0] = this.m_Range[i][0];
|
||||
newRange[i][1] = this.m_Range[i][1];
|
||||
for (int i = 0; ((i < newDesPa.length) && (i < this.genotype.length)); i++) {
|
||||
newDesPa[i] = this.genotype[i];
|
||||
newRange[i][0] = this.initializationRange[i][0];
|
||||
newRange[i][1] = this.initializationRange[i][1];
|
||||
}
|
||||
|
||||
// if the new length is bigger than the last value fills the extra elements
|
||||
for (int i = this.m_Genotype.length; (i < newDesPa.length); i++) {
|
||||
newDesPa[i] = this.m_Genotype[this.m_Genotype.length - 1];
|
||||
newRange[i][0] = this.m_Range[this.m_Genotype.length - 1][0];
|
||||
newRange[i][1] = this.m_Range[this.m_Genotype.length - 1][1];
|
||||
for (int i = this.genotype.length; (i < newDesPa.length); i++) {
|
||||
newDesPa[i] = this.genotype[this.genotype.length - 1];
|
||||
newRange[i][0] = this.initializationRange[this.genotype.length - 1][0];
|
||||
newRange[i][1] = this.initializationRange[this.genotype.length - 1][1];
|
||||
}
|
||||
this.m_Genotype = newDesPa;
|
||||
this.m_Range = newRange;
|
||||
this.genotype = newDesPa;
|
||||
this.initializationRange = newRange;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,7 +145,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.m_Range.length;
|
||||
return this.initializationRange.length;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,12 +157,12 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public void setIntRange(int[][] range) {
|
||||
if (range.length != this.m_Range.length) {
|
||||
if (range.length != this.initializationRange.length) {
|
||||
this.setIntegerDataLength(range.length);
|
||||
}
|
||||
for (int i = 0; ((i < this.m_Range.length) && (i < range.length)); i++) {
|
||||
this.m_Range[i][0] = range[i][0];
|
||||
this.m_Range[i][1] = range[i][1];
|
||||
for (int i = 0; ((i < this.initializationRange.length) && (i < range.length)); i++) {
|
||||
this.initializationRange[i][0] = range[i][0];
|
||||
this.initializationRange[i][1] = range[i][1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public int[][] getIntRange() {
|
||||
return this.m_Range;
|
||||
return this.initializationRange;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,11 +183,11 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public int[] getIntegerData() {
|
||||
this.m_Phenotype = new int[this.m_Range.length];
|
||||
for (int i = 0; i < this.m_Phenotype.length; i++) {
|
||||
this.m_Phenotype[i] = this.m_Genotype[i];
|
||||
this.phenotype = new int[this.initializationRange.length];
|
||||
for (int i = 0; i < this.phenotype.length; i++) {
|
||||
this.phenotype[i] = this.genotype[i];
|
||||
}
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +198,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public int[] getIntegerDataWithoutUpdate() {
|
||||
return this.m_Phenotype;
|
||||
return this.phenotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -208,7 +208,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public void setIntPhenotype(int[] doubleData) {
|
||||
this.m_Phenotype = doubleData;
|
||||
this.phenotype = doubleData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -220,9 +220,9 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
@Override
|
||||
public void setIntGenotype(int[] doubleData) {
|
||||
this.setIntPhenotype(doubleData);
|
||||
this.m_Genotype = new int[this.m_Range.length];
|
||||
this.genotype = new int[this.initializationRange.length];
|
||||
for (int i = 0; i < doubleData.length; i++) {
|
||||
this.m_Genotype[i] = doubleData[i];
|
||||
this.genotype[i] = doubleData[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
||||
if (obj instanceof int[]) {
|
||||
int[] bs = (int[]) obj;
|
||||
if (bs.length != this.m_Range.length) {
|
||||
if (bs.length != this.initializationRange.length) {
|
||||
System.out.println("Init value and requested length doesn't match!");
|
||||
}
|
||||
this.setIntGenotype(bs);
|
||||
@ -278,8 +278,8 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
}
|
||||
result += "]\n";
|
||||
result += "CodingRange: [";
|
||||
for (int i = 0; i < this.m_Range.length; i++) {
|
||||
result += "(" + this.m_Range[i][0] + "; " + this.m_Range[i][1] + "); ";
|
||||
for (int i = 0; i < this.initializationRange.length; i++) {
|
||||
result += "(" + this.initializationRange[i][0] + "; " + this.initializationRange[i][1] + "); ";
|
||||
}
|
||||
result += "]\n";
|
||||
return result;
|
||||
@ -296,7 +296,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public int[] getIGenotype() {
|
||||
return this.m_Genotype;
|
||||
return this.genotype;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,7 +309,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public void setIGenotype(int[] b) {
|
||||
this.m_Genotype = b;
|
||||
this.genotype = b;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,7 +321,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public int getGenotypeLength() {
|
||||
return this.m_Genotype.length;
|
||||
return this.genotype.length;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,13 +329,13 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
*/
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
int mutationIndex = RNG.randomInt(0, this.m_Genotype.length - 1);
|
||||
this.m_Genotype[mutationIndex] = RNG.randomInt(this.m_Range[mutationIndex][0], this.m_Range[mutationIndex][1]);
|
||||
int mutationIndex = RNG.randomInt(0, this.genotype.length - 1);
|
||||
this.genotype[mutationIndex] = RNG.randomInt(this.initializationRange[mutationIndex][0], this.initializationRange[mutationIndex][1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
int[][] range = m_Range;
|
||||
int[][] range = initializationRange;
|
||||
if ((prob != null) && (prob instanceof InterfaceHasInitRange) && (((InterfaceHasInitRange) prob).getInitRange() != null)) {
|
||||
Object rng = ((InterfaceHasInitRange) prob).getInitRange();
|
||||
if (rng instanceof double[][]) {
|
||||
@ -353,8 +353,8 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
this.m_Genotype[i] = RNG.randomInt(range[i][0], range[i][1]);
|
||||
for (int i = 0; i < this.genotype.length; i++) {
|
||||
this.genotype[i] = RNG.randomInt(range[i][0], range[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,19 +12,19 @@ import eva2.util.annotation.Description;
|
||||
@Description(value = "This is a mixed data type combining an integer vector with a permutation vector.")
|
||||
public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual implements InterfaceDataTypeInteger, InterfaceDataTypePermutation, java.io.Serializable {
|
||||
|
||||
private InterfaceDataTypeInteger m_Integer = new GIIndividualIntegerData();
|
||||
private InterfaceDataTypePermutation m_Permutation = new OBGAIndividualPermutationData();
|
||||
private InterfaceDataTypeInteger integerData = new GIIndividualIntegerData();
|
||||
private InterfaceDataTypePermutation permutationData = new OBGAIndividualPermutationData();
|
||||
|
||||
public GIOBGAIndividualIntegerPermutationData() {
|
||||
this.mutationProbability = 1.0;
|
||||
this.crossoverProbability = 1.0;
|
||||
this.m_Integer = new GIIndividualIntegerData();
|
||||
this.m_Permutation = new OBGAIndividualPermutationData();
|
||||
this.integerData = new GIIndividualIntegerData();
|
||||
this.permutationData = new OBGAIndividualPermutationData();
|
||||
}
|
||||
|
||||
public GIOBGAIndividualIntegerPermutationData(GIOBGAIndividualIntegerPermutationData individual) {
|
||||
this.m_Integer = (InterfaceDataTypeInteger) ((AbstractEAIndividual) individual.getIntegers()).clone();
|
||||
this.m_Permutation = (InterfaceDataTypePermutation) ((AbstractEAIndividual) individual.getPermutations()).clone();
|
||||
this.integerData = (InterfaceDataTypeInteger) ((AbstractEAIndividual) individual.getIntegers()).clone();
|
||||
this.permutationData = (InterfaceDataTypePermutation) ((AbstractEAIndividual) individual.getPermutations()).clone();
|
||||
|
||||
// cloning the members of AbstractEAIndividual
|
||||
this.age = individual.age;
|
||||
@ -58,10 +58,10 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
public boolean equalGenotypes(AbstractEAIndividual individual) {
|
||||
if (individual instanceof GIOBGAIndividualIntegerPermutationData) {
|
||||
GIOBGAIndividualIntegerPermutationData indy = (GIOBGAIndividualIntegerPermutationData) individual;
|
||||
if (!((AbstractEAIndividual) this.m_Integer).equalGenotypes((AbstractEAIndividual) indy.m_Integer)) {
|
||||
if (!((AbstractEAIndividual) this.integerData).equalGenotypes((AbstractEAIndividual) indy.integerData)) {
|
||||
return false;
|
||||
}
|
||||
if (!((AbstractEAIndividual) this.m_Permutation).equalGenotypes((AbstractEAIndividual) indy.m_Permutation)) {
|
||||
if (!((AbstractEAIndividual) this.permutationData).equalGenotypes((AbstractEAIndividual) indy.permutationData)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -77,14 +77,14 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public void init(InterfaceOptimizationProblem opt) {
|
||||
((AbstractEAIndividual) this.m_Integer).init(opt);
|
||||
((AbstractEAIndividual) this.m_Permutation).init(opt);
|
||||
((AbstractEAIndividual) this.integerData).init(opt);
|
||||
((AbstractEAIndividual) this.permutationData).init(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
((AbstractEAIndividual) this.m_Integer).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.m_Permutation).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.integerData).defaultInit(prob);
|
||||
((AbstractEAIndividual) this.permutationData).defaultInit(prob);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,15 +98,15 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
||||
if (obj instanceof Object[]) {
|
||||
if (((Object[]) obj)[0] instanceof double[]) {
|
||||
((AbstractEAIndividual) this.m_Integer).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.m_Permutation).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.integerData).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.permutationData).initByValue(((Object[]) obj)[1], opt);
|
||||
} else {
|
||||
((AbstractEAIndividual) this.m_Integer).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.m_Permutation).initByValue(((Object[]) obj)[0], opt);
|
||||
((AbstractEAIndividual) this.integerData).initByValue(((Object[]) obj)[1], opt);
|
||||
((AbstractEAIndividual) this.permutationData).initByValue(((Object[]) obj)[0], opt);
|
||||
}
|
||||
} else {
|
||||
((AbstractEAIndividual) this.m_Integer).init(opt);
|
||||
((AbstractEAIndividual) this.m_Permutation).init(opt);
|
||||
((AbstractEAIndividual) this.integerData).init(opt);
|
||||
((AbstractEAIndividual) this.permutationData).init(opt);
|
||||
System.out.println("Initial value for GIOBGAIndividualIntegerPermutationData is not suitable!");
|
||||
}
|
||||
}
|
||||
@ -117,17 +117,17 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
@Override
|
||||
public void mutate() {
|
||||
if (RNG.flipCoin(this.mutationProbability)) {
|
||||
((AbstractEAIndividual) this.m_Integer).mutate();
|
||||
((AbstractEAIndividual) this.integerData).mutate();
|
||||
}
|
||||
if (RNG.flipCoin(this.mutationProbability)) {
|
||||
((AbstractEAIndividual) this.m_Permutation).mutate();
|
||||
((AbstractEAIndividual) this.permutationData).mutate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultMutate() {
|
||||
((AbstractEAIndividual) this.m_Integer).defaultMutate();
|
||||
((AbstractEAIndividual) this.m_Permutation).defaultMutate();
|
||||
((AbstractEAIndividual) this.integerData).defaultMutate();
|
||||
((AbstractEAIndividual) this.permutationData).defaultMutate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,17 +169,6 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
((GIOBGAIndividualIntegerPermutationData) result[i]).setIntegers((InterfaceDataTypeInteger) resNum[i]);
|
||||
((GIOBGAIndividualIntegerPermutationData) result[i]).setPermutations((InterfaceDataTypePermutation) resBin[i]);
|
||||
}
|
||||
|
||||
// result = ((AbstractEAIndividual)this.m_Numbers).mateWith(partners);
|
||||
// AbstractEAIndividual dad = (AbstractEAIndividual)result[0];
|
||||
// Population tpartners = new Population();
|
||||
// for (int i = 1; i < result.length; i++) tpartners.add(result[i]);
|
||||
// result = dad.mateWith(tpartners);
|
||||
|
||||
// out = "Result:\n";
|
||||
// for (int i = 0; i < result.length; i++) out += result[i].getSolutionRepresentationFor() + "\n";
|
||||
// System.out.println(out);
|
||||
|
||||
} else {
|
||||
// simply return a number of perfect clones
|
||||
result = new AbstractEAIndividual[partners.size() + 1];
|
||||
@ -203,8 +192,8 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
@Override
|
||||
public String getStringRepresentation() {
|
||||
String result = "This is a hybrid Individual:\n";
|
||||
result += "The Integer Part:\n" + ((AbstractEAIndividual) this.m_Integer).getStringRepresentation();
|
||||
result += "\nThe Permutation Part:\n" + ((AbstractEAIndividual) this.m_Permutation).getStringRepresentation();
|
||||
result += "The Integer Part:\n" + ((AbstractEAIndividual) this.integerData).getStringRepresentation();
|
||||
result += "\nThe Permutation Part:\n" + ((AbstractEAIndividual) this.permutationData).getStringRepresentation();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -218,7 +207,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public void setIntegerDataLength(int length) {
|
||||
this.m_Integer.setIntegerDataLength(length);
|
||||
this.integerData.setIntegerDataLength(length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,7 +217,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.m_Integer.size();
|
||||
return this.integerData.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,7 +229,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public void setIntRange(int[][] range) {
|
||||
this.m_Integer.setIntRange(range);
|
||||
this.integerData.setIntRange(range);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,7 +239,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public int[][] getIntRange() {
|
||||
return this.m_Integer.getIntRange();
|
||||
return this.integerData.getIntRange();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,7 +249,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public int[] getIntegerData() {
|
||||
return this.m_Integer.getIntegerData();
|
||||
return this.integerData.getIntegerData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,7 +260,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public int[] getIntegerDataWithoutUpdate() {
|
||||
return this.m_Integer.getIntegerDataWithoutUpdate();
|
||||
return this.integerData.getIntegerDataWithoutUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -281,7 +270,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public void setIntPhenotype(int[] intData) {
|
||||
this.m_Integer.setIntPhenotype(intData);
|
||||
this.integerData.setIntPhenotype(intData);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -292,7 +281,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public void setIntGenotype(int[] intData) {
|
||||
this.m_Integer.setIntGenotype(intData);
|
||||
this.integerData.setIntGenotype(intData);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
@ -305,8 +294,8 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public void setPermutationDataLength(int[] length) {
|
||||
this.m_Permutation.setPermutationDataLength(length);
|
||||
this.m_Integer.setIntegerDataLength(length.length);
|
||||
this.permutationData.setPermutationDataLength(length);
|
||||
this.integerData.setIntegerDataLength(length.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -316,7 +305,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public int[] sizePermutation() {
|
||||
return this.m_Permutation.sizePermutation();
|
||||
return this.permutationData.sizePermutation();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -326,7 +315,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public int[][] getPermutationData() {
|
||||
return this.m_Permutation.getPermutationData();
|
||||
return this.permutationData.getPermutationData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -337,7 +326,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
*/
|
||||
@Override
|
||||
public int[][] getPermutationDataWithoutUpdate() {
|
||||
return this.m_Permutation.getPermutationDataWithoutUpdate();
|
||||
return this.permutationData.getPermutationDataWithoutUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -363,7 +352,7 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
|
||||
@Override
|
||||
public void setFirstindex(int[] firstindex) {
|
||||
this.m_Permutation.setFirstindex(firstindex);
|
||||
this.permutationData.setFirstindex(firstindex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -383,11 +372,11 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
* @param Numbers The new representation for the inner constants.
|
||||
*/
|
||||
public void setIntegers(InterfaceDataTypeInteger Numbers) {
|
||||
this.m_Integer = Numbers;
|
||||
this.integerData = Numbers;
|
||||
}
|
||||
|
||||
public InterfaceDataTypeInteger getIntegers() {
|
||||
return this.m_Integer;
|
||||
return this.integerData;
|
||||
}
|
||||
|
||||
public String integersTipText() {
|
||||
@ -400,11 +389,11 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
||||
* @param p The new representation for the inner constants.
|
||||
*/
|
||||
public void setPermutations(InterfaceDataTypePermutation p) {
|
||||
this.m_Permutation = p;
|
||||
this.permutationData = p;
|
||||
}
|
||||
|
||||
public InterfaceDataTypePermutation getPermutations() {
|
||||
return this.m_Permutation;
|
||||
return this.permutationData;
|
||||
}
|
||||
|
||||
public String permutationsTipText() {
|
||||
|
@ -153,7 +153,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
||||
if ((this.checkMaxDepth) && (this.phenotype[i].isMaxDepthViolated(this.maxAllowedDepth))) {
|
||||
System.err.println("Trying to meet the Target Depth! " + this.phenotype[i].isMaxDepthViolated(this.maxAllowedDepth) + " " + phenotype[i].getMaxDepth());
|
||||
this.phenotype[i].repairMaxDepth(this.gpArea[i], this.maxAllowedDepth);
|
||||
//System.out.println("TragetDepth: " + this.m_TargetDepth + " : " + this.m_Program.getMaxDepth());
|
||||
//System.out.println("TragetDepth: " + this.targetDepth + " : " + this.m_Program.getMaxDepth());
|
||||
}
|
||||
}
|
||||
return this.phenotype;
|
||||
|
@ -9,15 +9,10 @@ import java.util.BitSet;
|
||||
/**
|
||||
* This gives the gray coding for double with a variable number of bits for coding
|
||||
* As far as i recall the least significant bit is to the left.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 24.03.2003
|
||||
* Time: 18:39:51
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class GAGrayCodingDouble implements InterfaceGADoubleCoding, java.io.Serializable {
|
||||
|
||||
GAStandardCodingDouble m_HelpingHand = new GAStandardCodingDouble();
|
||||
GAStandardCodingDouble standardCodingDouble = new GAStandardCodingDouble();
|
||||
|
||||
/**
|
||||
* This method decodes a part of a given BitSet into a double value. This method may change the contens
|
||||
@ -52,7 +47,7 @@ public class GAGrayCodingDouble implements InterfaceGADoubleCoding, java.io.Seri
|
||||
tmpBitSet.clear(i);
|
||||
}
|
||||
}
|
||||
return this.m_HelpingHand.decodeValue(tmpBitSet, range, tmpLocus, correction);
|
||||
return this.standardCodingDouble.decodeValue(tmpBitSet, range, tmpLocus, correction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +69,7 @@ public class GAGrayCodingDouble implements InterfaceGADoubleCoding, java.io.Seri
|
||||
tmpLocus[0] = 0;
|
||||
tmpLocus[1] = locus[1];
|
||||
tmpBitSet = new BitSet(tmpLocus.length);
|
||||
this.m_HelpingHand.codeValue(value, range, tmpBitSet, tmpLocus);
|
||||
this.standardCodingDouble.codeValue(value, range, tmpBitSet, tmpLocus);
|
||||
if (tmpBitSet.get(0)) {
|
||||
refBitSet.set(locus[0]);
|
||||
} else {
|
||||
|
@ -4,15 +4,10 @@ import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* This is a gray coding for integers, sorry no variable number of bits here.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 24.03.2003
|
||||
* Time: 18:40:03
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class GAGrayCodingInteger implements InterfaceGAIntegerCoding, java.io.Serializable {
|
||||
|
||||
GAStandardCodingInteger m_HelpingHand = new GAStandardCodingInteger();
|
||||
GAStandardCodingInteger standardCodingInteger = new GAStandardCodingInteger();
|
||||
|
||||
/**
|
||||
* This method decodes a part of a given BitSet into a int value. This method may change the contens
|
||||
@ -52,7 +47,7 @@ public class GAGrayCodingInteger implements InterfaceGAIntegerCoding, java.io.Se
|
||||
tmpBitSet.clear(i);
|
||||
}
|
||||
}
|
||||
return this.m_HelpingHand.decodeValue(tmpBitSet, range, tmpLocus, correction);
|
||||
return this.standardCodingInteger.decodeValue(tmpBitSet, range, tmpLocus, correction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +69,7 @@ public class GAGrayCodingInteger implements InterfaceGAIntegerCoding, java.io.Se
|
||||
tmpLocus[0] = 0;
|
||||
tmpLocus[1] = locus[1];
|
||||
tmpBitSet = new BitSet(tmpLocus.length);
|
||||
this.m_HelpingHand.codeValue(value, range, tmpBitSet, tmpLocus);
|
||||
this.standardCodingInteger.codeValue(value, range, tmpBitSet, tmpLocus);
|
||||
|
||||
// if (tmpBitSet.get(0)) refBitSet.set(locus[1]);
|
||||
// else refBitSet.clear(locus[1]);
|
||||
@ -103,7 +98,7 @@ public class GAGrayCodingInteger implements InterfaceGAIntegerCoding, java.io.Se
|
||||
*/
|
||||
@Override
|
||||
public int calculateNecessaryBits(int[] range) {
|
||||
return this.m_HelpingHand.calculateNecessaryBits(range);
|
||||
return this.standardCodingInteger.calculateNecessaryBits(range);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,11 +8,6 @@ import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* The traditional binary coding for integer number, no variable number of bits here, sorry.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 24.03.2003
|
||||
* Time: 16:38:45
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class GAStandardCodingInteger implements InterfaceGAIntegerCoding, java.io.Serializable {
|
||||
|
||||
|
@ -17,16 +17,11 @@ import java.util.Vector;
|
||||
|
||||
/**
|
||||
* This gives an abstract node, with default functionality for get and set methods.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 04.04.2003
|
||||
* Time: 13:12:53
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serializable {
|
||||
protected AbstractGPNode m_Parent;
|
||||
protected AbstractGPNode[] m_Nodes = new AbstractGPNode[0];
|
||||
protected int m_Depth = 0;
|
||||
protected AbstractGPNode parentNode;
|
||||
protected AbstractGPNode[] nodes = new AbstractGPNode[0];
|
||||
protected int depth = 0;
|
||||
private static final boolean TRACE = false;
|
||||
|
||||
/**
|
||||
@ -77,11 +72,11 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param node the node to clone values from
|
||||
*/
|
||||
protected void cloneMembers(AbstractGPNode node) {
|
||||
this.m_Depth = node.m_Depth;
|
||||
this.m_Parent = node.m_Parent;
|
||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
||||
for (int i = 0; i < node.m_Nodes.length; i++) {
|
||||
this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
||||
this.depth = node.depth;
|
||||
this.parentNode = node.parentNode;
|
||||
this.nodes = new AbstractGPNode[node.nodes.length];
|
||||
for (int i = 0; i < node.nodes.length; i++) {
|
||||
this.nodes[i] = (AbstractGPNode) node.nodes[i].clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,9 +85,9 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
sbuf.append(op);
|
||||
if (node.getArity() > 0) {
|
||||
sbuf.append("(");
|
||||
for (int i = 0; i < node.m_Nodes.length; i++) {
|
||||
sbuf.append(node.m_Nodes[i].getStringRepresentation());
|
||||
if (i < node.m_Nodes.length - 1) {
|
||||
for (int i = 0; i < node.nodes.length; i++) {
|
||||
sbuf.append(node.nodes[i].getStringRepresentation());
|
||||
if (i < node.nodes.length - 1) {
|
||||
sbuf.append(", ");
|
||||
}
|
||||
}
|
||||
@ -156,10 +151,10 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
return new Pair<AbstractGPNode, String>(currentNode, restStr);
|
||||
} else {
|
||||
restStr = str.substring(cutFront + 1).trim(); // cut this op and front brace
|
||||
currentNode.m_Nodes = new AbstractGPNode[currentNode.getArity()];
|
||||
currentNode.nodes = new AbstractGPNode[currentNode.getArity()];
|
||||
for (int i = 0; i < currentNode.getArity(); i++) {
|
||||
Pair<AbstractGPNode, String> nextState = parseFromString(restStr, nodeTypes);
|
||||
currentNode.m_Nodes[i] = nextState.head();
|
||||
currentNode.nodes[i] = nextState.head();
|
||||
try {
|
||||
restStr = nextState.tail().substring(1).trim(); // cut comma or brace
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
@ -384,7 +379,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @return The depth.
|
||||
*/
|
||||
public int getDepth() {
|
||||
return this.m_Depth;
|
||||
return this.depth;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -393,7 +388,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param depth The depth of the node
|
||||
*/
|
||||
public void setDepth(int depth) {
|
||||
this.m_Depth = depth;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -403,7 +398,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @return The requested node.
|
||||
*/
|
||||
public AbstractGPNode getNode(int index) {
|
||||
return this.m_Nodes[index];
|
||||
return this.nodes[index];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -414,8 +409,8 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
*/
|
||||
public void setNode(AbstractGPNode node, int index) {
|
||||
node.setParent(this);
|
||||
node.setDepth(this.m_Depth + 1);
|
||||
this.m_Nodes[index] = node;
|
||||
node.setDepth(this.depth + 1);
|
||||
this.nodes[index] = node;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -426,10 +421,10 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
*/
|
||||
public void setNode(AbstractGPNode newnode, AbstractGPNode oldnode) {
|
||||
newnode.setParent(this);
|
||||
newnode.updateDepth(this.m_Depth + 1);
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
if (this.m_Nodes[i] == oldnode) {
|
||||
this.m_Nodes[i] = newnode;
|
||||
newnode.updateDepth(this.depth + 1);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
if (this.nodes[i] == oldnode) {
|
||||
this.nodes[i] = newnode;
|
||||
// System.out.println("SWITCHED " + i);
|
||||
}
|
||||
}
|
||||
@ -442,8 +437,8 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
*/
|
||||
public void addNodesTo(ArrayList ListOfNodes) {
|
||||
ListOfNodes.add(this);
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
this.m_Nodes[i].addNodesTo(ListOfNodes);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
this.nodes[i].addNodesTo(ListOfNodes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -464,9 +459,9 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @return
|
||||
*/
|
||||
public AbstractGPNode getRandomLeaf() {
|
||||
if (m_Nodes.length > 0) {
|
||||
int k = RNG.randomInt(m_Nodes.length);
|
||||
return m_Nodes[k].getRandomLeaf();
|
||||
if (nodes.length > 0) {
|
||||
int k = RNG.randomInt(nodes.length);
|
||||
return nodes[k].getRandomLeaf();
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
@ -478,14 +473,14 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param parent The new parent
|
||||
*/
|
||||
public void setParent(AbstractGPNode parent) {
|
||||
this.m_Parent = parent;
|
||||
this.parentNode = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to get the parent of the node
|
||||
*/
|
||||
public AbstractGPNode getParent() {
|
||||
return this.m_Parent;
|
||||
return this.parentNode;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -494,14 +489,14 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param parent The parent
|
||||
*/
|
||||
public void connect(AbstractGPNode parent) {
|
||||
this.m_Parent = parent;
|
||||
this.parentNode = parent;
|
||||
if (parent != null) {
|
||||
this.m_Depth = this.m_Parent.getDepth() + 1;
|
||||
this.depth = this.parentNode.getDepth() + 1;
|
||||
} else {
|
||||
this.m_Depth = 0;
|
||||
this.depth = 0;
|
||||
}
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
this.m_Nodes[i].connect(this);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
this.nodes[i].connect(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -509,7 +504,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* This method will simply init the array of nodes
|
||||
*/
|
||||
public void initNodeArray() {
|
||||
this.m_Nodes = new AbstractGPNode[this.getArity()];
|
||||
this.nodes = new AbstractGPNode[this.getArity()];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -519,16 +514,16 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param depth The absolute target depth.
|
||||
*/
|
||||
public void initFull(GPArea area, int depth) {
|
||||
this.m_Nodes = new AbstractGPNode[this.getArity()];
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
if (this.m_Depth + 1 >= depth) {
|
||||
this.m_Nodes[i] = (AbstractGPNode) area.getRandomNodeWithArity(0).clone();
|
||||
this.nodes = new AbstractGPNode[this.getArity()];
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
if (this.depth + 1 >= depth) {
|
||||
this.nodes[i] = (AbstractGPNode) area.getRandomNodeWithArity(0).clone();
|
||||
} else {
|
||||
this.m_Nodes[i] = (AbstractGPNode) area.getRandomNonTerminal().clone();
|
||||
this.nodes[i] = (AbstractGPNode) area.getRandomNonTerminal().clone();
|
||||
}
|
||||
this.m_Nodes[i].setDepth(this.m_Depth + 1);
|
||||
this.m_Nodes[i].setParent(this);
|
||||
this.m_Nodes[i].initFull(area, depth);
|
||||
this.nodes[i].setDepth(this.depth + 1);
|
||||
this.nodes[i].setParent(this);
|
||||
this.nodes[i].initFull(area, depth);
|
||||
}
|
||||
}
|
||||
|
||||
@ -539,16 +534,16 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param depth The absolute target depth.
|
||||
*/
|
||||
public void initGrow(GPArea area, int depth) {
|
||||
this.m_Nodes = new AbstractGPNode[this.getArity()];
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
if (this.m_Depth + 1 >= depth) {
|
||||
this.m_Nodes[i] = (AbstractGPNode) area.getRandomNodeWithArity(0).clone();
|
||||
this.nodes = new AbstractGPNode[this.getArity()];
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
if (this.depth + 1 >= depth) {
|
||||
this.nodes[i] = (AbstractGPNode) area.getRandomNodeWithArity(0).clone();
|
||||
} else {
|
||||
this.m_Nodes[i] = (AbstractGPNode) area.getRandomNode().clone();
|
||||
this.nodes[i] = (AbstractGPNode) area.getRandomNode().clone();
|
||||
}
|
||||
this.m_Nodes[i].setDepth(this.m_Depth + 1);
|
||||
this.m_Nodes[i].setParent(this);
|
||||
this.m_Nodes[i].initGrow(area, depth);
|
||||
this.nodes[i].setDepth(this.depth + 1);
|
||||
this.nodes[i].setParent(this);
|
||||
this.nodes[i].initGrow(area, depth);
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,8 +554,8 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
*/
|
||||
public int getNumberOfNodes() {
|
||||
int result = 1;
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
result += this.m_Nodes[i].getNumberOfNodes();
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
result += this.nodes[i].getNumberOfNodes();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -571,10 +566,10 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @return The max depth.
|
||||
*/
|
||||
public int getMaxDepth() {
|
||||
int result = this.m_Depth;
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
if (this.m_Nodes[i] != null) {
|
||||
result = Math.max(result, this.m_Nodes[i].getMaxDepth());
|
||||
int result = this.depth;
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
if (this.nodes[i] != null) {
|
||||
result = Math.max(result, this.nodes[i].getMaxDepth());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -587,7 +582,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
*/
|
||||
public int getSubtreeDepth() {
|
||||
int maxDepth = getMaxDepth();
|
||||
return maxDepth - m_Depth;
|
||||
return maxDepth - depth;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -602,11 +597,11 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// if (depth > this.m_Depth) return false;
|
||||
// if (depth > this.depth) return false;
|
||||
// else {
|
||||
// boolean result = true;
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
// result = result & this.m_Nodes[i].isMaxDepthViolated(depth);
|
||||
// for (int i = 0; i < this.nodes.length; i++) {
|
||||
// result = result & this.nodes[i].isMaxDepthViolated(depth);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
@ -618,21 +613,21 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param depth The max depth.
|
||||
*/
|
||||
public void repairMaxDepth(GPArea area, int depth) {
|
||||
if (this.m_Depth == depth - 1) {
|
||||
if (this.depth == depth - 1) {
|
||||
// in this case i need to check whether or not my
|
||||
// follow-up nodes are terminals
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
if (this.m_Nodes[i].getArity() != 0) {
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
if (this.nodes[i].getArity() != 0) {
|
||||
// replace this node with a new node
|
||||
this.m_Nodes[i] = (AbstractGPNode) area.getRandomNodeWithArity(0).clone();
|
||||
this.m_Nodes[i].setDepth(this.m_Depth + 1);
|
||||
this.m_Nodes[i].setParent(this);
|
||||
this.nodes[i] = (AbstractGPNode) area.getRandomNodeWithArity(0).clone();
|
||||
this.nodes[i].setDepth(this.depth + 1);
|
||||
this.nodes[i].setParent(this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// else i call the method on my followup nodes
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
this.m_Nodes[i].repairMaxDepth(area, depth);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
this.nodes[i].repairMaxDepth(area, depth);
|
||||
}
|
||||
}
|
||||
|
||||
@ -652,11 +647,11 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
if (this.getArity() != node.getArity()) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_Nodes.length != node.m_Nodes.length) {
|
||||
if (this.nodes.length != node.nodes.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
if (!this.m_Nodes[i].equals(node.m_Nodes[i])) {
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
if (!this.nodes[i].equals(node.nodes[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -672,9 +667,9 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param myDepth
|
||||
*/
|
||||
public void updateDepth(int myDepth) {
|
||||
m_Depth = myDepth;
|
||||
for (int i = 0; i < m_Nodes.length; i++) {
|
||||
m_Nodes[i].updateDepth(myDepth + 1);
|
||||
depth = myDepth;
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
nodes[i].updateDepth(myDepth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -684,12 +679,12 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
||||
* @param myDepth
|
||||
*/
|
||||
public boolean checkDepth(int myDepth) {
|
||||
if (m_Depth != myDepth) {
|
||||
if (depth != myDepth) {
|
||||
System.err.println("Depth was wrong at level " + myDepth);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < m_Nodes.length; i++) {
|
||||
if (!m_Nodes[i].checkDepth(myDepth + 1)) {
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
if (!nodes[i].checkDepth(myDepth + 1)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -11,35 +11,30 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* This class gives the area of GPNodes for a GP problem. The area gives
|
||||
* the range of possible nodes to select from for a GP.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 13.06.2003
|
||||
* Time: 18:32:26
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class GPArea implements java.io.Serializable {
|
||||
/**
|
||||
* Handles property change notification
|
||||
*/
|
||||
private transient PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
private transient PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
|
||||
|
||||
private ArrayList<AbstractGPNode> m_CompleteList = new ArrayList<AbstractGPNode>();
|
||||
private ArrayList<AbstractGPNode> m_ReducedList = new ArrayList<AbstractGPNode>();
|
||||
private ArrayList<Boolean> m_BlackList = new ArrayList<Boolean>();
|
||||
private ArrayList<AbstractGPNode> completeList = new ArrayList<AbstractGPNode>();
|
||||
private ArrayList<AbstractGPNode> reducedList = new ArrayList<AbstractGPNode>();
|
||||
private ArrayList<Boolean> blackList = new ArrayList<Boolean>();
|
||||
|
||||
public GPArea() {
|
||||
|
||||
}
|
||||
|
||||
public GPArea(GPArea g) {
|
||||
if (g.m_BlackList != null) {
|
||||
this.m_BlackList = (ArrayList<Boolean>) g.m_BlackList.clone();
|
||||
if (g.blackList != null) {
|
||||
this.blackList = (ArrayList<Boolean>) g.blackList.clone();
|
||||
}
|
||||
if (g.m_ReducedList != null) {
|
||||
this.m_ReducedList = (ArrayList<AbstractGPNode>) g.m_ReducedList.clone();
|
||||
if (g.reducedList != null) {
|
||||
this.reducedList = (ArrayList<AbstractGPNode>) g.reducedList.clone();
|
||||
}
|
||||
if (g.m_CompleteList != null) {
|
||||
this.m_CompleteList = (ArrayList<AbstractGPNode>) g.m_CompleteList.clone();
|
||||
if (g.completeList != null) {
|
||||
this.completeList = (ArrayList<AbstractGPNode>) g.completeList.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,8 +49,8 @@ public class GPArea implements java.io.Serializable {
|
||||
* @param n The Node that is to be added
|
||||
*/
|
||||
public void add2CompleteList(AbstractGPNode n) {
|
||||
this.m_CompleteList.add(n);
|
||||
this.m_BlackList.add(new Boolean(true));
|
||||
this.completeList.add(n);
|
||||
this.blackList.add(new Boolean(true));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,8 +60,8 @@ public class GPArea implements java.io.Serializable {
|
||||
* @param b The initial BlacklLst value
|
||||
*/
|
||||
public void add2CompleteList(AbstractGPNode n, boolean b) {
|
||||
this.m_CompleteList.add(n);
|
||||
this.m_BlackList.add(new Boolean(b));
|
||||
this.completeList.add(n);
|
||||
this.blackList.add(new Boolean(b));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,7 +70,7 @@ public class GPArea implements java.io.Serializable {
|
||||
* @return blacklist
|
||||
*/
|
||||
public ArrayList<Boolean> getBlackList() {
|
||||
return this.m_BlackList;
|
||||
return this.blackList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,7 +79,7 @@ public class GPArea implements java.io.Serializable {
|
||||
* @param a blacklist
|
||||
*/
|
||||
public void SetBlackList(ArrayList<Boolean> a) {
|
||||
this.m_BlackList = a;
|
||||
this.blackList = a;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +89,7 @@ public class GPArea implements java.io.Serializable {
|
||||
* @param b the boolean value
|
||||
*/
|
||||
public void setBlackListElement(int i, boolean b) {
|
||||
this.m_BlackList.set(i, new Boolean(b));
|
||||
this.blackList.set(i, new Boolean(b));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +98,7 @@ public class GPArea implements java.io.Serializable {
|
||||
* @return blacklist
|
||||
*/
|
||||
public ArrayList<AbstractGPNode> getCompleteList() {
|
||||
return this.m_CompleteList;
|
||||
return this.completeList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,7 +107,7 @@ public class GPArea implements java.io.Serializable {
|
||||
* @return blacklist
|
||||
*/
|
||||
public ArrayList<AbstractGPNode> getReducedList() {
|
||||
return this.m_ReducedList;
|
||||
return this.reducedList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,21 +116,21 @@ public class GPArea implements java.io.Serializable {
|
||||
* @param a blacklist
|
||||
*/
|
||||
public void SetCompleteList(ArrayList<AbstractGPNode> a) {
|
||||
this.m_CompleteList = a;
|
||||
m_Support.firePropertyChange("GPArea", null, this);
|
||||
this.completeList = a;
|
||||
propertyChangeSupport.firePropertyChange("GPArea", null, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method compiles the Complete List to the allowed list using the BlackList
|
||||
*/
|
||||
public void compileReducedList() {
|
||||
this.m_ReducedList = new ArrayList<AbstractGPNode>();
|
||||
for (int i = 0; i < this.m_CompleteList.size(); i++) {
|
||||
if (((Boolean) (this.m_BlackList.get(i))).booleanValue()) {
|
||||
this.m_ReducedList.add(this.m_CompleteList.get(i));
|
||||
this.reducedList = new ArrayList<AbstractGPNode>();
|
||||
for (int i = 0; i < this.completeList.size(); i++) {
|
||||
if (((Boolean) (this.blackList.get(i))).booleanValue()) {
|
||||
this.reducedList.add(this.completeList.get(i));
|
||||
}
|
||||
}
|
||||
m_Support.firePropertyChange("GPArea", null, this);
|
||||
propertyChangeSupport.firePropertyChange("GPArea", null, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,9 +140,9 @@ public class GPArea implements java.io.Serializable {
|
||||
*/
|
||||
public AbstractGPNode getRandomNodeWithArity(int targetarity) {
|
||||
ArrayList<AbstractGPNode> tmpArray = new ArrayList<AbstractGPNode>();
|
||||
for (int i = 0; i < this.m_ReducedList.size(); i++) {
|
||||
if (((AbstractGPNode) this.m_ReducedList.get(i)).getArity() == targetarity) {
|
||||
tmpArray.add(this.m_ReducedList.get(i));
|
||||
for (int i = 0; i < this.reducedList.size(); i++) {
|
||||
if (((AbstractGPNode) this.reducedList.get(i)).getArity() == targetarity) {
|
||||
tmpArray.add(this.reducedList.get(i));
|
||||
}
|
||||
}
|
||||
if (tmpArray.size() == 0) {
|
||||
@ -161,10 +156,10 @@ public class GPArea implements java.io.Serializable {
|
||||
* This method will return a random node.
|
||||
*/
|
||||
public AbstractGPNode getRandomNode() {
|
||||
if (this.m_ReducedList.size() == 0) {
|
||||
if (this.reducedList.size() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return (AbstractGPNode) this.m_ReducedList.get(RNG.randomInt(0, this.m_ReducedList.size() - 1));
|
||||
return (AbstractGPNode) this.reducedList.get(RNG.randomInt(0, this.reducedList.size() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,9 +168,9 @@ public class GPArea implements java.io.Serializable {
|
||||
*/
|
||||
public AbstractGPNode getRandomNonTerminal() {
|
||||
ArrayList<AbstractGPNode> tmpArray = new ArrayList<AbstractGPNode>();
|
||||
for (int i = 0; i < this.m_ReducedList.size(); i++) {
|
||||
if (((AbstractGPNode) this.m_ReducedList.get(i)).getArity() > 0) {
|
||||
tmpArray.add(this.m_ReducedList.get(i));
|
||||
for (int i = 0; i < this.reducedList.size(); i++) {
|
||||
if (((AbstractGPNode) this.reducedList.get(i)).getArity() > 0) {
|
||||
tmpArray.add(this.reducedList.get(i));
|
||||
}
|
||||
}
|
||||
if (tmpArray.size() == 0) {
|
||||
@ -186,30 +181,30 @@ public class GPArea implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (m_CompleteList == null) || (m_CompleteList.size() == 0);
|
||||
return (completeList == null) || (completeList.size() == 0);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
m_CompleteList = new ArrayList<AbstractGPNode>();
|
||||
m_ReducedList = new ArrayList<AbstractGPNode>();
|
||||
m_BlackList = new ArrayList<Boolean>();
|
||||
m_Support.firePropertyChange("GPArea", null, this);
|
||||
completeList = new ArrayList<AbstractGPNode>();
|
||||
reducedList = new ArrayList<AbstractGPNode>();
|
||||
blackList = new ArrayList<Boolean>();
|
||||
propertyChangeSupport.firePropertyChange("GPArea", null, this);
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
if (m_Support == null) {
|
||||
m_Support = new PropertyChangeSupport(this);
|
||||
if (propertyChangeSupport == null) {
|
||||
propertyChangeSupport = new PropertyChangeSupport(this);
|
||||
}
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
propertyChangeSupport.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
if (m_Support == null) {
|
||||
m_Support = new PropertyChangeSupport(this);
|
||||
if (propertyChangeSupport == null) {
|
||||
propertyChangeSupport = new PropertyChangeSupport(this);
|
||||
}
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
propertyChangeSupport.removePropertyChangeListener(l);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class GPNodeAbs extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 0;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result += ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ public class GPNodeAdd extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 0;
|
||||
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
tmpObj = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
tmpObj = this.nodes[i].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result += ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class GPNodeCos extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result = Math.sin(((Double) tmpObj).doubleValue());
|
||||
}
|
||||
|
@ -7,14 +7,9 @@ import eva2.optimization.problems.InterfaceProgramProblem;
|
||||
* A division node with two arguments and secure division. If
|
||||
* the second argument is absolute smaller than 0.00000001 the
|
||||
* result is 1.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 04.04.2003
|
||||
* Time: 16:01:18
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class GPNodeDiv extends AbstractGPNode implements java.io.Serializable {
|
||||
private double m_LowerBorderForSec = 0.00000001;
|
||||
private double lowerBorderForSec = 0.00000001;
|
||||
|
||||
|
||||
public GPNodeDiv() {
|
||||
@ -22,7 +17,7 @@ public class GPNodeDiv extends AbstractGPNode implements java.io.Serializable {
|
||||
}
|
||||
|
||||
public GPNodeDiv(GPNodeDiv node) {
|
||||
this.m_LowerBorderForSec = node.m_LowerBorderForSec;
|
||||
this.lowerBorderForSec = node.lowerBorderForSec;
|
||||
this.cloneMembers(node);
|
||||
}
|
||||
|
||||
@ -67,20 +62,20 @@ public class GPNodeDiv extends AbstractGPNode implements java.io.Serializable {
|
||||
double result = 1;
|
||||
double tmpValue = 0;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result = ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
for (int i = 1; i < this.m_Nodes.length; i++) {
|
||||
tmpObj = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 1; i < this.nodes.length; i++) {
|
||||
tmpObj = this.nodes[i].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
tmpValue = ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
if (Math.abs(tmpValue) < this.m_LowerBorderForSec) {
|
||||
if (Math.abs(tmpValue) < this.lowerBorderForSec) {
|
||||
if (tmpValue < 0) {
|
||||
tmpValue = -this.m_LowerBorderForSec;
|
||||
tmpValue = -this.lowerBorderForSec;
|
||||
} else {
|
||||
tmpValue = this.m_LowerBorderForSec;
|
||||
tmpValue = this.lowerBorderForSec;
|
||||
}
|
||||
}
|
||||
result /= tmpValue;
|
||||
@ -97,6 +92,6 @@ public class GPNodeDiv extends AbstractGPNode implements java.io.Serializable {
|
||||
// * @return string
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// return AbstractGPNode.makeStringRepresentation(m_Nodes, "/");
|
||||
// return AbstractGPNode.makeStringRepresentation(nodes, "/");
|
||||
// }
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class GPNodeExp extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result = Math.exp(((Double) tmpObj).doubleValue());
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class GPNodeExp extends AbstractGPNode implements java.io.Serializable {
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// String result = "exp( ";
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) result += this.m_Nodes[i].getStringRepresentation() +" ";
|
||||
// for (int i = 0; i < this.nodes.length; i++) result += this.nodes[i].getStringRepresentation() +" ";
|
||||
// result += ")";
|
||||
// return result;
|
||||
// }
|
||||
|
@ -57,10 +57,10 @@ public class GPNodeFlowExec2 extends AbstractGPNode implements java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public Object evaluate(InterfaceProgramProblem environment) {
|
||||
Object[] result = new Object[this.m_Nodes.length];
|
||||
Object[] result = new Object[this.nodes.length];
|
||||
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
result[i] = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
result[i] = this.nodes[i].evaluate(environment);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class GPNodeFlowExec2 extends AbstractGPNode implements java.io.Serializa
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// String result = "Exec2( ";
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) result += this.m_Nodes[i].getStringRepresentation() +" ";
|
||||
// for (int i = 0; i < this.nodes.length; i++) result += this.nodes[i].getStringRepresentation() +" ";
|
||||
// result += ")";
|
||||
// return result;
|
||||
// }
|
||||
|
@ -57,10 +57,10 @@ public class GPNodeFlowExec3 extends AbstractGPNode implements java.io.Serializa
|
||||
*/
|
||||
@Override
|
||||
public Object evaluate(InterfaceProgramProblem environment) {
|
||||
Object[] result = new Object[this.m_Nodes.length];
|
||||
Object[] result = new Object[this.nodes.length];
|
||||
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
result[i] = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
result[i] = this.nodes[i].evaluate(environment);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -74,7 +74,7 @@ public class GPNodeFlowExec3 extends AbstractGPNode implements java.io.Serializa
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// String result = "Exec3( ";
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) result += this.m_Nodes[i].getStringRepresentation() +" ";
|
||||
// for (int i = 0; i < this.nodes.length; i++) result += this.nodes[i].getStringRepresentation() +" ";
|
||||
// result += ")";
|
||||
// return result;
|
||||
// }
|
||||
|
@ -3,24 +3,17 @@ package eva2.optimization.individuals.codings.gp;
|
||||
import eva2.optimization.problems.InterfaceProgramProblem;
|
||||
|
||||
/**
|
||||
* This node is able to read a sensor value from the environment (e.g. the
|
||||
* problem) the sensor to read is given by the identifier and has to be
|
||||
* implemented in the problem definition.
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 04.04.2003
|
||||
* Time: 15:38:05
|
||||
* To change this template use Options | File Templates.
|
||||
*
|
||||
*/
|
||||
public class GPNodeInput extends AbstractGPNode implements java.io.Serializable {
|
||||
private String m_Identifier;
|
||||
private String identifier;
|
||||
private Object lastValue;
|
||||
|
||||
/**
|
||||
* This method creates a new GPNodeInput
|
||||
*/
|
||||
public GPNodeInput() {
|
||||
this.m_Identifier = "X";
|
||||
this.identifier = "X";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,23 +22,23 @@ public class GPNodeInput extends AbstractGPNode implements java.io.Serializable
|
||||
* @param identifier The name of the sensor requested.
|
||||
*/
|
||||
public GPNodeInput(String identifier) {
|
||||
this.m_Identifier = identifier;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public GPNodeInput(GPNodeInput node) {
|
||||
this.m_Identifier = node.m_Identifier;
|
||||
this.identifier = node.identifier;
|
||||
this.cloneMembers(node);
|
||||
}
|
||||
|
||||
public void setIdentifier(String str) {
|
||||
m_Identifier = str;
|
||||
identifier = str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof GPNodeInput) {
|
||||
GPNodeInput node = (GPNodeInput) obj;
|
||||
if (!this.m_Identifier.equalsIgnoreCase(node.m_Identifier)) {
|
||||
if (!this.identifier.equalsIgnoreCase(node.identifier)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -61,7 +54,7 @@ public class GPNodeInput extends AbstractGPNode implements java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Sensor:" + this.m_Identifier;
|
||||
return "Sensor:" + this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +84,7 @@ public class GPNodeInput extends AbstractGPNode implements java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public Object evaluate(InterfaceProgramProblem environment) {
|
||||
lastValue = environment.getSensorValue(this.m_Identifier);
|
||||
lastValue = environment.getSensorValue(this.identifier);
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
@ -103,14 +96,14 @@ public class GPNodeInput extends AbstractGPNode implements java.io.Serializable
|
||||
@Override
|
||||
public String getOpIdentifier() {
|
||||
if (this.lastValue == null) {
|
||||
return this.m_Identifier;
|
||||
return this.identifier;
|
||||
} else {
|
||||
if (this.lastValue instanceof Double) {
|
||||
double tmpD = ((Double) this.lastValue).doubleValue();
|
||||
tmpD = ((long) (tmpD * 10000.0 + ((tmpD >= 0.0) ? 0.5 : -0.5))) / 10000.0;
|
||||
return ("S:" + this.m_Identifier + " = " + tmpD);
|
||||
return ("S:" + this.identifier + " = " + tmpD);
|
||||
} else {
|
||||
return ("S:" + this.m_Identifier + " = " + this.lastValue.toString());
|
||||
return ("S:" + this.identifier + " = " + this.lastValue.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ public class GPNodeMult extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
tmpObj = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
tmpObj = this.nodes[i].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result *= ((Double) tmpObj).doubleValue();
|
||||
} else {
|
||||
@ -79,6 +79,6 @@ public class GPNodeMult extends AbstractGPNode implements java.io.Serializable {
|
||||
// * @return string
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// return AbstractGPNode.makeStringRepresentation(m_Nodes, "*");
|
||||
// return AbstractGPNode.makeStringRepresentation(nodes, "*");
|
||||
// }
|
||||
}
|
||||
|
@ -60,12 +60,12 @@ public class GPNodeNeg extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 0;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result += ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
for (int i = 1; i < this.m_Nodes.length; i++) {
|
||||
tmpObj = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 1; i < this.nodes.length; i++) {
|
||||
tmpObj = this.nodes[i].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result -= ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
@ -81,6 +81,6 @@ public class GPNodeNeg extends AbstractGPNode implements java.io.Serializable {
|
||||
// * @return string
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// return AbstractGPNode.makeStringRepresentation(m_Nodes, "-");
|
||||
// return AbstractGPNode.makeStringRepresentation(nodes, "-");
|
||||
// }
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ import eva2.optimization.problems.InterfaceProgramProblem;
|
||||
*/
|
||||
public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable {
|
||||
|
||||
private String m_Identifier;
|
||||
private String identifier;
|
||||
|
||||
public GPNodeOutput() {
|
||||
this.m_Identifier = "Y";
|
||||
this.identifier = "Y";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,11 +27,11 @@ public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable
|
||||
* @param identifier The name of the sensor requested.
|
||||
*/
|
||||
public GPNodeOutput(String identifier) {
|
||||
this.m_Identifier = identifier;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public GPNodeOutput(GPNodeOutput node) {
|
||||
this.m_Identifier = node.m_Identifier;
|
||||
this.identifier = node.identifier;
|
||||
this.cloneMembers(node);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof GPNodeOutput) {
|
||||
GPNodeOutput node = (GPNodeOutput) obj;
|
||||
if (!this.m_Identifier.equalsIgnoreCase(node.m_Identifier)) {
|
||||
if (!this.identifier.equalsIgnoreCase(node.identifier)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -55,7 +55,7 @@ public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Actuator:" + this.m_Identifier;
|
||||
return "Actuator:" + this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,13 +85,13 @@ public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable
|
||||
*/
|
||||
@Override
|
||||
public Object evaluate(InterfaceProgramProblem environment) {
|
||||
environment.setActuatorValue(this.m_Identifier, null);
|
||||
environment.setActuatorValue(this.identifier, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOpIdentifier() {
|
||||
return "OUT:" + m_Identifier;
|
||||
return "OUT:" + identifier;
|
||||
}
|
||||
// /** This method returns a string representation
|
||||
// * @return string
|
||||
|
@ -59,7 +59,7 @@ public class GPNodePow2 extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result = Math.pow(((Double) tmpObj).doubleValue(), 2);
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class GPNodePow2 extends AbstractGPNode implements java.io.Serializable {
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// String result = "";
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) result += this.m_Nodes[i].getStringRepresentation() +" ";
|
||||
// for (int i = 0; i < this.nodes.length; i++) result += this.nodes[i].getStringRepresentation() +" ";
|
||||
// return "("+result+")^2";
|
||||
// }
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class GPNodePow3 extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result = Math.pow(((Double) tmpObj).doubleValue(), 3);
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class GPNodePow3 extends AbstractGPNode implements java.io.Serializable {
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// String result = "pow( ";
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) result += this.m_Nodes[i].getStringRepresentation() +" ";
|
||||
// for (int i = 0; i < this.nodes.length; i++) result += this.nodes[i].getStringRepresentation() +" ";
|
||||
// result += ", 3)";
|
||||
// return result;
|
||||
// }
|
||||
|
@ -41,8 +41,8 @@ public class GPNodeProd extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
tmpObj = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
tmpObj = this.nodes[i].evaluate(environment);
|
||||
if (tmpObj instanceof double[]) {
|
||||
result *= Mathematics.product((double[]) tmpObj);
|
||||
} else if (tmpObj instanceof Double[]) {
|
||||
|
@ -59,7 +59,7 @@ public class GPNodeSin extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result = Math.sin(((Double) tmpObj).doubleValue());
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class GPNodeSin extends AbstractGPNode implements java.io.Serializable {
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// String result = "sin( ";
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) result += this.m_Nodes[i].getStringRepresentation() +" ";
|
||||
// for (int i = 0; i < this.nodes.length; i++) result += this.nodes[i].getStringRepresentation() +" ";
|
||||
// result += ")";
|
||||
// return result;
|
||||
// }
|
||||
|
@ -60,7 +60,7 @@ public class GPNodeSqrt extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 1;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result = Math.sqrt(Math.abs(((Double) tmpObj).doubleValue()));
|
||||
}
|
||||
@ -77,7 +77,7 @@ public class GPNodeSqrt extends AbstractGPNode implements java.io.Serializable {
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// String result = "sqrt( ";
|
||||
// for (int i = 0; i < this.m_Nodes.length; i++) result += this.m_Nodes[i].getStringRepresentation() +" ";
|
||||
// for (int i = 0; i < this.nodes.length; i++) result += this.nodes[i].getStringRepresentation() +" ";
|
||||
// result += ")";
|
||||
// return result;
|
||||
// }
|
||||
|
@ -60,12 +60,12 @@ public class GPNodeSub extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 0;
|
||||
|
||||
tmpObj = this.m_Nodes[0].evaluate(environment);
|
||||
tmpObj = this.nodes[0].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result += ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
for (int i = 1; i < this.m_Nodes.length; i++) {
|
||||
tmpObj = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 1; i < this.nodes.length; i++) {
|
||||
tmpObj = this.nodes[i].evaluate(environment);
|
||||
if (tmpObj instanceof Double) {
|
||||
result -= ((Double) tmpObj).doubleValue();
|
||||
}
|
||||
@ -81,6 +81,6 @@ public class GPNodeSub extends AbstractGPNode implements java.io.Serializable {
|
||||
// * @return string
|
||||
// */
|
||||
// public String getStringRepresentation() {
|
||||
// return AbstractGPNode.makeStringRepresentation(m_Nodes, "-");
|
||||
// return AbstractGPNode.makeStringRepresentation(nodes, "-");
|
||||
// }
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ public class GPNodeSum extends AbstractGPNode implements java.io.Serializable {
|
||||
Object tmpObj;
|
||||
double result = 0;
|
||||
|
||||
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||
tmpObj = this.m_Nodes[i].evaluate(environment);
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
tmpObj = this.nodes[i].evaluate(environment);
|
||||
if (tmpObj instanceof double[]) {
|
||||
result += Mathematics.sum((double[]) tmpObj);
|
||||
} else if (tmpObj instanceof Double[]) {
|
||||
|
@ -943,21 +943,6 @@ public class ANPSO extends NichePSO implements InterfaceOptimizer, InterfaceAddi
|
||||
this.maxInitialSubSwarmSize = maxSubSwarmSize;
|
||||
}
|
||||
|
||||
// public void setMainSwarmPhi2(double mainSwarmPhi2) {
|
||||
// super.SetMainSwarmPhi2(mainSwarmPhi2);
|
||||
// }
|
||||
// public String mainSwarmPhi2TipText(){
|
||||
// return "weights the social component for the PSO used to train the main swarm";
|
||||
// }
|
||||
|
||||
// /** This method allows you to choose the topology type.
|
||||
// * @param s The type.
|
||||
// */
|
||||
// public void setMainSwarmTopology(SelectedTag s) {
|
||||
// mainSwarm.m_Topology = s;
|
||||
// this.mainSwarmTopologyTag = s.getSelectedTagID();
|
||||
// GenericObjectEditor.setHideProperty(getClass(), "mainSwarmTopologyRange", mainSwarmTopologyTag == 3); // "Multi-Swarm" has no topologyRange
|
||||
// }
|
||||
|
||||
public String mainSwarmTopologyTipText() {
|
||||
return "sets the topology type used to train the main swarm";
|
||||
|
Loading…
x
Reference in New Issue
Block a user