Refactored IndividualInterface and MutateXXDefault versions. DE/PSO now work on any InterfaceDataTypeDouble
This commit is contained in:
parent
0fdb7edc52
commit
9d9f507d13
@ -5,11 +5,17 @@ package eva2;
|
|||||||
*
|
*
|
||||||
* --- Changelog
|
* --- Changelog
|
||||||
* 2.030: Added an EnumEditor to access enums easily through the GUI.
|
* 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
|
* 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.
|
* 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.
|
* 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.
|
* 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.
|
* Repaired the GenericArrayEditor. Population measures can now be plotted in stats.
|
||||||
* 2.026: Added DiversityTerminator and KnownOptimaTerminator, slightly changed InterfaceTerminator for these
|
* 2.026: Added DiversityTerminator and KnownOptimaTerminator, slightly changed InterfaceTerminator for these
|
||||||
* and InterfaceStatistics to provide termination message to text window.
|
* and InterfaceStatistics to provide termination message to text window.
|
||||||
|
@ -9,20 +9,60 @@ package eva2.server.go;
|
|||||||
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
|
||||||
* $Author: mkron $
|
* $Author: mkron $
|
||||||
*/
|
*/
|
||||||
/*==========================================================================*
|
|
||||||
* IMPORTS
|
|
||||||
*==========================================================================*/
|
|
||||||
/*==========================================================================*
|
|
||||||
* INTERFACE DECLARATION
|
|
||||||
*==========================================================================*/
|
|
||||||
/**
|
/**
|
||||||
*
|
* Minimal interface for an EA individual.
|
||||||
*/
|
*/
|
||||||
public interface IndividualInterface {
|
public interface IndividualInterface {
|
||||||
|
/**
|
||||||
|
* Create a clone of the individual instance.
|
||||||
|
*
|
||||||
|
* @return a clone of the individual instance
|
||||||
|
*/
|
||||||
public IndividualInterface getClone();
|
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();
|
public double[] getFitness();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the fitness array to the given array.
|
||||||
|
*
|
||||||
|
* @param fit new fitness of the individual
|
||||||
|
*/
|
||||||
public void SetFitness (double[] fit);
|
public void SetFitness (double[] fit);
|
||||||
public double[] getDoubleArray();
|
|
||||||
public boolean isDominant(double[] otherFitness);
|
/**
|
||||||
|
* 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);
|
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();
|
||||||
}
|
}
|
@ -22,9 +22,9 @@ import eva2.tools.EVAERROR;
|
|||||||
/** This is the abstract EA individual implementing the most important methods giving
|
/** This is the abstract EA individual implementing the most important methods giving
|
||||||
* access to mutation and crossover rates and operators, fitness values and selection
|
* access to mutation and crossover rates and operators, fitness values and selection
|
||||||
* probabilities. All EA individuals should typically extend this abstract EA individual.
|
* probabilities. All EA individuals should typically extend this abstract EA individual.
|
||||||
* In that case the EA individuals only implement the genotpye and phenotype interfaces.
|
* In that case the EA individuals only implement the genotype and phenotype interfaces.
|
||||||
* The names of the implementation should be build like this:
|
* The names of the implementation should be built like this:
|
||||||
* (Genotpye)Individual(Phenotype)
|
* (Genotype)Individual(Phenotype)
|
||||||
* Thus a binary individual coding double values is named GAIndividualDoubleData and a
|
* Thus a binary individual coding double values is named GAIndividualDoubleData and a
|
||||||
* real-valued individual coding binary values is named ESIndividualBinaryData.
|
* real-valued individual coding binary values is named ESIndividualBinaryData.
|
||||||
* Created by IntelliJ IDEA.
|
* 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.
|
/** 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!
|
* return false!
|
||||||
* @param indy The individual to compare to.
|
* @param indy The individual to compare to.
|
||||||
* @return True if better false else
|
* @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.
|
/** 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!
|
* return false!
|
||||||
* @param indy The individual to compare to.
|
* @param indy The individual to compare to.
|
||||||
* @return True if better false else
|
* @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.
|
/** 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!
|
* return false!
|
||||||
* @param indy The individual to compare to.
|
* @param indy The individual to compare to.
|
||||||
* @return True if better false else
|
* @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.
|
/** 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!
|
* return false!
|
||||||
*
|
*
|
||||||
* @param indy The individual to compare to.
|
* @param indy The individual to compare to.
|
||||||
@ -889,16 +889,16 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
|
|||||||
return (IndividualInterface)this.clone();
|
return (IndividualInterface)this.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method is used to get the basic data type of an individual double[].
|
// /** 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
|
// * @deprecated Since not all EAIndividuals provide double as basic data type
|
||||||
* the fitness can be is returned as default value.
|
// * the fitness can be is returned as default value.
|
||||||
* @see #getFitness()
|
// * @see #getFitness()
|
||||||
* @return double[]
|
// * @return double[]
|
||||||
*/
|
// */
|
||||||
public double[] getDoubleArray() {
|
// public double[] getDoubleArray() {
|
||||||
if (this instanceof InterfaceDataTypeDouble) return ((InterfaceDataTypeDouble)this).getDoubleData();
|
// if (this instanceof InterfaceDataTypeDouble) return ((InterfaceDataTypeDouble)this).getDoubleData();
|
||||||
else return this.getFitness();
|
// else return this.getFitness();
|
||||||
}
|
// }
|
||||||
|
|
||||||
public boolean isDominantNotEqual(double[] otherFitness) {
|
public boolean isDominantNotEqual(double[] otherFitness) {
|
||||||
return isDominatingFitnessNotEqual(m_Fitness, otherFitness);
|
return isDominatingFitnessNotEqual(m_Fitness, otherFitness);
|
||||||
|
@ -257,18 +257,13 @@ public class ESIndividualBinaryData extends AbstractEAIndividual implements Inte
|
|||||||
/** This method performs a simple one element mutation on the double vector
|
/** This method performs a simple one element mutation on the double vector
|
||||||
*/
|
*/
|
||||||
public void defaultMutate() {
|
public void defaultMutate() {
|
||||||
int mutationIndex = RNG.randomInt(0, this.m_Genotype.length-1);
|
ESIndividualDoubleData.defaultMutate(m_Genotype, m_Range);
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method initializes the double vector
|
/** This method initializes the double vector
|
||||||
*/
|
*/
|
||||||
public void defaultInit() {
|
public void defaultInit() {
|
||||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
|
||||||
this.m_Genotype[i] = RNG.randomDouble(this.m_Range[i][0], this.m_Range[i][1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**********************************************************************************************************************
|
/**********************************************************************************************************************
|
||||||
* These are for GUI
|
* These are for GUI
|
||||||
|
@ -275,17 +275,40 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
|
|||||||
/** This method performs a simple one element mutation on the double vector
|
/** This method performs a simple one element mutation on the double vector
|
||||||
*/
|
*/
|
||||||
public void defaultMutate() {
|
public void defaultMutate() {
|
||||||
int mutationIndex = RNG.randomInt(0, this.m_Genotype.length-1);
|
ESIndividualDoubleData.defaultMutate(this.m_Genotype, this.m_Range);
|
||||||
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];
|
/**
|
||||||
|
* 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
|
/** This method initializes the double vector
|
||||||
*/
|
*/
|
||||||
public void defaultInit() {
|
public void defaultInit() {
|
||||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
|
||||||
this.m_Genotype[i] = RNG.randomDouble(this.m_Range[i][0], this.m_Range[i][1]);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ import eva2.server.go.operators.mutation.MutateESGlobal;
|
|||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
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.
|
* the sorting of the real-valued genotype gives the permutation.
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
* User: streiche
|
* 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() {
|
public void defaultMutate() {
|
||||||
for (int i = 0; i < m_Genotype.length; i++) {
|
for (int i = 0; i < m_Genotype.length; i++) {
|
||||||
int mutationIndex = RNG.randomInt(0, this.m_Genotype[i].length-1);
|
ESIndividualDoubleData.defaultMutate(m_Genotype[i], m_Range[i]);
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* This method initializes the double vector
|
||||||
/** This method initializes the double vector
|
|
||||||
*/
|
*/
|
||||||
public void defaultInit() {
|
public void defaultInit() {
|
||||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||||
for (int j = 0; j < this.m_Genotype[i].length; j++) {
|
ESIndividualDoubleData.defaultInit(m_Genotype[i], m_Range[i]);
|
||||||
this.m_Genotype[i][j] = RNG.randomDouble(this.m_Range[i][j][0], this.m_Range[i][j][1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,11 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
|||||||
((AbstractEAIndividual)this.m_BitSet).init(opt);
|
((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
|
/** This method will init the individual with a given value for the
|
||||||
* phenotype.
|
* phenotype.
|
||||||
* @param obj The initial value for the phenotype
|
* @param obj The initial value for the phenotype
|
||||||
@ -103,6 +108,11 @@ public class GAESIndividualBinaryDoubleData extends AbstractEAIndividual impleme
|
|||||||
if (RNG.flipCoin(this.m_MutationProbability))((AbstractEAIndividual)this.m_BitSet).mutate();
|
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
|
/** This method will mate the Individual with given other individuals
|
||||||
* of the same type.
|
* of the same type.
|
||||||
* @param partners The possible partners
|
* @param partners The possible partners
|
||||||
|
@ -3,16 +3,11 @@ package eva2.server.go.individuals;
|
|||||||
|
|
||||||
import java.util.BitSet;
|
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 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.
|
/** This individual uses a binary genotype to code for binary values.
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
|
@ -3,16 +3,13 @@ package eva2.server.go.individuals;
|
|||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
import wsi.ra.math.RNG;
|
||||||
import eva2.server.go.individuals.codings.ga.GAStandardCodingDouble;
|
import eva2.server.go.individuals.codings.ga.GAStandardCodingDouble;
|
||||||
import eva2.server.go.individuals.codings.ga.InterfaceGADoubleCoding;
|
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.CrossoverGANPoint;
|
||||||
import eva2.server.go.operators.crossover.InterfaceCrossover;
|
|
||||||
import eva2.server.go.operators.mutation.InterfaceMutation;
|
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.MutateGAStandard;
|
||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
|
||||||
|
|
||||||
/** This individual uses a binary genotype to code for double values
|
/** This individual uses a binary genotype to code for double values
|
||||||
* using two alternative encodings.
|
* using two alternative encodings.
|
||||||
|
@ -1,20 +1,11 @@
|
|||||||
package eva2.server.go.individuals;
|
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.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.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.populations.Population;
|
||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
|
||||||
|
|
||||||
/** This individual combines a real-valued phenotype with a tree-based phenotype.
|
/** This individual combines a real-valued phenotype with a tree-based phenotype.
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
@ -83,6 +74,11 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
|||||||
((AbstractEAIndividual)this.m_Program).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
|
/** This method will init the individual with a given value for the
|
||||||
* phenotype.
|
* phenotype.
|
||||||
* @param obj The initial value for the phenotype
|
* @param obj The initial value for the phenotype
|
||||||
@ -111,6 +107,11 @@ public class GAPIndividualProgramData extends AbstractEAIndividual implements In
|
|||||||
if (RNG.flipCoin(this.m_MutationProbability))((AbstractEAIndividual)this.m_Program).mutate();
|
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
|
/** This method will mate the Individual with given other individuals
|
||||||
* of the same type.
|
* of the same type.
|
||||||
* @param partners The possible partners
|
* @param partners The possible partners
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package eva2.server.go.individuals;
|
package eva2.server.go.individuals;
|
||||||
|
|
||||||
|
|
||||||
import java.util.BitSet;
|
|
||||||
import java.util.ArrayList;
|
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.AbstractGPNode;
|
||||||
import eva2.server.go.individuals.codings.gp.GPArea;
|
import eva2.server.go.individuals.codings.gp.GPArea;
|
||||||
import eva2.server.go.individuals.codings.gp.InterfaceProgram;
|
import eva2.server.go.individuals.codings.gp.InterfaceProgram;
|
||||||
import eva2.server.go.operators.crossover.CrossoverGADefault;
|
import eva2.server.go.operators.crossover.CrossoverGADefault;
|
||||||
import eva2.server.go.operators.mutation.InterfaceMutation;
|
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 eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
|
||||||
|
|
||||||
/** This individual uses a binary genotype to code for a tree-based representation
|
/** This individual uses a binary genotype to code for a tree-based representation
|
||||||
* using a BNF grammar, see also Grammatical Evolution.
|
* 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_Area = new GPArea[1];
|
||||||
this.m_GenotypeLengthPerProgram = 240;
|
this.m_GenotypeLengthPerProgram = 240;
|
||||||
this.m_Genotype = new BitSet();
|
this.m_Genotype = new BitSet();
|
||||||
this.m_MutationOperator = new MutateGADefault();
|
this.m_MutationOperator = new MutateDefault();
|
||||||
this.m_CrossoverOperator = new CrossoverGADefault();
|
this.m_CrossoverOperator = new CrossoverGADefault();
|
||||||
this.m_MutationProbability = 0.5;
|
this.m_MutationProbability = 0.5;
|
||||||
this.m_CrossoverProbability = 0.5;
|
this.m_CrossoverProbability = 0.5;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package eva2.server.go.individuals;
|
package eva2.server.go.individuals;
|
||||||
|
|
||||||
|
import wsi.ra.math.RNG;
|
||||||
import eva2.server.go.operators.crossover.CrossoverGIDefault;
|
import eva2.server.go.operators.crossover.CrossoverGIDefault;
|
||||||
import eva2.server.go.operators.mutation.InterfaceMutation;
|
import eva2.server.go.operators.mutation.InterfaceMutation;
|
||||||
import eva2.server.go.operators.mutation.MutateGIDefault;
|
import eva2.server.go.operators.mutation.MutateDefault;
|
||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
|
||||||
|
|
||||||
/** This individual uses a integer genotype to code for integer values.
|
/** This individual uses a integer genotype to code for integer values.
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
@ -21,7 +21,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
|||||||
|
|
||||||
public GIIndividualIntegerData() {
|
public GIIndividualIntegerData() {
|
||||||
this.m_MutationProbability = 0.1;
|
this.m_MutationProbability = 0.1;
|
||||||
this.m_MutationOperator = new MutateGIDefault();
|
this.m_MutationOperator = new MutateDefault();
|
||||||
this.m_CrossoverProbability = 0.7;
|
this.m_CrossoverProbability = 0.7;
|
||||||
this.m_CrossoverOperator = new CrossoverGIDefault();
|
this.m_CrossoverOperator = new CrossoverGIDefault();
|
||||||
this.m_Range = new int[10][2];
|
this.m_Range = new int[10][2];
|
||||||
|
@ -75,6 +75,11 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
|||||||
((AbstractEAIndividual)this.m_Permutation).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
|
/** This method will init the individual with a given value for the
|
||||||
* phenotype.
|
* phenotype.
|
||||||
* @param obj The initial value for the phenotype
|
* @param obj The initial value for the phenotype
|
||||||
@ -103,6 +108,11 @@ public class GIOBGAIndividualIntegerPermutationData extends AbstractEAIndividual
|
|||||||
if (RNG.flipCoin(this.m_MutationProbability))((AbstractEAIndividual)this.m_Permutation).mutate();
|
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
|
/** This method will mate the Individual with given other individuals
|
||||||
* of the same type.
|
* of the same type.
|
||||||
* @param partners The possible partners
|
* @param partners The possible partners
|
||||||
|
@ -3,16 +3,15 @@ package eva2.server.go.individuals;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import wsi.ra.math.RNG;
|
||||||
import eva2.server.go.individuals.codings.gp.AbstractGPNode;
|
import eva2.server.go.individuals.codings.gp.AbstractGPNode;
|
||||||
import eva2.server.go.individuals.codings.gp.GPArea;
|
import eva2.server.go.individuals.codings.gp.GPArea;
|
||||||
import eva2.server.go.individuals.codings.gp.InterfaceProgram;
|
import eva2.server.go.individuals.codings.gp.InterfaceProgram;
|
||||||
import eva2.server.go.operators.crossover.CrossoverGPDefault;
|
import eva2.server.go.operators.crossover.CrossoverGPDefault;
|
||||||
import eva2.server.go.operators.mutation.InterfaceMutation;
|
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 eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
import eva2.tools.EVAHELP;
|
|
||||||
|
|
||||||
/** This individual uses a tree-based genotype to code for program trees.
|
/** This individual uses a tree-based genotype to code for program trees.
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
@ -35,7 +34,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
this.m_Area = new GPArea[1];
|
this.m_Area = new GPArea[1];
|
||||||
m_Area[0] = new GPArea();
|
m_Area[0] = new GPArea();
|
||||||
this.m_Genotype = new AbstractGPNode[1];
|
this.m_Genotype = new AbstractGPNode[1];
|
||||||
this.m_MutationOperator = new MutateGPDefault();
|
this.m_MutationOperator = new MutateDefault();
|
||||||
this.m_CrossoverOperator = new CrossoverGPDefault();
|
this.m_CrossoverOperator = new CrossoverGPDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,11 +33,4 @@ public interface InterfaceESIndividual {
|
|||||||
*/
|
*/
|
||||||
public double[][] getDoubleRange();
|
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();
|
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,4 @@ public interface InterfaceGAIndividual {
|
|||||||
*/
|
*/
|
||||||
public int getGenotypeLength();
|
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();
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package eva2.server.go.individuals;
|
package eva2.server.go.individuals;
|
||||||
|
|
||||||
import java.util.BitSet;
|
|
||||||
|
|
||||||
/** This interface gives access to a integer genotype and should
|
/** This interface gives access to a integer genotype and should
|
||||||
* only be used by mutation and crossover operators.
|
* only be used by mutation and crossover operators.
|
||||||
@ -48,12 +47,4 @@ public interface InterfaceGIIndividual {
|
|||||||
* @return The length of the genotype.
|
* @return The length of the genotype.
|
||||||
*/
|
*/
|
||||||
public int getGenotypeLength();
|
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();
|
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,4 @@ public interface InterfaceGPIndividual {
|
|||||||
*/
|
*/
|
||||||
public Object[] getFunctionArea();
|
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();
|
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,4 @@ public interface InterfaceOBGAIndividual {
|
|||||||
* @param b int[] new genotype
|
* @param b int[] new genotype
|
||||||
*/
|
*/
|
||||||
public void SetOBGenotype(int[][] b);
|
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();
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import java.util.BitSet;
|
|||||||
public interface InterfaceGADoubleCoding {
|
public interface InterfaceGADoubleCoding {
|
||||||
/** This method decodes a part of a given BitSet into a double value. This method may change the contens
|
/** 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.
|
* 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 refBitSet The BitSet where the questioned value is stored.
|
||||||
* @param range The allowed range of the value.
|
* @param range The allowed range of the value.
|
||||||
* @param locus The position and length on the BitSet that is to be decoded.
|
* @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);
|
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 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 value The value to be coded.
|
||||||
* @param range The allowed range of the value.
|
* @param range The allowed range of the value.
|
||||||
* @param refBitSet The BitSet where the questioned value is stored.
|
* @param refBitSet The BitSet where the questioned value is stored.
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
package eva2.server.go.operators.mutation;
|
package eva2.server.go.operators.mutation;
|
||||||
|
|
||||||
|
import eva2.server.go.IndividualInterface;
|
||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
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.populations.Population;
|
||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* Mutate individuals using the default operator implemented by the individuals themselves.
|
||||||
* User: streiche
|
*
|
||||||
* Date: 18.05.2005
|
|
||||||
* Time: 17:08:49
|
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
*/
|
||||||
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
|
/** This method will enable you to clone a given mutation operator
|
||||||
* @return The clone
|
* @return The clone
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new MutateGIDefault();
|
return new MutateDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to evaluate wether two mutation operators
|
/** 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
|
* @param mutator The other mutation operator
|
||||||
*/
|
*/
|
||||||
public boolean equals(Object mutator) {
|
public boolean equals(Object mutator) {
|
||||||
if (mutator instanceof MutateGIDefault) return true;
|
if (mutator instanceof MutateDefault) return true;
|
||||||
else return false;
|
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
|
/** This method allows you to perform either crossover on the strategy parameters
|
||||||
* or to deal in some other way with the crossover event.
|
* or to deal in some other way with the crossover event.
|
||||||
* @param indy1 The original mother
|
* @param indy1 The original mother
|
||||||
@ -47,20 +54,12 @@ public class MutateGIDefault implements InterfaceMutation, java.io.Serializable
|
|||||||
// nothing to do here
|
// 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
|
/** This method allows you to get a string representation of the mutation
|
||||||
* operator
|
* operator
|
||||||
* @return A descriptive string.
|
* @return A descriptive string.
|
||||||
*/
|
*/
|
||||||
public String getStringRepresentation() {
|
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.
|
* @return The name.
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "GI default mutation";
|
return "Default mutation";
|
||||||
}
|
}
|
||||||
/** This method returns a global info string
|
/** This method returns a global info string
|
||||||
* @return description
|
* @return description
|
||||||
*/
|
*/
|
||||||
public String globalInfo() {
|
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.";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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.";
|
|
||||||
}
|
|
||||||
}
|
|
@ -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.";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +1,12 @@
|
|||||||
package eva2.server.go.operators.mutation;
|
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.AbstractEAIndividual;
|
||||||
import eva2.server.go.individuals.InterfaceGAIndividual;
|
|
||||||
import eva2.server.go.individuals.InterfaceGPIndividual;
|
import eva2.server.go.individuals.InterfaceGPIndividual;
|
||||||
import eva2.server.go.populations.Population;
|
import eva2.server.go.populations.Population;
|
||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* 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));
|
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 < this.m_LowerLimitStepSize) this.m_MutationStep = this.m_LowerLimitStepSize;
|
||||||
if (this.m_MutationStep > 1) this.m_MutationStep = 1;
|
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());
|
//System.out.println("After Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor());
|
||||||
}
|
}
|
||||||
|
@ -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.";
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,7 @@ import wsi.ra.math.RNG;
|
|||||||
import eva2.gui.GenericObjectEditor;
|
import eva2.gui.GenericObjectEditor;
|
||||||
import eva2.server.go.InterfacePopulationChangedEventListener;
|
import eva2.server.go.InterfacePopulationChangedEventListener;
|
||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
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.operators.selection.replacement.ReplacementCrowding;
|
||||||
import eva2.server.go.populations.InterfaceSolutionSet;
|
import eva2.server.go.populations.InterfaceSolutionSet;
|
||||||
import eva2.server.go.populations.Population;
|
import eva2.server.go.populations.Population;
|
||||||
@ -166,11 +166,11 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
|||||||
* @param indy The current individual
|
* @param indy The current individual
|
||||||
* @return the delta vector
|
* @return the delta vector
|
||||||
*/
|
*/
|
||||||
private double[] fetchDeltaBest(Population pop, InterfaceESIndividual indy) {
|
private double[] fetchDeltaBest(Population pop, InterfaceDataTypeDouble indy) {
|
||||||
double[] x1, result;
|
double[] x1, result;
|
||||||
AbstractEAIndividual xbIndy;
|
AbstractEAIndividual xbIndy;
|
||||||
|
|
||||||
x1 = indy.getDGenotype();
|
x1 = indy.getDoubleData();
|
||||||
result = new double[x1.length];
|
result = new double[x1.length];
|
||||||
if (m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) {
|
if (m_Problem instanceof AbstractMultiObjectiveOptimizationProblem) {
|
||||||
// implements MODE for the multi-objective case: a dominating individual is selected for difference building
|
// 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) {
|
public AbstractEAIndividual generateNewIndividual(Population pop) {
|
||||||
int firstParentIndex;
|
int firstParentIndex;
|
||||||
AbstractEAIndividual indy;
|
AbstractEAIndividual indy;
|
||||||
InterfaceESIndividual esIndy;
|
InterfaceDataTypeDouble esIndy;
|
||||||
if (doLogParents) parents = new Vector<AbstractEAIndividual>();
|
if (doLogParents) parents = new Vector<AbstractEAIndividual>();
|
||||||
else parents = null;
|
else parents = null;
|
||||||
try {
|
try {
|
||||||
// select one random indy as starting individual. its a parent in any case.
|
// select one random indy as starting individual. its a parent in any case.
|
||||||
firstParentIndex = RNG.randomInt(0, pop.size()-1);
|
firstParentIndex = RNG.randomInt(0, pop.size()-1);
|
||||||
indy = (AbstractEAIndividual)(pop.getEAIndividual(firstParentIndex)).getClone();
|
indy = (AbstractEAIndividual)(pop.getEAIndividual(firstParentIndex)).getClone();
|
||||||
esIndy = (InterfaceESIndividual)indy;
|
esIndy = (InterfaceDataTypeDouble)indy;
|
||||||
} catch (java.lang.ClassCastException e) {
|
} catch (java.lang.ClassCastException e) {
|
||||||
System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
|
System.err.println("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
|
||||||
return (AbstractEAIndividual)((AbstractEAIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getClone();
|
return (AbstractEAIndividual)((AbstractEAIndividual)pop.get(RNG.randomInt(0, pop.size()-1))).getClone();
|
||||||
}
|
}
|
||||||
double[] nX, vX, oX;
|
double[] nX, vX, oX;
|
||||||
oX = esIndy.getDGenotype();
|
oX = esIndy.getDoubleData();
|
||||||
vX = esIndy.getDGenotype();
|
vX = esIndy.getDoubleData();
|
||||||
nX = new double[oX.length];
|
nX = new double[oX.length];
|
||||||
switch (this.m_DEType.getSelectedTag().getID()) {
|
switch (this.m_DEType.getSelectedTag().getID()) {
|
||||||
case 0 : {
|
case 0 : {
|
||||||
@ -274,11 +274,11 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
|||||||
if (RNG.flipCoin(this.m_Mt)) {
|
if (RNG.flipCoin(this.m_Mt)) {
|
||||||
double[] xk, xl;
|
double[] xk, xl;
|
||||||
double p, pj, pk, pl;
|
double p, pj, pk, pl;
|
||||||
InterfaceESIndividual indy1 = null, indy2 = null;
|
InterfaceDataTypeDouble indy1 = null, indy2 = null;
|
||||||
try {
|
try {
|
||||||
// and i got indy!
|
// and i got indy!
|
||||||
indy1 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1));
|
indy1 = (InterfaceDataTypeDouble)pop.get(RNG.randomInt(0, pop.size()-1));
|
||||||
indy2 = (InterfaceESIndividual)pop.get(RNG.randomInt(0, pop.size()-1));
|
indy2 = (InterfaceDataTypeDouble)pop.get(RNG.randomInt(0, pop.size()-1));
|
||||||
if (parents != null) {
|
if (parents != null) {
|
||||||
parents.add((AbstractEAIndividual)indy1);
|
parents.add((AbstractEAIndividual)indy1);
|
||||||
parents.add((AbstractEAIndividual)indy2);
|
parents.add((AbstractEAIndividual)indy2);
|
||||||
@ -286,8 +286,8 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
|||||||
} catch (java.lang.ClassCastException e) {
|
} catch (java.lang.ClassCastException e) {
|
||||||
EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
|
EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
|
||||||
}
|
}
|
||||||
xk = indy1.getDGenotype();
|
xk = indy1.getDoubleData();
|
||||||
xl = indy2.getDGenotype();
|
xl = indy2.getDoubleData();
|
||||||
p = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy1).getFitness(0)) + Math.abs(((AbstractEAIndividual)indy2).getFitness(0));
|
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;
|
pj = Math.abs(((AbstractEAIndividual)esIndy).getFitness(0))/p;
|
||||||
pk = Math.abs(((AbstractEAIndividual)indy1).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
|
// setting the new genotype and fitness
|
||||||
esIndy.SetDGenotype(nX);
|
esIndy.SetDoubleGenotype(nX);
|
||||||
indy.SetAge(0);
|
indy.SetAge(0);
|
||||||
double[] fit = new double[1];
|
double[] fit = new double[1];
|
||||||
fit[0] = 0;
|
fit[0] = 0;
|
||||||
@ -339,7 +339,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
|
|||||||
|
|
||||||
private double[] getGenotype(AbstractEAIndividual indy) {
|
private double[] getGenotype(AbstractEAIndividual indy) {
|
||||||
try {
|
try {
|
||||||
return ((InterfaceESIndividual)indy).getDGenotype();
|
return ((InterfaceDataTypeDouble)indy).getDoubleData();
|
||||||
} catch (java.lang.ClassCastException e) {
|
} catch (java.lang.ClassCastException e) {
|
||||||
EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
|
EVAERROR.errorMsgOnce("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
|
||||||
return null;
|
return null;
|
||||||
|
@ -132,11 +132,11 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
|||||||
* @param best The best individual found so far.
|
* @param best The best individual found so far.
|
||||||
*/
|
*/
|
||||||
private void updateQuantumIndividual(int index, AbstractEAIndividual indy, Population pop) {
|
private void updateQuantumIndividual(int index, AbstractEAIndividual indy, Population pop) {
|
||||||
InterfaceESIndividual endy = (InterfaceESIndividual) indy;
|
InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy;
|
||||||
// search for the local best position
|
// search for the local best position
|
||||||
|
|
||||||
double[] localBestPosition;
|
double[] localBestPosition;
|
||||||
double[] position = endy.getDGenotype();
|
double[] position = endy.getDoubleData();
|
||||||
|
|
||||||
localBestPosition = findNeighbourhoodOptimum(index, pop);
|
localBestPosition = findNeighbourhoodOptimum(index, pop);
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (indy instanceof InterfaceDataTypeDouble) ((InterfaceDataTypeDouble)indy).SetDoubleGenotype(newPos);
|
if (indy instanceof InterfaceDataTypeDouble) ((InterfaceDataTypeDouble)indy).SetDoubleGenotype(newPos);
|
||||||
else endy.SetDGenotype(newPos);
|
else endy.SetDoubleGenotype(newPos);
|
||||||
|
|
||||||
resetFitness(indy);
|
resetFitness(indy);
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
|||||||
*/
|
*/
|
||||||
protected void updateIndividual(int index, AbstractEAIndividual indy, Population pop) {
|
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 (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);
|
int type=(Integer)indy.getData(partTypeKey);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case quantumType:
|
case quantumType:
|
||||||
@ -424,7 +424,7 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (doSpeedAdaptation) {
|
if (doSpeedAdaptation) {
|
||||||
adaptTrackingSpeed(((InterfaceESIndividual)population.get(0)).getDoubleRange());
|
adaptTrackingSpeed(((InterfaceDataTypeDouble)population.get(0)).getDoubleRange());
|
||||||
}
|
}
|
||||||
// if (m_Problem instanceof DynLocalizationProblem) {
|
// if (m_Problem instanceof DynLocalizationProblem) {
|
||||||
// ((DynLocalizationProblem)m_Problem).adaptPSOByPopulation(population, this);
|
// ((DynLocalizationProblem)m_Problem).adaptPSOByPopulation(population, this);
|
||||||
|
@ -134,8 +134,8 @@ public class ParticleFilterOptimization implements InterfaceOptimizer, java.io.S
|
|||||||
indy.SetFitness(0, 0);
|
indy.SetFitness(0, 0);
|
||||||
|
|
||||||
if (this.withShow) {
|
if (this.withShow) {
|
||||||
InterfaceESIndividual endy = (InterfaceESIndividual) indy;
|
InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy;
|
||||||
double[] curPosition = endy.getDGenotype();
|
double[] curPosition = endy.getDoubleData();
|
||||||
|
|
||||||
myPlot.setUnconnectedPoint(curPosition[0], curPosition[1], indCount);
|
myPlot.setUnconnectedPoint(curPosition[0], curPosition[1], indCount);
|
||||||
myPlot.setConnectedPoint(curPosition[0], curPosition[1], indCount);
|
myPlot.setConnectedPoint(curPosition[0], curPosition[1], indCount);
|
||||||
|
@ -3,6 +3,10 @@ package eva2.server.go.strategies;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Vector;
|
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.BeanInspector;
|
||||||
import eva2.gui.GenericObjectEditor;
|
import eva2.gui.GenericObjectEditor;
|
||||||
import eva2.gui.TopoPlot;
|
import eva2.gui.TopoPlot;
|
||||||
@ -10,7 +14,6 @@ import eva2.server.go.InterfacePopulationChangedEventListener;
|
|||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||||
import eva2.server.go.individuals.AbstractEAIndividualComparator;
|
import eva2.server.go.individuals.AbstractEAIndividualComparator;
|
||||||
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
import eva2.server.go.individuals.InterfaceESIndividual;
|
|
||||||
import eva2.server.go.operators.distancemetric.PhenotypeMetric;
|
import eva2.server.go.operators.distancemetric.PhenotypeMetric;
|
||||||
import eva2.server.go.populations.InterfaceSolutionSet;
|
import eva2.server.go.populations.InterfaceSolutionSet;
|
||||||
import eva2.server.go.populations.Population;
|
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.F1Problem;
|
||||||
import eva2.server.go.problems.Interface2DBorderProblem;
|
import eva2.server.go.problems.Interface2DBorderProblem;
|
||||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
import eva2.server.go.problems.InterfaceOptimizationProblem;
|
||||||
import wsi.ra.math.RNG;
|
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
import eva2.tools.Mathematics;
|
import eva2.tools.Mathematics;
|
||||||
import eva2.tools.SelectedTag;
|
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.
|
* 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) {
|
protected void initIndividualDefaults(AbstractEAIndividual indy) {
|
||||||
double[] writeData;
|
double[] writeData;
|
||||||
// init velocity
|
// init velocity
|
||||||
writeData = new double[((InterfaceESIndividual)indy).getDGenotype().length];
|
writeData = new double[((InterfaceDataTypeDouble)indy).getDoubleData().length];
|
||||||
for (int j = 0; j < writeData.length; j++) {
|
for (int j = 0; j < writeData.length; j++) {
|
||||||
writeData[j] = RNG.gaussianDouble(1.0);
|
writeData[j] = RNG.gaussianDouble(1.0);
|
||||||
//sum += (writeData[j])*(writeData[j]);
|
//sum += (writeData[j])*(writeData[j]);
|
||||||
}
|
}
|
||||||
//sum = Math.sqrt(sum);
|
//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++) {
|
for (int j = 0; j < writeData.length; j++) {
|
||||||
writeData[j] = (writeData[j]/relSpeed)*this.m_InitialVelocity;
|
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);
|
System.arraycopy(tmpD, 0, writeData, 0, tmpD.length);
|
||||||
indy.SetData(partBestFitKey, writeData);
|
indy.SetData(partBestFitKey, writeData);
|
||||||
// init best position
|
// init best position
|
||||||
tmpD = ((InterfaceESIndividual)indy).getDGenotype();
|
tmpD = ((InterfaceDataTypeDouble)indy).getDoubleData();
|
||||||
writeData = new double[tmpD.length];
|
writeData = new double[tmpD.length];
|
||||||
System.arraycopy(tmpD, 0, writeData, 0, tmpD.length);
|
System.arraycopy(tmpD, 0, writeData, 0, tmpD.length);
|
||||||
indy.SetData(partBestPosKey, writeData);
|
indy.SetData(partBestPosKey, writeData);
|
||||||
@ -212,11 +210,11 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
* @param population
|
* @param population
|
||||||
*/
|
*/
|
||||||
protected void traceEMA(Population population) {
|
protected void traceEMA(Population population) {
|
||||||
if (population.get(0) instanceof InterfaceESIndividual) {
|
if (population.get(0) instanceof InterfaceDataTypeDouble) {
|
||||||
double[] curAvVelAndSpeed = getPopulationVelSpeed(population, 3);
|
double[] curAvVelAndSpeed = getPopulationVelSpeed(population, 3);
|
||||||
double[][] range = ((InterfaceESIndividual)population.get(0)).getDoubleRange();
|
double[][] range = ((InterfaceDataTypeDouble)population.get(0)).getDoubleRange();
|
||||||
if (tracedVelocity == null) {
|
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<tracedVelocity.length; i++) tracedVelocity[i] = curAvVelAndSpeed[i];
|
for (int i=0; i<tracedVelocity.length; i++) tracedVelocity[i] = curAvVelAndSpeed[i];
|
||||||
} else {
|
} else {
|
||||||
if (population.getGeneration() < emaPeriods) {// if less than emaPeriods have passed, use larger alpha
|
if (population.getGeneration() < emaPeriods) {// if less than emaPeriods have passed, use larger alpha
|
||||||
@ -256,10 +254,10 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
*/
|
*/
|
||||||
private double[] getPopulationVelSpeed(Population pop, int calcModeSwitch) {
|
private double[] getPopulationVelSpeed(Population pop, int calcModeSwitch) {
|
||||||
AbstractEAIndividual indy = (AbstractEAIndividual)pop.get(0);
|
AbstractEAIndividual indy = (AbstractEAIndividual)pop.get(0);
|
||||||
if (!(indy instanceof InterfaceESIndividual)) System.out.println("error, PSO needs ES individuals!");
|
if (!(indy instanceof InterfaceDataTypeDouble)) System.out.println("error, PSO needs individuals with double data!");
|
||||||
|
|
||||||
double[] ret;
|
double[] ret;
|
||||||
double[][] range = ((InterfaceESIndividual)indy).getDoubleRange();
|
double[][] range = ((InterfaceDataTypeDouble)indy).getDoubleRange();
|
||||||
int retSize = 0;
|
int retSize = 0;
|
||||||
///// warning, this method uses dark magic
|
///// warning, this method uses dark magic
|
||||||
|
|
||||||
@ -368,7 +366,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
// double sum;
|
// double sum;
|
||||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||||
indy = (AbstractEAIndividual) this.m_Population.get(i);
|
indy = (AbstractEAIndividual) this.m_Population.get(i);
|
||||||
if (indy instanceof InterfaceESIndividual) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
initIndividualDefaults(indy);
|
initIndividualDefaults(indy);
|
||||||
}
|
}
|
||||||
indy.SetData(indexKey, i);
|
indy.SetData(indexKey, i);
|
||||||
@ -378,12 +376,13 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
|
|
||||||
for (int i = 0; i < this.m_Population.size(); i++) {
|
for (int i = 0; i < this.m_Population.size(); i++) {
|
||||||
indy = (AbstractEAIndividual) this.m_Population.get(i);
|
indy = (AbstractEAIndividual) this.m_Population.get(i);
|
||||||
if (indy instanceof InterfaceESIndividual) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
initIndividualMemory(indy);
|
initIndividualMemory(indy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
|
this.m_BestIndividual = (AbstractEAIndividual)this.m_Population.getBestEAIndividual().clone();
|
||||||
|
|
||||||
if (reset) this.firePropertyChangedEvent("NextGenerationPerformed");
|
if (reset) this.firePropertyChangedEvent("NextGenerationPerformed");
|
||||||
|
|
||||||
treeLevels = 0;
|
treeLevels = 0;
|
||||||
@ -438,7 +437,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
neighbourPos = (double[])neighbourIndy.getData(partBestPosKey);
|
neighbourPos = (double[])neighbourIndy.getData(partBestPosKey);
|
||||||
} else {
|
} else {
|
||||||
neighbourFit = neighbourIndy.getFitness();
|
neighbourFit = neighbourIndy.getFitness();
|
||||||
neighbourPos = ((InterfaceESIndividual)neighbourIndy).getDGenotype();
|
neighbourPos = ((InterfaceDataTypeDouble)neighbourIndy).getDoubleData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (neighbourFit == null || attractorFit == null) {
|
if (neighbourFit == null || attractorFit == null) {
|
||||||
@ -453,15 +452,14 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void resetIndividual(AbstractEAIndividual indy) {
|
protected void resetIndividual(AbstractEAIndividual indy) {
|
||||||
if (indy instanceof InterfaceESIndividual) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
indy.setParents(null);
|
indy.setParents(null);
|
||||||
InterfaceESIndividual endy = (InterfaceESIndividual) indy;
|
indy.defaultInit();
|
||||||
endy.defaultInit();
|
|
||||||
indy.SetData(partTypeKey, defaultType); // turn into default type
|
indy.SetData(partTypeKey, defaultType); // turn into default type
|
||||||
initIndividualDefaults(indy);
|
initIndividualDefaults(indy);
|
||||||
initIndividualMemory(indy);
|
initIndividualMemory(indy);
|
||||||
plotIndy(endy.getDGenotype(), null, (Integer)indy.getData(indexKey));
|
plotIndy(((InterfaceDataTypeDouble)indy).getDoubleData(), null, (Integer)indy.getData(indexKey));
|
||||||
} else System.err.println("error, InterfaceESIndividual required (PSO)");
|
} else System.err.println("error, double valued individuals required for PSO");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will update a given individual
|
/** This method will update a given individual
|
||||||
@ -471,7 +469,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
* @param best The best individual found so far.
|
* @param best The best individual found so far.
|
||||||
*/
|
*/
|
||||||
protected void updateIndividual(int index, AbstractEAIndividual indy, Population pop) {
|
protected void updateIndividual(int index, AbstractEAIndividual indy, Population pop) {
|
||||||
if (indy instanceof InterfaceESIndividual) {
|
if (indy instanceof InterfaceDataTypeDouble) {
|
||||||
int type=(Integer)indy.getData(partTypeKey);
|
int type=(Integer)indy.getData(partTypeKey);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case resetType:
|
case resetType:
|
||||||
@ -488,13 +486,13 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void defaultIndividualUpdate(int index, AbstractEAIndividual indy, Population pop) {
|
protected void defaultIndividualUpdate(int index, AbstractEAIndividual indy, Population pop) {
|
||||||
InterfaceESIndividual endy = (InterfaceESIndividual) indy;
|
InterfaceDataTypeDouble endy = (InterfaceDataTypeDouble) indy;
|
||||||
|
|
||||||
indy.SetData(partTypeKey, defaultType);
|
indy.SetData(partTypeKey, defaultType);
|
||||||
// default update
|
// default update
|
||||||
double[] personalBestPos = (double[]) indy.getData(partBestPosKey);
|
double[] personalBestPos = (double[]) indy.getData(partBestPosKey);
|
||||||
double[] velocity = (double[]) indy.getData(partVelKey);
|
double[] velocity = (double[]) indy.getData(partVelKey);
|
||||||
double[] curPosition = endy.getDGenotype();
|
double[] curPosition = endy.getDoubleData();
|
||||||
double[][] range = endy.getDoubleRange();
|
double[][] range = endy.getDoubleRange();
|
||||||
|
|
||||||
// search for the local best position
|
// search for the local best position
|
||||||
@ -583,7 +581,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
*/
|
*/
|
||||||
protected void updateIndProps(AbstractEAIndividual indy) {
|
protected void updateIndProps(AbstractEAIndividual indy) {
|
||||||
indy.SetData(partBestFitKey, indy.getFitness());
|
indy.SetData(partBestFitKey, indy.getFitness());
|
||||||
indy.SetData(partBestPosKey, ((InterfaceESIndividual)indy).getDGenotype());
|
indy.SetData(partBestPosKey, ((InterfaceDataTypeDouble)indy).getDoubleData());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1005,7 +1003,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
|
|||||||
// finally set the new position and the current velocity
|
// finally set the new position and the current velocity
|
||||||
if (indy instanceof InterfaceDataTypeDouble) ((InterfaceDataTypeDouble)indy).SetDoubleGenotype(newPosition);
|
if (indy instanceof InterfaceDataTypeDouble) ((InterfaceDataTypeDouble)indy).SetDoubleGenotype(newPosition);
|
||||||
else {
|
else {
|
||||||
((InterfaceESIndividual) indy).SetDGenotype(newPosition); // WARNING, this does a checkBounds in any case!
|
((InterfaceDataTypeDouble) indy).SetDoubleGenotype(newPosition); // WARNING, this does a checkBounds in any case!
|
||||||
if (!m_CheckConstraints) System.err.println("warning, checkbounds will be forced by InterfaceESIndividual!");
|
if (!m_CheckConstraints) System.err.println("warning, checkbounds will be forced by InterfaceESIndividual!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import eva2.gui.GenericObjectEditor;
|
|||||||
import eva2.server.go.InterfacePopulationChangedEventListener;
|
import eva2.server.go.InterfacePopulationChangedEventListener;
|
||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||||
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
||||||
import eva2.server.go.individuals.InterfaceESIndividual;
|
|
||||||
import eva2.server.go.populations.InterfaceSolutionSet;
|
import eva2.server.go.populations.InterfaceSolutionSet;
|
||||||
import eva2.server.go.populations.Population;
|
import eva2.server.go.populations.Population;
|
||||||
import eva2.server.go.populations.SolutionSet;
|
import eva2.server.go.populations.SolutionSet;
|
||||||
@ -637,8 +636,8 @@ public class Tribes implements InterfaceOptimizer, java.io.Serializable {
|
|||||||
public void setPopulation(Population pop) {
|
public void setPopulation(Population pop) {
|
||||||
if (pop == null) return;
|
if (pop == null) return;
|
||||||
population = pop;
|
population = pop;
|
||||||
if (population.get(0) instanceof InterfaceESIndividual) {
|
if (population.get(0) instanceof InterfaceDataTypeDouble) {
|
||||||
range = ((InterfaceESIndividual)population.get(0)).getDoubleRange();
|
range = ((InterfaceDataTypeDouble)population.get(0)).getDoubleRange();
|
||||||
setDimension(range.length);
|
setDimension(range.length);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("warning, TRIBES requires InterfaceESIndidivual instead of " + population.get(0).getClass() + ". Couldnt correctly init the problem range.");
|
System.err.println("warning, TRIBES requires InterfaceESIndidivual instead of " + population.get(0).getClass() + ". Couldnt correctly init the problem range.");
|
||||||
|
@ -8,7 +8,7 @@ import eva2.server.go.problems.InterfaceOptimizationProblem;
|
|||||||
import eva2.server.go.strategies.Tribes;
|
import eva2.server.go.strategies.Tribes;
|
||||||
import wsi.ra.math.RNG;
|
import wsi.ra.math.RNG;
|
||||||
|
|
||||||
public class TribesExplorer extends AbstractEAIndividual implements InterfaceESIndividual, InterfaceDataTypeDouble {
|
public class TribesExplorer extends AbstractEAIndividual implements InterfaceDataTypeDouble {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -956,6 +956,17 @@ v[d] = cmin * v[d];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void defaultInit() {
|
||||||
|
// shouldnt be called as we are beyond the EvA framework in this class
|
||||||
|
for (int i = 0; i < this.position.x.length; i++) {
|
||||||
|
this.position.x[0] = 0.;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void defaultMutate() {
|
||||||
|
// shouldnt be called as we are beyond the EvA framework in this class
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
|
||||||
if (obj instanceof double[]) {
|
if (obj instanceof double[]) {
|
||||||
@ -1020,19 +1031,19 @@ v[d] = cmin * v[d];
|
|||||||
return position.x.length;
|
return position.x.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDGenotype(double[] b) {
|
// public void SetDGenotype(double[] b) {
|
||||||
position.setDoubleArray(b);
|
// position.setDoubleArray(b);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void defaultInit() {
|
// public void defaultInit() {
|
||||||
System.err.println("defaultInit not available for TribesExplorer!");
|
// System.err.println("defaultInit not available for TribesExplorer!");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void defaultMutate() {
|
// public void defaultMutate() {
|
||||||
System.err.println("defaultMutate not available for TribesExplorer!");
|
// System.err.println("defaultMutate not available for TribesExplorer!");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public double[] getDGenotype() {
|
// public double[] getDGenotype() {
|
||||||
return position.getDoubleArray().clone();
|
// return position.getDoubleArray().clone();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user