diff --git a/src/eva2/EvAInfo.java b/src/eva2/EvAInfo.java index 18f64807..96f545d9 100644 --- a/src/eva2/EvAInfo.java +++ b/src/eva2/EvAInfo.java @@ -5,11 +5,17 @@ package eva2; * * --- Changelog * 2.030: Added an EnumEditor to access enums easily through the GUI. + * IPOP-ES and RankMuCMA mutator have been added lately (wow!). + * Cleaned up the IndividualInterface and reduced the usage of InterfaceESIndividual. This + * means that, e.g., that DE and PSO now also work on GAIndividualDoubleData. Because this + * requires much time for transcoding, however, this is not useful by itself. Yet it could be + * interesting for combined individuals composed of two data types. + * Cleaned up MutateXXDefault to a single MutateDefault, too. * 2.029: Tuned the 2d-graphs which now paints quicker and changes size depending on the * surrounding plot window. Added a preloader-thread to accelerate the GUI at starting time. * 2.028: Tuned the Population to sort only when necessary on calls to getBestN... Added StatisticsDummy. * Slightly tuned SimpleProblemWrapper to call initProblem of simple problems if available. - * 2.027: Renamed SetData and SetDataLamarckian from individual datatype interfaces to SetGenotype and SetPhenotype. + * 2.027: Renamed SetData and SetDataLamarckian from individual data type interfaces to SetGenotype and SetPhenotype. * Repaired the GenericArrayEditor. Population measures can now be plotted in stats. * 2.026: Added DiversityTerminator and KnownOptimaTerminator, slightly changed InterfaceTerminator for these * and InterfaceStatistics to provide termination message to text window. diff --git a/src/eva2/server/go/IndividualInterface.java b/src/eva2/server/go/IndividualInterface.java index 3d59afc9..86da44d0 100644 --- a/src/eva2/server/go/IndividualInterface.java +++ b/src/eva2/server/go/IndividualInterface.java @@ -9,20 +9,60 @@ package eva2.server.go; * $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $ * $Author: mkron $ */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ - /*==========================================================================* - * INTERFACE DECLARATION - *==========================================================================*/ + /** - * + * Minimal interface for an EA individual. */ public interface IndividualInterface { - public IndividualInterface getClone(); - public double[] getFitness(); - public void SetFitness (double[] fit); - public double[] getDoubleArray(); - public boolean isDominant(double[] otherFitness); - public boolean isDominant(IndividualInterface other); + /** + * Create a clone of the individual instance. + * + * @return a clone of the individual instance + */ + public IndividualInterface getClone(); + + /** + * Get the fitness array of the individual which may be null if none has been set. + * + * @return the fitness array of the individual + */ + public double[] getFitness(); + + /** + * Set the fitness array to the given array. + * + * @param fit new fitness of the individual + */ + public void SetFitness (double[] fit); + + /** + * Check whether the instance is dominating the given other individual and return + * true in this case. + * + * @param other a second individual of the same type + * @return true if the instance dominates the other individual, else false + */ + public boolean isDominant(double[] fitness); + + /** + * Check whether the instance is dominating the given other individual and return + * true in this case. + * Should behave equally to {@link #isDominant(double[])} if called with the fitness + * of the given individual. + * + * @param other a second individual of the same type + * @return true if the instance dominates the other individual, else false + */ + public boolean isDominant(IndividualInterface other); + + /** + * Perform a standard mutation operation on the individual. The exact implementation + * depends on the implemented genotype. + */ + public void defaultMutate(); + + /** + * Initialize the genotype randomly, usually in a uniform distribution. + */ + public void defaultInit(); } \ No newline at end of file diff --git a/src/eva2/server/go/individuals/AbstractEAIndividual.java b/src/eva2/server/go/individuals/AbstractEAIndividual.java index 6276e245..6a34a93d 100644 --- a/src/eva2/server/go/individuals/AbstractEAIndividual.java +++ b/src/eva2/server/go/individuals/AbstractEAIndividual.java @@ -22,9 +22,9 @@ import eva2.tools.EVAERROR; /** This is the abstract EA individual implementing the most important methods giving * access to mutation and crossover rates and operators, fitness values and selection * probabilities. All EA individuals should typically extend this abstract EA individual. - * In that case the EA individuals only implement the genotpye and phenotype interfaces. - * The names of the implementation should be build like this: - * (Genotpye)Individual(Phenotype) + * In that case the EA individuals only implement the genotype and phenotype interfaces. + * The names of the implementation should be built like this: + * (Genotype)Individual(Phenotype) * Thus a binary individual coding double values is named GAIndividualDoubleData and a * real-valued individual coding binary values is named ESIndividualBinaryData. * Created by IntelliJ IDEA. @@ -531,7 +531,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. } /** This method will allow you to compare two individuals regarding the dominance. - * Note this is dominance! If the individuals are invariant this method will + * Note this is dominance! If the individuals are not comparable this method will * return false! * @param indy The individual to compare to. * @return True if better false else @@ -583,7 +583,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. } /** This method will allow you to compare two individuals regarding the dominance. - * Note this is dominance! If the individuals are invariant this method will + * Note this is dominance! If the individuals are not comparable this method will * return false! * @param indy The individual to compare to. * @return True if better false else @@ -607,7 +607,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. } /** This method will allow you to compare two individuals regarding the dominance. - * Note this is dominance! If the individuals are invariant this method will + * Note this is dominance! If the individuals are not comparable this method will * return false! * @param indy The individual to compare to. * @return True if better false else @@ -620,7 +620,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. } /** This method will allow you to compare two individuals regarding the dominance. - * Note this is dominance! If the individuals are invariant this method will + * Note this is dominance! If the individuals are not comparable this method will * return false! * * @param indy The individual to compare to. @@ -889,16 +889,16 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java. return (IndividualInterface)this.clone(); } - /** This method is used to get the basic data type of an individual double[]. - * @deprecated Since not all EAIndividuals provide double as basic data type - * the fitness can be is returned as default value. - * @see #getFitness() - * @return double[] - */ - public double[] getDoubleArray() { - if (this instanceof InterfaceDataTypeDouble) return ((InterfaceDataTypeDouble)this).getDoubleData(); - else return this.getFitness(); - } +// /** This method is used to get the basic data type of an individual double[]. +// * @deprecated Since not all EAIndividuals provide double as basic data type +// * the fitness can be is returned as default value. +// * @see #getFitness() +// * @return double[] +// */ +// public double[] getDoubleArray() { +// if (this instanceof InterfaceDataTypeDouble) return ((InterfaceDataTypeDouble)this).getDoubleData(); +// else return this.getFitness(); +// } public boolean isDominantNotEqual(double[] otherFitness) { return isDominatingFitnessNotEqual(m_Fitness, otherFitness); diff --git a/src/eva2/server/go/individuals/ESIndividualBinaryData.java b/src/eva2/server/go/individuals/ESIndividualBinaryData.java index d82a649e..691a5f5c 100644 --- a/src/eva2/server/go/individuals/ESIndividualBinaryData.java +++ b/src/eva2/server/go/individuals/ESIndividualBinaryData.java @@ -257,18 +257,13 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte /** This method performs a simple one element mutation on the double vector */ public void defaultMutate() { - int mutationIndex = RNG.randomInt(0, this.m_Genotype.length-1); - this.m_Genotype[mutationIndex] += ((this.m_Range[mutationIndex][1] - this.m_Range[mutationIndex][0])/2)*RNG.gaussianDouble(0.05f); - if (this.m_Genotype[mutationIndex] < this.m_Range[mutationIndex][0]) this.m_Genotype[mutationIndex] = this.m_Range[mutationIndex][0]; - if (this.m_Genotype[mutationIndex] > this.m_Range[mutationIndex][1]) this.m_Genotype[mutationIndex] = this.m_Range[mutationIndex][1]; + ESIndividualDoubleData.defaultMutate(m_Genotype, m_Range); } /** This method initializes the double vector */ public void defaultInit() { - for (int i = 0; i < this.m_Genotype.length; i++) { - this.m_Genotype[i] = RNG.randomDouble(this.m_Range[i][0], this.m_Range[i][1]); - } + ESIndividualDoubleData.defaultInit(m_Genotype, m_Range); } /********************************************************************************************************************** * These are for GUI diff --git a/src/eva2/server/go/individuals/ESIndividualDoubleData.java b/src/eva2/server/go/individuals/ESIndividualDoubleData.java index eeba3602..34604850 100644 --- a/src/eva2/server/go/individuals/ESIndividualDoubleData.java +++ b/src/eva2/server/go/individuals/ESIndividualDoubleData.java @@ -275,17 +275,40 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte /** This method performs a simple one element mutation on the double vector */ public void defaultMutate() { - int mutationIndex = RNG.randomInt(0, this.m_Genotype.length-1); - this.m_Genotype[mutationIndex] += ((this.m_Range[mutationIndex][1] - this.m_Range[mutationIndex][0])/2)*RNG.gaussianDouble(0.05f); - if (this.m_Genotype[mutationIndex] < this.m_Range[mutationIndex][0]) this.m_Genotype[mutationIndex] = this.m_Range[mutationIndex][0]; - if (this.m_Genotype[mutationIndex] > this.m_Range[mutationIndex][1]) this.m_Genotype[mutationIndex] = this.m_Range[mutationIndex][1]; + ESIndividualDoubleData.defaultMutate(this.m_Genotype, this.m_Range); } + /** + * Helper method for default ES mutation. A single, uniformly chosen double entry + * is mutated with a gaussian value. + * If the range constraint is violated, the value is set on the bound. + * + * @param genotype + * @param range + */ + public static void defaultMutate(double[] genotype, double[][] range) { + int mutationIndex = RNG.randomInt(0, genotype.length-1); + genotype[mutationIndex] += ((range[mutationIndex][1] - range[mutationIndex][0])/2)*RNG.gaussianDouble(0.05f); + if (genotype[mutationIndex] < range[mutationIndex][0]) genotype[mutationIndex] = range[mutationIndex][0]; + if (genotype[mutationIndex] > range[mutationIndex][1]) genotype[mutationIndex] = range[mutationIndex][1]; + } + /** This method initializes the double vector */ public void defaultInit() { - for (int i = 0; i < this.m_Genotype.length; i++) { - this.m_Genotype[i] = RNG.randomDouble(this.m_Range[i][0], this.m_Range[i][1]); + ESIndividualDoubleData.defaultInit(m_Genotype, m_Range); + } + + /** + * Helper method for initialization. The genotype is distributed uniformly + * within the given range. + * + * @param genotype + * @param range + */ + public static void defaultInit(double[] genotype, double[][] range) { + for (int i = 0; i < genotype.length; i++) { + genotype[i] = RNG.randomDouble(range[i][0], range[i][1]); } } diff --git a/src/eva2/server/go/individuals/ESIndividualPermutationData.java b/src/eva2/server/go/individuals/ESIndividualPermutationData.java index cab03986..885e90b9 100644 --- a/src/eva2/server/go/individuals/ESIndividualPermutationData.java +++ b/src/eva2/server/go/individuals/ESIndividualPermutationData.java @@ -7,7 +7,8 @@ import eva2.server.go.operators.mutation.MutateESGlobal; import eva2.server.go.problems.InterfaceOptimizationProblem; import wsi.ra.math.RNG; -/** This individual uses a real-valued genotype to code for a permutations, +/** + * This individual uses a real-valued genotype to code for a permutations, * the sorting of the real-valued genotype gives the permutation. * Created by IntelliJ IDEA. * User: streiche @@ -316,25 +317,20 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements } - /** This method performs a simple one element mutation on the double vector + /** This method performs a one element mutation on every permutation coded by a double vector. */ public void defaultMutate() { for (int i = 0; i < m_Genotype.length; i++) { - int mutationIndex = RNG.randomInt(0, this.m_Genotype[i].length-1); - this.m_Genotype[i][mutationIndex] += ((this.m_Range[i][mutationIndex][1] - this.m_Range[i][mutationIndex][0])/2)*RNG.gaussianDouble(0.05f); - if (this.m_Genotype[i][mutationIndex] < this.m_Range[i][mutationIndex][0]) this.m_Genotype[i][mutationIndex] = this.m_Range[i][mutationIndex][0]; - if (this.m_Genotype[i][mutationIndex] > this.m_Range[i][mutationIndex][1]) this.m_Genotype[i][mutationIndex] = this.m_Range[i][mutationIndex][1]; + ESIndividualDoubleData.defaultMutate(m_Genotype[i], m_Range[i]); } - } - /** This method initializes the double vector + /** + * This method initializes the double vector */ public void defaultInit() { for (int i = 0; i < this.m_Genotype.length; i++) { - for (int j = 0; j < this.m_Genotype[i].length; j++) { - this.m_Genotype[i][j] = RNG.randomDouble(this.m_Range[i][j][0], this.m_Range[i][j][1]); - } + ESIndividualDoubleData.defaultInit(m_Genotype[i], m_Range[i]); } } diff --git a/src/eva2/server/go/individuals/GAESIndividualBinaryDoubleData.java b/src/eva2/server/go/individuals/GAESIndividualBinaryDoubleData.java index 7b64ff4d..0072995b 100644 --- a/src/eva2/server/go/individuals/GAESIndividualBinaryDoubleData.java +++ b/src/eva2/server/go/individuals/GAESIndividualBinaryDoubleData.java @@ -75,6 +75,11 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme ((AbstractEAIndividual)this.m_BitSet).init(opt); } + public void defaultInit() { + ((AbstractEAIndividual)this.m_Numbers).defaultInit(); + ((AbstractEAIndividual)this.m_BitSet).defaultInit(); + } + /** This method will init the individual with a given value for the * phenotype. * @param obj The initial value for the phenotype @@ -103,6 +108,11 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme if (RNG.flipCoin(this.m_MutationProbability))((AbstractEAIndividual)this.m_BitSet).mutate(); } + public void defaultMutate() { + ((AbstractEAIndividual)this.m_Numbers).defaultMutate(); + ((AbstractEAIndividual)this.m_BitSet).defaultMutate(); + } + /** This method will mate the Individual with given other individuals * of the same type. * @param partners The possible partners diff --git a/src/eva2/server/go/individuals/GAIndividualBinaryData.java b/src/eva2/server/go/individuals/GAIndividualBinaryData.java index b9a8492b..170bdfd7 100644 --- a/src/eva2/server/go/individuals/GAIndividualBinaryData.java +++ b/src/eva2/server/go/individuals/GAIndividualBinaryData.java @@ -3,16 +3,11 @@ package eva2.server.go.individuals; import java.util.BitSet; -import eva2.server.go.operators.crossover.CrossoverGADefault; -import eva2.server.go.operators.crossover.CrossoverGANPoint; -import eva2.server.go.operators.crossover.InterfaceCrossover; -import eva2.server.go.operators.crossover.NoCrossover; -import eva2.server.go.operators.mutation.InterfaceMutation; -import eva2.server.go.operators.mutation.MutateGADefault; -import eva2.server.go.operators.mutation.MutateGAStandard; -import eva2.server.go.operators.mutation.NoMutation; -import eva2.server.go.problems.InterfaceOptimizationProblem; import wsi.ra.math.RNG; +import eva2.server.go.operators.crossover.CrossoverGANPoint; +import eva2.server.go.operators.mutation.InterfaceMutation; +import eva2.server.go.operators.mutation.MutateGAStandard; +import eva2.server.go.problems.InterfaceOptimizationProblem; /** This individual uses a binary genotype to code for binary values. * Created by IntelliJ IDEA. diff --git a/src/eva2/server/go/individuals/GAIndividualDoubleData.java b/src/eva2/server/go/individuals/GAIndividualDoubleData.java index ec0b73d8..f133fadb 100644 --- a/src/eva2/server/go/individuals/GAIndividualDoubleData.java +++ b/src/eva2/server/go/individuals/GAIndividualDoubleData.java @@ -3,16 +3,13 @@ package eva2.server.go.individuals; import java.util.BitSet; +import wsi.ra.math.RNG; import eva2.server.go.individuals.codings.ga.GAStandardCodingDouble; import eva2.server.go.individuals.codings.ga.InterfaceGADoubleCoding; -import eva2.server.go.operators.crossover.CrossoverGADefault; import eva2.server.go.operators.crossover.CrossoverGANPoint; -import eva2.server.go.operators.crossover.InterfaceCrossover; import eva2.server.go.operators.mutation.InterfaceMutation; -import eva2.server.go.operators.mutation.MutateGADefault; import eva2.server.go.operators.mutation.MutateGAStandard; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; /** This individual uses a binary genotype to code for double values * using two alternative encodings. diff --git a/src/eva2/server/go/individuals/GAPIndividualProgramData.java b/src/eva2/server/go/individuals/GAPIndividualProgramData.java index 71b8859b..da077d2c 100644 --- a/src/eva2/server/go/individuals/GAPIndividualProgramData.java +++ b/src/eva2/server/go/individuals/GAPIndividualProgramData.java @@ -1,20 +1,11 @@ package eva2.server.go.individuals; -import java.util.ArrayList; - -import eva2.server.go.individuals.codings.gp.AbstractGPNode; -import eva2.server.go.individuals.codings.gp.GPArea; +import wsi.ra.math.RNG; import eva2.server.go.individuals.codings.gp.InterfaceProgram; -import eva2.server.go.operators.crossover.CrossoverESDefault; -import eva2.server.go.operators.crossover.CrossoverGPDefault; -import eva2.server.go.operators.crossover.InterfaceCrossover; import eva2.server.go.operators.mutation.InterfaceMutation; -import eva2.server.go.operators.mutation.MutateESDefault; -import eva2.server.go.operators.mutation.MutateGPDefault; import eva2.server.go.populations.Population; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; /** This individual combines a real-valued phenotype with a tree-based phenotype. * Created by IntelliJ IDEA. @@ -82,7 +73,12 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In ((AbstractEAIndividual)this.m_Numbers).init(opt); ((AbstractEAIndividual)this.m_Program).init(opt); } - + + public void defaultInit() { + ((AbstractEAIndividual)this.m_Numbers).defaultInit(); + ((AbstractEAIndividual)this.m_Program).defaultInit(); + } + /** This method will init the individual with a given value for the * phenotype. * @param obj The initial value for the phenotype @@ -111,6 +107,11 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In if (RNG.flipCoin(this.m_MutationProbability))((AbstractEAIndividual)this.m_Program).mutate(); } + public void defaultMutate() { + ((AbstractEAIndividual)this.m_Numbers).defaultMutate(); + ((AbstractEAIndividual)this.m_Program).defaultMutate(); + } + /** This method will mate the Individual with given other individuals * of the same type. * @param partners The possible partners diff --git a/src/eva2/server/go/individuals/GEIndividualProgramData.java b/src/eva2/server/go/individuals/GEIndividualProgramData.java index 5069ca9c..85620964 100644 --- a/src/eva2/server/go/individuals/GEIndividualProgramData.java +++ b/src/eva2/server/go/individuals/GEIndividualProgramData.java @@ -1,17 +1,17 @@ package eva2.server.go.individuals; -import java.util.BitSet; import java.util.ArrayList; +import java.util.BitSet; +import wsi.ra.math.RNG; import eva2.server.go.individuals.codings.gp.AbstractGPNode; import eva2.server.go.individuals.codings.gp.GPArea; import eva2.server.go.individuals.codings.gp.InterfaceProgram; import eva2.server.go.operators.crossover.CrossoverGADefault; import eva2.server.go.operators.mutation.InterfaceMutation; -import eva2.server.go.operators.mutation.MutateGADefault; +import eva2.server.go.operators.mutation.MutateDefault; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; /** This individual uses a binary genotype to code for a tree-based representation * using a BNF grammar, see also Grammatical Evolution. @@ -42,7 +42,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int this.m_Area = new GPArea[1]; this.m_GenotypeLengthPerProgram = 240; this.m_Genotype = new BitSet(); - this.m_MutationOperator = new MutateGADefault(); + this.m_MutationOperator = new MutateDefault(); this.m_CrossoverOperator = new CrossoverGADefault(); this.m_MutationProbability = 0.5; this.m_CrossoverProbability = 0.5; diff --git a/src/eva2/server/go/individuals/GIIndividualIntegerData.java b/src/eva2/server/go/individuals/GIIndividualIntegerData.java index fc3b6694..5547c662 100644 --- a/src/eva2/server/go/individuals/GIIndividualIntegerData.java +++ b/src/eva2/server/go/individuals/GIIndividualIntegerData.java @@ -1,10 +1,10 @@ package eva2.server.go.individuals; +import wsi.ra.math.RNG; import eva2.server.go.operators.crossover.CrossoverGIDefault; import eva2.server.go.operators.mutation.InterfaceMutation; -import eva2.server.go.operators.mutation.MutateGIDefault; +import eva2.server.go.operators.mutation.MutateDefault; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; /** This individual uses a integer genotype to code for integer values. * Created by IntelliJ IDEA. @@ -21,7 +21,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int public GIIndividualIntegerData() { this.m_MutationProbability = 0.1; - this.m_MutationOperator = new MutateGIDefault(); + this.m_MutationOperator = new MutateDefault(); this.m_CrossoverProbability = 0.7; this.m_CrossoverOperator = new CrossoverGIDefault(); this.m_Range = new int[10][2]; diff --git a/src/eva2/server/go/individuals/GIOBGAIndividualIntegerPermutationData.java b/src/eva2/server/go/individuals/GIOBGAIndividualIntegerPermutationData.java index 1945dd4e..2a5b8df8 100644 --- a/src/eva2/server/go/individuals/GIOBGAIndividualIntegerPermutationData.java +++ b/src/eva2/server/go/individuals/GIOBGAIndividualIntegerPermutationData.java @@ -74,6 +74,11 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual ((AbstractEAIndividual)this.m_Integer).init(opt); ((AbstractEAIndividual)this.m_Permutation).init(opt); } + + public void defaultInit() { + ((AbstractEAIndividual)this.m_Integer).defaultInit(); + ((AbstractEAIndividual)this.m_Permutation).defaultInit(); + } /** This method will init the individual with a given value for the * phenotype. @@ -103,6 +108,11 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual if (RNG.flipCoin(this.m_MutationProbability))((AbstractEAIndividual)this.m_Permutation).mutate(); } + public void defaultMutate() { + ((AbstractEAIndividual)this.m_Integer).defaultMutate(); + ((AbstractEAIndividual)this.m_Permutation).defaultMutate(); + } + /** This method will mate the Individual with given other individuals * of the same type. * @param partners The possible partners diff --git a/src/eva2/server/go/individuals/GPIndividualProgramData.java b/src/eva2/server/go/individuals/GPIndividualProgramData.java index 431bcf14..7379c687 100644 --- a/src/eva2/server/go/individuals/GPIndividualProgramData.java +++ b/src/eva2/server/go/individuals/GPIndividualProgramData.java @@ -3,16 +3,15 @@ package eva2.server.go.individuals; import java.util.ArrayList; +import wsi.ra.math.RNG; import eva2.server.go.individuals.codings.gp.AbstractGPNode; import eva2.server.go.individuals.codings.gp.GPArea; import eva2.server.go.individuals.codings.gp.InterfaceProgram; import eva2.server.go.operators.crossover.CrossoverGPDefault; import eva2.server.go.operators.mutation.InterfaceMutation; -import eva2.server.go.operators.mutation.MutateGPDefault; +import eva2.server.go.operators.mutation.MutateDefault; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; import eva2.tools.EVAERROR; -import eva2.tools.EVAHELP; /** This individual uses a tree-based genotype to code for program trees. * Created by IntelliJ IDEA. @@ -35,7 +34,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int this.m_Area = new GPArea[1]; m_Area[0] = new GPArea(); this.m_Genotype = new AbstractGPNode[1]; - this.m_MutationOperator = new MutateGPDefault(); + this.m_MutationOperator = new MutateDefault(); this.m_CrossoverOperator = new CrossoverGPDefault(); } diff --git a/src/eva2/server/go/individuals/InterfaceESIndividual.java b/src/eva2/server/go/individuals/InterfaceESIndividual.java index 5544c588..8ed51df3 100644 --- a/src/eva2/server/go/individuals/InterfaceESIndividual.java +++ b/src/eva2/server/go/individuals/InterfaceESIndividual.java @@ -33,11 +33,4 @@ public interface InterfaceESIndividual { */ public double[][] getDoubleRange(); - /** This method performs a simple one element mutation on the double vector - */ - public void defaultMutate(); - - /** This method initializes the double vector - */ - public void defaultInit(); } diff --git a/src/eva2/server/go/individuals/InterfaceGAIndividual.java b/src/eva2/server/go/individuals/InterfaceGAIndividual.java index 73361a27..a411e5bb 100644 --- a/src/eva2/server/go/individuals/InterfaceGAIndividual.java +++ b/src/eva2/server/go/individuals/InterfaceGAIndividual.java @@ -11,7 +11,7 @@ import java.util.BitSet; * Time: 14:25:24 * To change this template use Options | File Templates. */ -public interface InterfaceGAIndividual { +public interface InterfaceGAIndividual { /** This method will allow the user to read the GA genotype * @return BitSet @@ -33,11 +33,4 @@ public interface InterfaceGAIndividual { */ public int getGenotypeLength(); - /** This method performs a simple one point mutation in the genotype - */ - public void defaultMutate(); - - /** This method initializes the GA genotype randomly - */ - public void defaultInit(); } diff --git a/src/eva2/server/go/individuals/InterfaceGIIndividual.java b/src/eva2/server/go/individuals/InterfaceGIIndividual.java index 4efd0ece..d9c45fb9 100644 --- a/src/eva2/server/go/individuals/InterfaceGIIndividual.java +++ b/src/eva2/server/go/individuals/InterfaceGIIndividual.java @@ -1,6 +1,5 @@ package eva2.server.go.individuals; -import java.util.BitSet; /** This interface gives access to a integer genotype and should * only be used by mutation and crossover operators. @@ -48,12 +47,4 @@ public interface InterfaceGIIndividual { * @return The length of the genotype. */ public int getGenotypeLength(); - - /** This method performs a simple one point mutation in the genotype - */ - public void defaultMutate(); - - /** This method initializes the GA genotype randomly - */ - public void defaultInit(); } diff --git a/src/eva2/server/go/individuals/InterfaceGPIndividual.java b/src/eva2/server/go/individuals/InterfaceGPIndividual.java index b6751617..05da744d 100644 --- a/src/eva2/server/go/individuals/InterfaceGPIndividual.java +++ b/src/eva2/server/go/individuals/InterfaceGPIndividual.java @@ -33,11 +33,4 @@ public interface InterfaceGPIndividual { */ public Object[] getFunctionArea(); - /** This method performs a simple one element mutation on the program - */ - public void defaultMutate(); - - /** This method initializes the program - */ - public void defaultInit(); } diff --git a/src/eva2/server/go/individuals/InterfaceOBGAIndividual.java b/src/eva2/server/go/individuals/InterfaceOBGAIndividual.java index c0ac1068..c0f71db1 100644 --- a/src/eva2/server/go/individuals/InterfaceOBGAIndividual.java +++ b/src/eva2/server/go/individuals/InterfaceOBGAIndividual.java @@ -27,14 +27,4 @@ public interface InterfaceOBGAIndividual { * @param b int[] new genotype */ public void SetOBGenotype(int[][] b); - - - /** - * defaultMutate perfoms a mutation by flipping two elements in the permutation - */ - public void defaultMutate(); - - /** This method initializes the program - */ - public void defaultInit(); } diff --git a/src/eva2/server/go/individuals/codings/ga/InterfaceGADoubleCoding.java b/src/eva2/server/go/individuals/codings/ga/InterfaceGADoubleCoding.java index 9dd075ae..cdaecc68 100644 --- a/src/eva2/server/go/individuals/codings/ga/InterfaceGADoubleCoding.java +++ b/src/eva2/server/go/individuals/codings/ga/InterfaceGADoubleCoding.java @@ -12,7 +12,7 @@ import java.util.BitSet; public interface InterfaceGADoubleCoding { /** This method decodes a part of a given BitSet into a double value. This method may change the contens * of the BitSet if it doesn't describe a valid value. - * The method checks wether or not the value is within the given range. + * The method checks whether or not the value is within the given range. * @param refBitSet The BitSet where the questioned value is stored. * @param range The allowed range of the value. * @param locus The position and length on the BitSet that is to be decoded. @@ -21,9 +21,9 @@ public interface InterfaceGADoubleCoding { */ public double decodeValue(BitSet refBitSet, double[] range, int[] locus, boolean correction); - /** This method codes a given int value directly into a BitSet at + /** This method codes a given double value directly into a BitSet at * the position which is specified by locus. - * The method checks wether or not the value is within the given range. + * The method checks whether or not the value is within the given range. * @param value The value to be coded. * @param range The allowed range of the value. * @param refBitSet The BitSet where the questioned value is stored. diff --git a/src/eva2/server/go/operators/mutation/MutateGIDefault.java b/src/eva2/server/go/operators/mutation/MutateDefault.java similarity index 76% rename from src/eva2/server/go/operators/mutation/MutateGIDefault.java rename to src/eva2/server/go/operators/mutation/MutateDefault.java index 0a1462b3..d235cc69 100644 --- a/src/eva2/server/go/operators/mutation/MutateGIDefault.java +++ b/src/eva2/server/go/operators/mutation/MutateDefault.java @@ -1,24 +1,23 @@ package eva2.server.go.operators.mutation; +import eva2.server.go.IndividualInterface; import eva2.server.go.individuals.AbstractEAIndividual; -import eva2.server.go.individuals.InterfaceGIIndividual; +import eva2.server.go.individuals.InterfaceESIndividual; import eva2.server.go.populations.Population; import eva2.server.go.problems.InterfaceOptimizationProblem; + /** - * Created by IntelliJ IDEA. - * User: streiche - * Date: 18.05.2005 - * Time: 17:08:49 - * To change this template use File | Settings | File Templates. + * Mutate individuals using the default operator implemented by the individuals themselves. + * */ -public class MutateGIDefault implements InterfaceMutation, java.io.Serializable { +public class MutateDefault implements InterfaceMutation, java.io.Serializable { /** This method will enable you to clone a given mutation operator * @return The clone */ public Object clone() { - return new MutateGIDefault(); + return new MutateDefault(); } /** This method allows you to evaluate wether two mutation operators @@ -26,7 +25,7 @@ public class MutateGIDefault implements InterfaceMutation, java.io.Serializable * @param mutator The other mutation operator */ public boolean equals(Object mutator) { - if (mutator instanceof MutateGIDefault) return true; + if (mutator instanceof MutateDefault) return true; else return false; } @@ -38,6 +37,14 @@ public class MutateGIDefault implements InterfaceMutation, java.io.Serializable } + /** This method will mutate a given AbstractEAIndividual. If the individual + * doesn't implement InterfaceGAIndividual nothing happens. + * @param individual The individual that is to be mutated + */ + public void mutate(AbstractEAIndividual individual) { + if (individual instanceof IndividualInterface) ((IndividualInterface)individual).defaultMutate(); + } + /** This method allows you to perform either crossover on the strategy parameters * or to deal in some other way with the crossover event. * @param indy1 The original mother @@ -47,20 +54,12 @@ public class MutateGIDefault implements InterfaceMutation, java.io.Serializable // nothing to do here } - /** This method will mutate a given AbstractEAIndividual. If the individual - * doesn't implement InterfaceGAIndividual nothing happens. - * @param individual The individual that is to be mutated - */ - public void mutate(AbstractEAIndividual individual) { - if (individual instanceof InterfaceGIIndividual) ((InterfaceGIIndividual)individual).defaultMutate(); - } - /** This method allows you to get a string representation of the mutation * operator * @return A descriptive string. */ public String getStringRepresentation() { - return "GI default mutation"; + return "Default mutation"; } /********************************************************************************************************************** @@ -71,12 +70,12 @@ public class MutateGIDefault implements InterfaceMutation, java.io.Serializable * @return The name. */ public String getName() { - return "GI default mutation"; + return "Default mutation"; } /** This method returns a global info string * @return description */ public String globalInfo() { - return "The default mutation alters one element of the int attributes."; + return "The default mutation just uses the default method implemented in the individual."; } -} \ No newline at end of file +} diff --git a/src/eva2/server/go/operators/mutation/MutateESDefault.java b/src/eva2/server/go/operators/mutation/MutateESDefault.java deleted file mode 100644 index 76d20b19..00000000 --- a/src/eva2/server/go/operators/mutation/MutateESDefault.java +++ /dev/null @@ -1,85 +0,0 @@ -package eva2.server.go.operators.mutation; - -import eva2.server.go.individuals.AbstractEAIndividual; -import eva2.server.go.individuals.InterfaceESIndividual; -import eva2.server.go.populations.Population; -import eva2.server.go.problems.InterfaceOptimizationProblem; - - -/** - * Created by IntelliJ IDEA. - * User: streiche - * Date: 25.03.2003 - * Time: 10:58:44 - * To change this template use Options | File Templates. - */ -public class MutateESDefault implements InterfaceMutation, java.io.Serializable { - - /** This method will enable you to clone a given mutation operator - * @return The clone - */ - public Object clone() { - return new MutateESDefault(); - } - - /** This method allows you to evaluate wether two mutation operators - * are actually the same. - * @param mutator The other mutation operator - */ - public boolean equals(Object mutator) { - if (mutator instanceof MutateESDefault) return true; - else return false; - } - - /** This method allows you to init the mutation operator - * @param individual The individual that will be mutated. - * @param opt The optimization problem. - */ - public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt){ - - } - - /** This method will mutate a given AbstractEAIndividual. If the individual - * doesn't implement InterfaceGAIndividual nothing happens. - * @param individual The individual that is to be mutated - */ - public void mutate(AbstractEAIndividual individual) { - //System.out.println("Before Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor()); - if (individual instanceof InterfaceESIndividual) ((InterfaceESIndividual)individual).defaultMutate(); - //System.out.println("After Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor()); - } - - /** This method allows you to perform either crossover on the strategy parameters - * or to deal in some other way with the crossover event. - * @param indy1 The original mother - * @param partners The original partners - */ - public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) { - // nothing to do here - } - - /** This method allows you to get a string representation of the mutation - * operator - * @return A descriptive string. - */ - public String getStringRepresentation() { - return "ES default mutation"; - } - -/********************************************************************************************************************** - * These are for GUI - */ - /** This method allows the CommonJavaObjectEditorPanel to read the - * name to the current object. - * @return The name. - */ - public String getName() { - return "ES default mutation"; - } - /** This method returns a global info string - * @return description - */ - public String globalInfo() { - return "The default mutation just uses the default method implemented in the individual."; - } -} diff --git a/src/eva2/server/go/operators/mutation/MutateGADefault.java b/src/eva2/server/go/operators/mutation/MutateGADefault.java deleted file mode 100644 index e5b6fab3..00000000 --- a/src/eva2/server/go/operators/mutation/MutateGADefault.java +++ /dev/null @@ -1,88 +0,0 @@ -package eva2.server.go.operators.mutation; - -import eva2.server.go.individuals.AbstractEAIndividual; -import eva2.server.go.individuals.InterfaceGAIndividual; -import eva2.server.go.populations.Population; -import eva2.server.go.problems.InterfaceOptimizationProblem; - - -/** - * This operator performs one-point mutation. - * Created by IntelliJ IDEA. - * - * User: streiche - * Date: 18.03.2003 - * Time: 12:36:08 - * To change this template use Options | File Templates. - */ -public class MutateGADefault implements InterfaceMutation, java.io.Serializable { - - /** This method will enable you to clone a given mutation operator - * @return The clone - */ - public Object clone() { - return new MutateGADefault(); - } - - /** This method allows you to evaluate wether two mutation operators - * are actually the same. - * @param mutator The other mutation operator - */ - public boolean equals(Object mutator) { - if (mutator instanceof MutateGADefault) return true; - else return false; - } - - /** This method allows you to init the mutation operator - * @param individual The individual that will be mutated. - * @param opt The optimization problem. - */ - public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { - - } - - /** This method will mutate a given AbstractEAIndividual. If the individual - * doesn't implement InterfaceGAIndividual nothing happens. - * @param individual The individual that is to be mutated - */ - public void mutate(AbstractEAIndividual individual) { - //System.out.println("Before Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor()); - if (individual instanceof InterfaceGAIndividual) ((InterfaceGAIndividual)individual).defaultMutate(); - //System.out.println("After Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor()); - } - - /** This method allows you to perform either crossover on the strategy parameters - * or to deal in some other way with the crossover event. - * @param indy1 The original mother - * @param partners The original partners - */ - public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) { - // nothing to do here - } - - - /** This method allows you to get a string representation of the mutation - * operator - * @return A descriptive string. - */ - public String getStringRepresentation() { - return "GA default mutation"; - } - -/********************************************************************************************************************** - * These are for GUI - */ - /** This method allows the CommonJavaObjectEditorPanel to read the - * name to the current object. - * @return The name. - */ - public String getName() { - return "GA default mutation"; - } - /** This method returns a global info string - * @return description - */ - public String globalInfo() { - return "The default mutation switches one bit of the GA genotype."; - } -} diff --git a/src/eva2/server/go/operators/mutation/MutateGPAdaptive.java b/src/eva2/server/go/operators/mutation/MutateGPAdaptive.java index 5f95f757..c25d5351 100644 --- a/src/eva2/server/go/operators/mutation/MutateGPAdaptive.java +++ b/src/eva2/server/go/operators/mutation/MutateGPAdaptive.java @@ -1,14 +1,12 @@ package eva2.server.go.operators.mutation; -import java.util.BitSet; - +import wsi.ra.math.RNG; +import eva2.server.go.IndividualInterface; import eva2.server.go.individuals.AbstractEAIndividual; -import eva2.server.go.individuals.InterfaceGAIndividual; import eva2.server.go.individuals.InterfaceGPIndividual; import eva2.server.go.populations.Population; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; /** * Created by IntelliJ IDEA. @@ -73,7 +71,7 @@ public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable this.m_MutationStep = this.m_MutationStep * Math.exp(this.m_Tau1 * RNG.gaussianDouble(1) + this.m_Tau2 * RNG.gaussianDouble(1)); if (this.m_MutationStep < this.m_LowerLimitStepSize) this.m_MutationStep = this.m_LowerLimitStepSize; if (this.m_MutationStep > 1) this.m_MutationStep = 1; - if (RNG.flipCoin(this.m_MutationStep)) ((InterfaceGPIndividual)individual).defaultMutate(); + if (RNG.flipCoin(this.m_MutationStep)) ((IndividualInterface)individual).defaultMutate(); } //System.out.println("After Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor()); } diff --git a/src/eva2/server/go/operators/mutation/MutateGPDefault.java b/src/eva2/server/go/operators/mutation/MutateGPDefault.java deleted file mode 100644 index b02267fc..00000000 --- a/src/eva2/server/go/operators/mutation/MutateGPDefault.java +++ /dev/null @@ -1,89 +0,0 @@ -package eva2.server.go.operators.mutation; - -import eva2.server.go.individuals.AbstractEAIndividual; -import eva2.server.go.individuals.InterfaceGPIndividual; -import eva2.server.go.populations.Population; -import eva2.server.go.problems.InterfaceOptimizationProblem; - -/** - * Created by IntelliJ IDEA. - * User: streiche - * Date: 04.04.2003 - * Time: 16:38:31 - * To change this template use Options | File Templates. - */ -public class MutateGPDefault implements InterfaceMutation, java.io.Serializable { - - public MutateGPDefault() { - - } - /** This method will enable you to clone a given mutation operator - * @return The clone - */ - public Object clone() { - return new MutateGPDefault(); - } - - /** This method allows you to evaluate wether two mutation operators - * are actually the same. - * @param mutator The other mutation operator - */ - public boolean equals(Object mutator) { - if (mutator instanceof MutateGPDefault) return true; - else return false; - } - - /** This method allows you to init the mutation operator - * @param individual The individual that will be mutated. - * @param opt The optimization problem. - */ - public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { - - } - - /** This method will mutate a given AbstractEAIndividual. If the individual - * doesn't implement InterfaceGAIndividual nothing happens. - * @param individual The individual that is to be mutated - */ - public void mutate(AbstractEAIndividual individual) { -// System.out.println("Before Mutate: " +((InterfaceGPIndividual)individual).getPGenotype()[0].getStringRepresentation()); -// System.out.println("Length: " +((InterfaceGPIndividual)individual).getPGenotype()[0].getNumberOfNodes()); - if (individual instanceof InterfaceGPIndividual) ((InterfaceGPIndividual)individual).defaultMutate(); -// System.out.println("After Mutate: " +((InterfaceGPIndividual)individual).getPGenotype()[0].getStringRepresentation()); -// System.out.println("Length: " +((InterfaceGPIndividual)individual).getPGenotype()[0].getNumberOfNodes()); - } - - /** This method allows you to perform either crossover on the strategy parameters - * or to deal in some other way with the crossover event. - * @param indy1 The original mother - * @param partners The original partners - */ - public void crossoverOnStrategyParameters(AbstractEAIndividual indy1, Population partners) { - // nothing to do here - } - - /** This method allows you to get a string representation of the mutation - * operator - * @return A descriptive string. - */ - public String getStringRepresentation() { - return "GP default mutation"; - } - -/********************************************************************************************************************** - * These are for GUI - */ - /** This method allows the CommonJavaObjectEditorPanel to read the - * name to the current object. - * @return The name. - */ - public String getName() { - return "GP default mutation"; - } - /** This method returns a global info string - * @return description - */ - public String globalInfo() { - return "The default mutation replaces a random subtree using init, also called headless chicken mutation."; - } -} diff --git a/src/eva2/server/go/strategies/DifferentialEvolution.java b/src/eva2/server/go/strategies/DifferentialEvolution.java index 347cdffc..4f4b832b 100644 --- a/src/eva2/server/go/strategies/DifferentialEvolution.java +++ b/src/eva2/server/go/strategies/DifferentialEvolution.java @@ -6,7 +6,7 @@ import wsi.ra.math.RNG; import eva2.gui.GenericObjectEditor; import eva2.server.go.InterfacePopulationChangedEventListener; import eva2.server.go.individuals.AbstractEAIndividual; -import eva2.server.go.individuals.InterfaceESIndividual; +import eva2.server.go.individuals.InterfaceDataTypeDouble; import eva2.server.go.operators.selection.replacement.ReplacementCrowding; import eva2.server.go.populations.InterfaceSolutionSet; import eva2.server.go.populations.Population; @@ -166,11 +166,11 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial * @param indy The current individual * @return the delta vector */ - private double[] fetchDeltaBest(Population pop, InterfaceESIndividual indy) { + private double[] fetchDeltaBest(Population pop, InterfaceDataTypeDouble indy) { double[] x1, result; AbstractEAIndividual xbIndy; - x1 = indy.getDGenotype(); + x1 = indy.getDoubleData(); result = new double[x1.length]; if (m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) { // implements MODE for the multi-objective case: a dominating individual is selected for difference building @@ -220,21 +220,21 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial public AbstractEAIndividual generateNewIndividual(Population pop) { int firstParentIndex; AbstractEAIndividual indy; - InterfaceESIndividual esIndy; + InterfaceDataTypeDouble esIndy; if (doLogParents) parents = new Vector(); else parents = null; try { // select one random indy as starting individual. its a parent in any case. firstParentIndex = RNG.randomInt(0, pop.size()-1); indy = (AbstractEAIndividual)(pop.getEAIndividual(firstParentIndex)).getClone(); - esIndy = (InterfaceESIndividual)indy; + esIndy = (InterfaceDataTypeDouble)indy; } catch (java.lang.ClassCastException e) { System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); return (AbstractEAIndividual)((AbstractEAIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getClone(); } double[] nX, vX, oX; - oX = esIndy.getDGenotype(); - vX = esIndy.getDGenotype(); + oX = esIndy.getDoubleData(); + vX = esIndy.getDoubleData(); nX = new double[oX.length]; switch (this.m_DEType.getSelectedTag().getID()) { case 0 : { @@ -274,11 +274,11 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial if (RNG.flipCoin(this.m_Mt)) { double[] xk, xl; double p, pj, pk, pl; - InterfaceESIndividual indy1 = null, indy2 = null; + InterfaceDataTypeDouble indy1 = null, indy2 = null; try { // and i got indy! - indy1 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1)); - indy2 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1)); + indy1 = (InterfaceDataTypeDouble)pop.get(RNG.randomInt(0, pop.size()-1)); + indy2 = (InterfaceDataTypeDouble)pop.get(RNG.randomInt(0, pop.size()-1)); if (parents != null) { parents.add((AbstractEAIndividual)indy1); parents.add((AbstractEAIndividual)indy2); @@ -286,8 +286,8 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial } catch (java.lang.ClassCastException e) { EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); } - xk = indy1.getDGenotype(); - xl = indy2.getDGenotype(); + xk = indy1.getDoubleData(); + xl = indy2.getDoubleData(); p = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy1).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy2).getFitness(0)); pj = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0))/p; pk = Math.abs(((AbstractEAIndividual)indy1).getFitness(0))/p; @@ -316,7 +316,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial } } // setting the new genotype and fitness - esIndy.SetDGenotype(nX); + esIndy.SetDoubleGenotype(nX); indy.SetAge(0); double[] fit = new double[1]; fit[0] = 0; @@ -339,7 +339,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial private double[] getGenotype(AbstractEAIndividual indy) { try { - return ((InterfaceESIndividual)indy).getDGenotype(); + return ((InterfaceDataTypeDouble)indy).getDoubleData(); } catch (java.lang.ClassCastException e) { EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!"); return null; diff --git a/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java b/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java index 74477a25..099d705c 100644 --- a/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java +++ b/src/eva2/server/go/strategies/DynamicParticleSwarmOptimization.java @@ -132,11 +132,11 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization * @param best The best individual found so far. */ private void updateQuantumIndividual(int index, AbstractEAIndividual indy, Population pop) { - InterfaceESIndividual endy = (InterfaceESIndividual) indy; + InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy; // search for the local best position double[] localBestPosition; - double[] position = endy.getDGenotype(); + double[] position = endy.getDoubleData(); localBestPosition = findNeighbourhoodOptimum(index, pop); @@ -157,7 +157,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization } if (indy instanceof InterfaceDataTypeDouble) ((InterfaceDataTypeDouble)indy).SetDoubleGenotype(newPos); - else endy.SetDGenotype(newPos); + else endy.SetDoubleGenotype(newPos); resetFitness(indy); @@ -392,7 +392,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization */ protected void updateIndividual(int index, AbstractEAIndividual indy, Population pop) { if (index != detectAnchor) { // only for non anchor individuals (its -1 if other detect strategy is used) - if (indy instanceof InterfaceESIndividual) { + if (indy instanceof InterfaceDataTypeDouble) { int type=(Integer)indy.getData(partTypeKey); switch (type) { case quantumType: @@ -424,7 +424,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization // } if (doSpeedAdaptation) { - adaptTrackingSpeed(((InterfaceESIndividual)population.get(0)).getDoubleRange()); + adaptTrackingSpeed(((InterfaceDataTypeDouble)population.get(0)).getDoubleRange()); } // if (m_Problem instanceof DynLocalizationProblem) { // ((DynLocalizationProblem)m_Problem).adaptPSOByPopulation(population, this); diff --git a/src/eva2/server/go/strategies/ParticleFilterOptimization.java b/src/eva2/server/go/strategies/ParticleFilterOptimization.java index 4429fbe2..bdd95ef8 100644 --- a/src/eva2/server/go/strategies/ParticleFilterOptimization.java +++ b/src/eva2/server/go/strategies/ParticleFilterOptimization.java @@ -134,8 +134,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S indy.SetFitness(0, 0); if (this.withShow) { - InterfaceESIndividual endy = (InterfaceESIndividual) indy; - double[] curPosition = endy.getDGenotype(); + InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy; + double[] curPosition = endy.getDoubleData(); myPlot.setUnconnectedPoint(curPosition[0], curPosition[1], indCount); myPlot.setConnectedPoint(curPosition[0], curPosition[1], indCount); diff --git a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java index b7ba5d52..441d8abf 100644 --- a/src/eva2/server/go/strategies/ParticleSwarmOptimization.java +++ b/src/eva2/server/go/strategies/ParticleSwarmOptimization.java @@ -3,6 +3,10 @@ package eva2.server.go.strategies; import java.util.Arrays; import java.util.Vector; +import wsi.ra.chart2d.DPoint; +import wsi.ra.chart2d.DPointSet; +import wsi.ra.math.RNG; +import wsi.ra.math.Jama.Matrix; import eva2.gui.BeanInspector; import eva2.gui.GenericObjectEditor; import eva2.gui.TopoPlot; @@ -10,7 +14,6 @@ import eva2.server.go.InterfacePopulationChangedEventListener; import eva2.server.go.individuals.AbstractEAIndividual; import eva2.server.go.individuals.AbstractEAIndividualComparator; import eva2.server.go.individuals.InterfaceDataTypeDouble; -import eva2.server.go.individuals.InterfaceESIndividual; import eva2.server.go.operators.distancemetric.PhenotypeMetric; import eva2.server.go.populations.InterfaceSolutionSet; import eva2.server.go.populations.Population; @@ -18,15 +21,10 @@ import eva2.server.go.populations.SolutionSet; import eva2.server.go.problems.F1Problem; import eva2.server.go.problems.Interface2DBorderProblem; import eva2.server.go.problems.InterfaceOptimizationProblem; -import wsi.ra.math.RNG; import eva2.tools.EVAERROR; import eva2.tools.Mathematics; import eva2.tools.SelectedTag; -import wsi.ra.chart2d.DPoint; -import wsi.ra.chart2d.DPointSet; -import wsi.ra.math.Jama.Matrix; - /** * This implements particle swarm optimization by Kennedy and Eberhardt. @@ -174,13 +172,13 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se protected void initIndividualDefaults(AbstractEAIndividual indy) { double[] writeData; // init velocity - writeData = new double[((InterfaceESIndividual)indy).getDGenotype().length]; + writeData = new double[((InterfaceDataTypeDouble)indy).getDoubleData().length]; for (int j = 0; j < writeData.length; j++) { writeData[j] = RNG.gaussianDouble(1.0); //sum += (writeData[j])*(writeData[j]); } //sum = Math.sqrt(sum); - double relSpeed = getRelativeSpeed(writeData, ((InterfaceESIndividual)indy).getDoubleRange()); + double relSpeed = getRelativeSpeed(writeData, ((InterfaceDataTypeDouble)indy).getDoubleRange()); for (int j = 0; j < writeData.length; j++) { writeData[j] = (writeData[j]/relSpeed)*this.m_InitialVelocity; } @@ -200,7 +198,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se System.arraycopy(tmpD, 0, writeData, 0, tmpD.length); indy.SetData(partBestFitKey, writeData); // init best position - tmpD = ((InterfaceESIndividual)indy).getDGenotype(); + tmpD = ((InterfaceDataTypeDouble)indy).getDoubleData(); writeData = new double[tmpD.length]; System.arraycopy(tmpD, 0, writeData, 0, tmpD.length); indy.SetData(partBestPosKey, writeData); @@ -212,11 +210,11 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se * @param population */ protected void traceEMA(Population population) { - if (population.get(0) instanceof InterfaceESIndividual) { + if (population.get(0) instanceof InterfaceDataTypeDouble) { double[] curAvVelAndSpeed = getPopulationVelSpeed(population, 3); - double[][] range = ((InterfaceESIndividual)population.get(0)).getDoubleRange(); + double[][] range = ((InterfaceDataTypeDouble)population.get(0)).getDoubleRange(); if (tracedVelocity == null) { - tracedVelocity = new double[((InterfaceESIndividual)population.get(0)).getDGenotype().length]; + tracedVelocity = new double[((InterfaceDataTypeDouble)population.get(0)).getDoubleData().length]; for (int i=0; i