From cb1bef68af47188600631b9234ae5b6ec24c6211 Mon Sep 17 00:00:00 2001 From: Marcel Kronfeld Date: Wed, 4 May 2011 11:58:04 +0000 Subject: [PATCH] Individual updates --- .../individuals/ESIndividualDoubleData.java | 25 ++++++++++++------- .../IndividualDistanceComparator.java | 3 ++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/eva2/server/go/individuals/ESIndividualDoubleData.java b/src/eva2/server/go/individuals/ESIndividualDoubleData.java index 8e116d65..52b1cd07 100644 --- a/src/eva2/server/go/individuals/ESIndividualDoubleData.java +++ b/src/eva2/server/go/individuals/ESIndividualDoubleData.java @@ -117,6 +117,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte } this.m_Genotype = newDesPa; this.m_Range = newRange; + this.m_Phenotype = null; // mark as invalid // changed 28.08.03 by request of Spieth // this.m_DecisionParameters = new double[length]; @@ -162,9 +163,14 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte * @return BitSet representing the double data. */ public double[] getDoubleData() { - this.m_Phenotype = new double[this.m_Genotype.length]; - System.arraycopy(this.m_Genotype, 0, this.m_Phenotype, 0, this.m_Genotype.length); - return this.m_Phenotype; + // since the phenotype is set to null if the genotype is changed, + // it should now be save to only perform the copy if the phenotype is null + if (this.m_Phenotype!=null) return m_Phenotype; + else { + this.m_Phenotype = new double[this.m_Genotype.length]; + System.arraycopy(this.m_Genotype, 0, this.m_Phenotype, 0, this.m_Genotype.length); + return this.m_Phenotype; + } } /** @@ -190,7 +196,8 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte * @param doubleData The new double data. */ public void SetDoubleGenotype(double[] doubleData) { - this.SetDoublePhenotype(doubleData); +// this.SetDoublePhenotype(doubleData); + this.SetDoublePhenotype(null); // tag it as invalid this.m_Genotype = new double[doubleData.length]; System.arraycopy(doubleData, 0, this.m_Genotype, 0, doubleData.length); } @@ -204,11 +211,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte public void init(InterfaceOptimizationProblem opt) { super.init(opt); // evil operators may not respect the range, so at least give some hint - if (!Mathematics.isInRange(m_Genotype, m_Range)) { - EVAERROR.errorMsgOnce("Warning: Individual out of range after initialization (and potential initial crossover/mutation)!"); -// System.err.println("Indy was: " + BeanInspector.toString(m_Genotype)); -// System.err.println("Range was " + BeanInspector.toString(m_Range)); - } + if (!Mathematics.isInRange(m_Genotype, m_Range)) EVAERROR.errorMsgOnce("Warning: Individual out of range after initialization (and potential initial crossover/mutation)!"); } /** This method will init the individual with a given value for the @@ -270,6 +273,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte */ public void SetDGenotype(double[] b) { this.m_Genotype = b; + this.m_Phenotype=null; // mark it as invalid 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[i][0]; if (this.m_Genotype[i] > this.m_Range[i][1]) this.m_Genotype[i] = this.m_Range[i][1]; @@ -280,6 +284,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte * @param b The new genotype of the Individual */ public void SetDGenotypeNocheck(double[] b) { + this.m_Phenotype = null; // mark it as invalid this.m_Genotype = b; } @@ -287,6 +292,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte */ public void defaultMutate() { ESIndividualDoubleData.defaultMutate(this.m_Genotype, this.m_Range); + m_Phenotype=null; // mark it as invalid } /** @@ -307,6 +313,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte public void defaultInit(InterfaceOptimizationProblem prob) { if ((prob != null) && (prob instanceof InterfaceHasInitRange) && (((InterfaceHasInitRange)prob).getInitRange()!=null)) ESIndividualDoubleData.defaultInit(m_Genotype, (double[][])((InterfaceHasInitRange)prob).getInitRange()); else ESIndividualDoubleData.defaultInit(m_Genotype, m_Range); + m_Phenotype = null; // mark as invalid } /** diff --git a/src/eva2/server/go/individuals/IndividualDistanceComparator.java b/src/eva2/server/go/individuals/IndividualDistanceComparator.java index ad387e4f..376cdce0 100644 --- a/src/eva2/server/go/individuals/IndividualDistanceComparator.java +++ b/src/eva2/server/go/individuals/IndividualDistanceComparator.java @@ -1,5 +1,6 @@ package eva2.server.go.individuals; +import java.io.Serializable; import java.util.Comparator; import eva2.server.go.operators.distancemetric.InterfaceDistanceMetric; @@ -8,7 +9,7 @@ import eva2.server.go.operators.distancemetric.InterfaceDistanceMetric; * Compare two AbstractEAIndividuals by their distance to a reference individual. * Usable to sort by a distance. **/ -public class IndividualDistanceComparator implements Comparator { +public class IndividualDistanceComparator implements Comparator, Serializable { private AbstractEAIndividual refIndy=null; private InterfaceDistanceMetric distMetric = null;