Importing release version 322 from old repos
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 18.03.2003
|
||||
* Time: 11:24:42
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public interface InterfaceMutation {
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone();
|
||||
|
||||
/** 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 the proper interface nothing happens.
|
||||
* @param individual The individual that is to be mutated
|
||||
*/
|
||||
public void mutate(AbstractEAIndividual individual);
|
||||
|
||||
/** 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);
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation();
|
||||
|
||||
/** 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);
|
||||
}
|
||||
234
src/javaeva/server/go/operators/mutation/MutateEAMixer.java
Normal file
234
src/javaeva/server/go/operators/mutation/MutateEAMixer.java
Normal file
@@ -0,0 +1,234 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
import javaeva.client.EvAClient;
|
||||
import javaeva.tools.CompileAndLoad;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 20.05.2005
|
||||
* Time: 13:53:46
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateEAMixer implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
private PropertyMutationMixer m_Mutators;
|
||||
private boolean m_UseSelfAdaption = false;
|
||||
protected double m_Tau1 = 0.15;
|
||||
protected double m_LowerLimitChance = 0.05;
|
||||
|
||||
public MutateEAMixer() {
|
||||
InterfaceMutation[] tmpList;
|
||||
Vector mutators = this.getClassesFromProperties("javaeva.server.oa.go.Operators.Mutation.MutateEAMixer", "javaeva.server.oa.go.Operators.Mutation.InterfaceMutation");
|
||||
tmpList = new InterfaceMutation[mutators.size()];
|
||||
for (int i = 0; i < mutators.size(); i++) {
|
||||
try {
|
||||
tmpList[i] = (InterfaceMutation)Class.forName((String)mutators.get(i)).newInstance();
|
||||
} catch (java.lang.ClassNotFoundException e) {
|
||||
System.out.println("Could not find class for " +(String)mutators.get(i) );
|
||||
} catch (java.lang.InstantiationException k) {
|
||||
System.out.println("Instantiation exception for " +(String)mutators.get(i) );
|
||||
} catch (java.lang.IllegalAccessException a) {
|
||||
System.out.println("Illegal access exception for " +(String)mutators.get(i) );
|
||||
}
|
||||
}
|
||||
this.m_Mutators = new PropertyMutationMixer(tmpList);
|
||||
tmpList = new InterfaceMutation[2];
|
||||
tmpList[0] = new MutateGINominal();
|
||||
tmpList[1] = new MutateGIOrdinal();
|
||||
this.m_Mutators.setSelectedMutators(tmpList);
|
||||
this.m_Mutators.normalizeWeights();
|
||||
this.m_Mutators.setDescriptiveString("Combining alternative mutation operators, please norm the weights!");
|
||||
this.m_Mutators.setWeightsLabel("Weigths");
|
||||
|
||||
}
|
||||
public MutateEAMixer(MutateEAMixer mutator) {
|
||||
this.m_Mutators = (PropertyMutationMixer)mutator.m_Mutators.clone();
|
||||
this.m_UseSelfAdaption = mutator.m_UseSelfAdaption;
|
||||
this.m_Tau1 = mutator.m_Tau1;
|
||||
this.m_LowerLimitChance = mutator.m_LowerLimitChance;
|
||||
}
|
||||
|
||||
private Vector getClassesFromProperties(String mySelf, String myInterface) {
|
||||
Vector classes = new Vector();
|
||||
String typeOptions = EvAClient.getProperty(myInterface);
|
||||
if (typeOptions == null) {
|
||||
System.out.println("Warning: No configuration property found in: " +EvAClient.EVA_PROPERTY_FILE + " "+"for javaeva.server.oa.go.Operators.Mutation.InterfaceMutation");
|
||||
} else {
|
||||
StringTokenizer st = new StringTokenizer(typeOptions, ", ");
|
||||
while (st.hasMoreTokens()) {
|
||||
String current = st.nextToken().trim();
|
||||
if (!current.equalsIgnoreCase(mySelf)) {
|
||||
try {
|
||||
Class c = Class.forName(current);
|
||||
classes.addElement(current);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Couldn't load class with name: " + current);
|
||||
System.out.println("ex:"+ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateEAMixer(this);
|
||||
}
|
||||
|
||||
/** 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 MutateEAMixer) {
|
||||
MutateEAMixer mut = (MutateEAMixer)mutator;
|
||||
|
||||
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){
|
||||
InterfaceMutation[] mutators = this.m_Mutators.getSelectedMutators();
|
||||
for (int i = 0; i < mutators.length; i++) mutators[i].init(individual, 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) {
|
||||
this.m_Mutators.normalizeWeights();
|
||||
double[] probs = this.m_Mutators.getWeights();
|
||||
if (this.m_UseSelfAdaption) {
|
||||
for (int i = 0; i < probs.length; i++) {
|
||||
probs[i] = probs[i] * Math.exp(this.m_Tau1 * RandomNumberGenerator.gaussianDouble(1));
|
||||
if (probs[i] <= this.m_LowerLimitChance) probs[i] = this.m_LowerLimitChance;
|
||||
if (probs[i] >= 1) probs[i] = 1;
|
||||
}
|
||||
this.m_Mutators.normalizeWeights();
|
||||
}
|
||||
|
||||
InterfaceMutation[] mutators = this.m_Mutators.getSelectedMutators();
|
||||
double pointer = RandomNumberGenerator.randomFloat(0, 1);
|
||||
double dum = probs[0];
|
||||
int index = 0;
|
||||
while ((pointer > dum) && (index < probs.length-1)) {
|
||||
index++;
|
||||
dum += probs[index];
|
||||
}
|
||||
if (index == probs.length) index = RandomNumberGenerator.randomInt(0, probs.length-1);
|
||||
//System.out.println("Using : " + mutators[index].getStringRepresentation());
|
||||
// for (int i = 0; i < probs.length; i++) {
|
||||
// System.out.println(""+mutators[i].getStringRepresentation()+" : "+ probs[i]);
|
||||
// }
|
||||
// System.out.println("");
|
||||
mutators[index].mutate(individual);
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
for (int i = 0; i < this.m_Mutators.getSelectedMutators().length; i++) {
|
||||
this.m_Mutators.getSelectedMutators()[i].crossoverOnStrategyParameters(indy1, partners);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "EA mutation mixer";
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* These are for GUI
|
||||
*/
|
||||
/** This method allows the CommonJavaObjectEditorPanel to read the
|
||||
* name to the current object.
|
||||
* @return The name.
|
||||
*/
|
||||
public String getName() {
|
||||
return "EA mutation mixer";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mmeta-mutation operator allows you to combine multiple alternative mutation operators.";
|
||||
}
|
||||
|
||||
/** Choose the set of mutators.
|
||||
* @param d The mutation operators.
|
||||
*/
|
||||
public void setMutators(PropertyMutationMixer d) {
|
||||
this.m_Mutators = d;
|
||||
}
|
||||
public PropertyMutationMixer getMutators() {
|
||||
return this.m_Mutators;
|
||||
}
|
||||
public String mutatorsTipText() {
|
||||
return "Choose the set of mutators.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setUseSelfAdaption(boolean d) {
|
||||
this.m_UseSelfAdaption = d;
|
||||
}
|
||||
public boolean getUseSelfAdaption() {
|
||||
return this.m_UseSelfAdaption;
|
||||
}
|
||||
public String useSelfAdaptionTipText() {
|
||||
return "Use my implementation of self-adaption for the mutation mixer.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setLowerLimitChance(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_LowerLimitChance = d;
|
||||
}
|
||||
public double getLowerLimitChance() {
|
||||
return this.m_LowerLimitChance;
|
||||
}
|
||||
public String lowerLimitChanceTipText() {
|
||||
return "Set the lower limit for the mutation chance.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau1(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau1 = d;
|
||||
}
|
||||
public double getTau1() {
|
||||
return this.m_Tau1;
|
||||
}
|
||||
public String tau1TipText() {
|
||||
return "Set the value for tau1.";
|
||||
}
|
||||
}
|
||||
318
src/javaeva/server/go/operators/mutation/MutateESCorrolated.java
Normal file
318
src/javaeva/server/go/operators/mutation/MutateESCorrolated.java
Normal file
@@ -0,0 +1,318 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 02.04.2003
|
||||
* Time: 17:58:30
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class MutateESCorrolated implements InterfaceMutation, java.io.Serializable {
|
||||
protected double m_MutationStepSize = 0.2;
|
||||
protected double m_Tau1 = 0.15;
|
||||
protected double m_LowerLimitStepSize = 0.0000005;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private double[] m_Sigmas;
|
||||
private double[] m_Alphas;
|
||||
protected double m_Tau2 = 0.15;
|
||||
|
||||
public MutateESCorrolated() {
|
||||
this.m_Sigmas = null;
|
||||
this.m_Alphas = null;
|
||||
}
|
||||
|
||||
public MutateESCorrolated(MutateESCorrolated mutator) {
|
||||
if ((mutator.m_Sigmas != null)) {
|
||||
this.m_Sigmas = new double[mutator.m_Sigmas.length];
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) {
|
||||
this.m_Sigmas[i] = mutator.m_Sigmas[i];
|
||||
}
|
||||
|
||||
}
|
||||
if (mutator.m_Alphas != null) {
|
||||
this.m_Alphas = new double[mutator.m_Alphas.length];
|
||||
for (int i = 0; i < this.m_Alphas.length; i++) {
|
||||
this.m_Alphas[i] = mutator.m_Alphas[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.m_MutationStepSize = mutator.m_MutationStepSize;
|
||||
this.m_Tau1 = mutator.m_Tau1;
|
||||
this.m_Tau2 = mutator.m_Tau2;
|
||||
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESCorrolated(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESCorrolated) {
|
||||
MutateESCorrolated mut = (MutateESCorrolated)mutator;
|
||||
if (this.m_Tau1 != mut.m_Tau1) return false;
|
||||
if (this.m_Tau2 != mut.m_Tau2) return false;
|
||||
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) return false;
|
||||
if (this.m_Sigmas != null) {
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) {
|
||||
if (this.m_Sigmas[i] != mut.m_Sigmas[i]) return false;
|
||||
}
|
||||
} else return false;
|
||||
if (this.m_Alphas != null) {
|
||||
for (int i = 0; i < this.m_Alphas.length; i++) {
|
||||
if (this.m_Alphas[i] != mut.m_Alphas[i]) return false;
|
||||
}
|
||||
} else return false;
|
||||
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) {
|
||||
// if (individual instanceof InterfaceESIndividual) {
|
||||
// double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
// double[] xCopy = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
// double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
// double tmpR = RandomNumberGenerator.gaussianDouble(1);
|
||||
// if (this.m_Sigmas == null) {
|
||||
// // init the Sigmas
|
||||
// this.m_Sigmas = new double[x.length];
|
||||
// for (int i = 0; i < this.m_Sigmas.length; i++) this.m_Sigmas[i] = this.m_MutationStepSize;
|
||||
// }
|
||||
//
|
||||
// //Mutate Sigmas
|
||||
// for (int i = 0; i < x.length; i++) {
|
||||
// this.m_Sigmas[i] = this.m_Sigmas[i] * Math.exp(this.m_Tau1 * tmpR + this.m_Tau2 * RandomNumberGenerator.gaussianDouble(1));
|
||||
// if (this.m_Sigmas[i] < this.m_LowerLimitStepSize) this.m_Sigmas[i] = this.m_LowerLimitStepSize;
|
||||
// }
|
||||
//
|
||||
//// if (this.m_Alphas == null) {
|
||||
//// // init the Alphas
|
||||
//// this.m_Alphas = new double[(x.length*(x.length-1))/2];
|
||||
//// for (int i = 0; i < this.m_Alphas.length; i++) this.m_Alphas[i] = 0.0;
|
||||
//// }
|
||||
//
|
||||
//// //Mutate Alphas
|
||||
//// for (int i = 0; i < this.m_Alphas.length; i++) {
|
||||
//// this.m_Alphas[i] = this.m_Alphas[i] + RandomNumberGenerator.gaussianDouble(0.01);
|
||||
//// if (this.m_Alphas[i] < -m_PI/2) this.m_Alphas[i] = -m_PI/2;
|
||||
//// if (this.m_Alphas[i] > m_PI/2) this.m_Alphas[i] = m_PI/2;
|
||||
//// }
|
||||
//
|
||||
// //Generate mutationvector in unitspace modified by sigmas
|
||||
// for (int i = 0; i < x.length; i++) {
|
||||
// xCopy[i] = RandomNumberGenerator.gaussianDouble(this.m_Sigmas[i]);
|
||||
// }
|
||||
//
|
||||
// //modify genotype
|
||||
// for (int i = 0; i < x.length; i++) {
|
||||
// x[i] += ((range[i][1] -range[i][0])/2)*xCopy[i];
|
||||
// if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
// if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
// }
|
||||
//
|
||||
// ((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
//
|
||||
// //turn mutationvector with alphas
|
||||
//// for (int i = 0; i < x.length-1; i++) {
|
||||
//// for (int j = i+1; j < x.length; j++) {
|
||||
//// double alpha=this.getAlpha(i,j, x.length);
|
||||
//// double xX=java.lang.Math.cos(alpha)*xCopy[i]-java.lang.Math.sin(alpha)*xCopy[j];
|
||||
//// double xY=java.lang.Math.sin(alpha)*xCopy[i]+java.lang.Math.cos(alpha)*xCopy[j];
|
||||
//// xCopy[i]=xX;
|
||||
//// xCopy[j]=xY;
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
public void mutate(AbstractEAIndividual individual) {
|
||||
if (individual instanceof InterfaceESIndividual) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[] xCopy = new double[x.length];
|
||||
double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
double tmpR = RandomNumberGenerator.gaussianDouble(1);
|
||||
|
||||
if (this.m_Sigmas == null) {
|
||||
// init the Sigmas
|
||||
this.m_Sigmas = new double[x.length];
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) this.m_Sigmas[i] = this.m_MutationStepSize;
|
||||
}
|
||||
//Mutate Sigmas
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
this.m_Sigmas[i] = this.m_Sigmas[i] * Math.exp(this.m_Tau1 * tmpR + this.m_Tau2 * RandomNumberGenerator.gaussianDouble(1));
|
||||
if (this.m_Sigmas[i] < this.m_LowerLimitStepSize) this.m_Sigmas[i] = this.m_LowerLimitStepSize;
|
||||
}
|
||||
|
||||
if (this.m_Alphas == null) {
|
||||
// init the Alphas
|
||||
this.m_Alphas = new double[(x.length*(x.length-1))/2];
|
||||
for (int i = 0; i < this.m_Alphas.length; i++) this.m_Alphas[i] = 0.0;
|
||||
}
|
||||
//Mutate Alphas
|
||||
for (int i = 0; i < this.m_Alphas.length; i++) {
|
||||
this.m_Alphas[i] = this.m_Alphas[i] + RandomNumberGenerator.gaussianDouble(0.2);
|
||||
if (this.m_Alphas[i] < -Math.PI/2) this.m_Alphas[i] = -Math.PI/2;
|
||||
if (this.m_Alphas[i] > Math.PI/2) this.m_Alphas[i] = Math.PI/2;
|
||||
}
|
||||
|
||||
//Generate mutationvector in unitspace modified by sigmas
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
xCopy[i] = RandomNumberGenerator.gaussianDouble(this.m_Sigmas[i]);
|
||||
}
|
||||
|
||||
//turn mutationvector with alphas
|
||||
for (int i = 0; i < x.length-1; i++) {
|
||||
for (int j = i+1; j < x.length; j++) {
|
||||
double alpha=this.getAlpha(i,j, x.length);
|
||||
double xX=java.lang.Math.cos(alpha)*xCopy[i]-java.lang.Math.sin(alpha)*xCopy[j];
|
||||
double xY=java.lang.Math.sin(alpha)*xCopy[i]+java.lang.Math.cos(alpha)*xCopy[j];
|
||||
xCopy[i]=xX;
|
||||
xCopy[j]=xY;
|
||||
}
|
||||
}
|
||||
|
||||
//modify genotype
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] += ((range[i][1] -range[i][0])/2)*xCopy[i];
|
||||
if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
}
|
||||
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
}
|
||||
|
||||
/**
|
||||
* @param i
|
||||
* @param j
|
||||
*/
|
||||
private double getAlpha(int i, int j, int n) {
|
||||
int sum=0;
|
||||
if (i<j) {
|
||||
for (int count=0; count<i; count++) {
|
||||
sum+=n-count-1;
|
||||
}
|
||||
sum+=j-i; sum--;
|
||||
return this.m_Alphas[sum];
|
||||
}else{
|
||||
System.out.println("Falscher Zugriff auf Alphaliste!");
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "ES local 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 local correlated mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The local correlated mutation stores n sigmas for each double attribute and n(n-1) alphas.";
|
||||
}
|
||||
|
||||
/** Set the value for tau2 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau2(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau2 = d;
|
||||
}
|
||||
public double getTau2() {
|
||||
return this.m_Tau2;
|
||||
}
|
||||
public String tau2TipText() {
|
||||
return "Set the value for tau2.";
|
||||
}
|
||||
|
||||
/** Set the initial mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setMutationStepSize(double d) {
|
||||
if (d < 0) d = this.m_LowerLimitStepSize;
|
||||
this.m_MutationStepSize = d;
|
||||
}
|
||||
public double getMutationStepSize() {
|
||||
return this.m_MutationStepSize;
|
||||
}
|
||||
public String mutationStepSizeTipText() {
|
||||
return "Choose the initial mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setLowerLimitStepSize(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_LowerLimitStepSize = d;
|
||||
}
|
||||
public double getLowerLimitStepSize() {
|
||||
return this.m_LowerLimitStepSize;
|
||||
}
|
||||
public String lowerLimitStepSizeTipText() {
|
||||
return "Set the lower limit for the mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau1(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau1 = d;
|
||||
}
|
||||
public double getTau1() {
|
||||
return this.m_Tau1;
|
||||
}
|
||||
public String tau1TipText() {
|
||||
return "Set the value for tau1.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
import wsi.ra.math.Jama.EigenvalueDecomposition;
|
||||
import wsi.ra.math.Jama.Matrix;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 27.05.2003
|
||||
* Time: 17:47:45
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
|
||||
public class MutateESCovarianceMartixAdaption implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
private int m_D;
|
||||
private double[] m_Z;
|
||||
private double m_SigmaGlobal = 1;
|
||||
private double m_InitSigmaScalar = 1;
|
||||
private double m_c;
|
||||
private double cu;
|
||||
private double cov;
|
||||
private double Beta;
|
||||
private double[] s_N;
|
||||
private double[] s_d_N;
|
||||
public double[] Bz;
|
||||
private double xi_dach;
|
||||
private Matrix m_C;
|
||||
private Matrix B;
|
||||
private boolean m_CheckConstraints = false;
|
||||
private int m_constraint = 20;
|
||||
private int m_Counter;
|
||||
private int m_frequency = 1;
|
||||
private double[] m_Eigenvalues;
|
||||
|
||||
public MutateESCovarianceMartixAdaption() {
|
||||
|
||||
}
|
||||
public MutateESCovarianceMartixAdaption(MutateESCovarianceMartixAdaption mutator) {
|
||||
this.m_Counter = mutator.m_Counter;
|
||||
this.m_frequency = mutator.m_frequency;
|
||||
this.m_InitSigmaScalar = mutator.m_InitSigmaScalar;
|
||||
this.m_constraint = mutator.m_constraint;
|
||||
this.m_CheckConstraints = mutator.m_CheckConstraints;
|
||||
this.m_D = mutator.m_D;
|
||||
this.m_SigmaGlobal = mutator.m_SigmaGlobal;
|
||||
this.m_c = mutator.m_c;
|
||||
this.cu = mutator.cu;
|
||||
this.cov = mutator.cov;
|
||||
this.Beta = mutator.Beta;
|
||||
this.xi_dach = mutator.xi_dach;
|
||||
if (mutator.s_N != null) this.s_N = (double[]) mutator.s_N.clone();
|
||||
if (mutator.s_d_N != null) this.s_d_N = (double[]) mutator.s_d_N.clone();
|
||||
if (mutator.Bz != null) this.Bz = (double[]) mutator.Bz.clone();
|
||||
if (mutator.m_C != null) this.m_C = (Matrix) mutator.m_C.clone();
|
||||
if (mutator.B != null) this.B = (Matrix) mutator.B.clone();
|
||||
if (mutator.m_Z != null) this.m_Z = (double[]) mutator.m_Z.clone();
|
||||
if (mutator.m_Eigenvalues != null) this.m_Eigenvalues = (double[]) mutator.m_Eigenvalues.clone();
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESCovarianceMartixAdaption(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESCovarianceMartixAdaption) {
|
||||
MutateESCovarianceMartixAdaption mut = (MutateESCovarianceMartixAdaption)mutator;
|
||||
// i assume if the C Matrix is equal then the mutation operators are equal
|
||||
try {
|
||||
double[][] c1 = this.m_C.getArray();
|
||||
double[][] c2 = mut.m_C.getArray();
|
||||
for (int i = 0; i < c1.length; i++) {
|
||||
for(int j = 0; j < c1[i].length; j++) {
|
||||
if (c1[i][j] != c2[i][j]) return false;
|
||||
}
|
||||
}
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
if (!(individual instanceof InterfaceESIndividual)) return;
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] ranges = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
this.m_Counter = this.m_frequency;
|
||||
this.m_SigmaGlobal = this.m_InitSigmaScalar;
|
||||
this.m_D = x.length;
|
||||
this.m_C = Matrix.identity(this.m_D, this.m_D);
|
||||
EigenvalueDecomposition helper = new EigenvalueDecomposition(this.m_C);
|
||||
this.B = helper.getV();
|
||||
this.m_c = Math.sqrt(1.0 / (double) this.m_D);
|
||||
this.cu = Math.sqrt( (2.0 - this.m_c) / this.m_c);
|
||||
this.Beta = this.m_c;
|
||||
this.cov = 2.0 / ( (double) this.m_D * (double) this.m_D);
|
||||
this.m_Z = new double[this.m_D];
|
||||
this.s_N = new double[this.m_D];
|
||||
this.Bz = new double[this.m_D];
|
||||
this.s_d_N = new double[this.m_D];
|
||||
for (int i = 0; i < this.m_D; i++) {
|
||||
this.s_N[i] = 0;
|
||||
this.Bz[i] = 0;
|
||||
this.s_d_N[i] = 0;
|
||||
}
|
||||
this.xi_dach = Math.sqrt(this.m_D - 0.5);
|
||||
evaluateNewObjectX(x, ranges);
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] ranges = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
this.adaptStrategy();
|
||||
this.evaluateNewObjectX(x, ranges);
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
if (x[i] < ranges[i][0]) x[i] = ranges[i][0];
|
||||
if (x[i] > ranges[i][1]) x[i] = ranges[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
}
|
||||
//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
|
||||
}
|
||||
|
||||
private void adaptStrategy() {
|
||||
double Cij;
|
||||
double Bz_d;
|
||||
double length = 0.0;
|
||||
for (int i = 0; i < this.m_D; i++)
|
||||
this.s_N[i] = (1.0 - this.m_c) * this.s_N[i] + this.m_c * this.cu * this.Bz[i];
|
||||
// ADAPT COVARIANCE
|
||||
for (int i = 0; i <this. m_D; i++) {
|
||||
for (int j = i; j < this.m_D; j++) {
|
||||
Cij = (1.0 - this.cov) * this.m_C.get(i, j) + this.cov * this.s_N[i] * this.s_N[j];
|
||||
this.m_C.set(i, j, Cij);
|
||||
this.m_C.set(j, i, Cij);
|
||||
}
|
||||
}
|
||||
// ADAPT GLOBAL STEPSIZE
|
||||
for (int i = 0; i < this.m_D; i++) {
|
||||
Bz_d = 0.0;
|
||||
for (int j = 0; j < this.m_D; j++)
|
||||
Bz_d = Bz_d + this.B.get(i, j) * this.m_Z[j];
|
||||
this.s_d_N[i] = (1.0 - this.m_c) * this.s_d_N[i] + this.m_c * this.cu * Bz_d;
|
||||
length = length + this.s_d_N[i] * this.s_d_N[i];
|
||||
}
|
||||
this.m_SigmaGlobal = this.m_SigmaGlobal * Math.exp(this.Beta * this.m_c * (Math.sqrt(length) - this.xi_dach));;
|
||||
}
|
||||
|
||||
private void evaluateNewObjectX(double[] x,double[][] range) {
|
||||
// if (Double.isNaN((x[0]))) System.out.println("treffer in cma "+ x[0]);
|
||||
// if (Double.isNaN((m_C.get(0,0)))) System.out.println("treffer in cma");
|
||||
// for (int i=0;i<N;i++) { // evaluate new random values
|
||||
// m_Z[i] = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
// }
|
||||
// m_C = (m_C.plus(m_C.transpose()).times(0.5)); // MAKE C SYMMETRIC
|
||||
// EigenvalueDecomposition helper = new EigenvalueDecomposition(m_C);
|
||||
// B = helper.getV();
|
||||
// double [] Eigenvalues = helper.getRealEigenvalues();
|
||||
// double[] tmpD = new double[x.length];
|
||||
// boolean constraint = false;
|
||||
// while (constraint == false) {
|
||||
//
|
||||
// for (int i=0;i<N;i++) {
|
||||
// Bz[i] = 0;
|
||||
// for (int j=0;j<N;j++) {
|
||||
// Bz[i] = Bz[i] + Math.sqrt(Math.abs(Eigenvalues[j])) * B.get(i,j)*m_Z[j];
|
||||
// }
|
||||
// tmpD[i]=x[i]+m_SigmaScalar*Bz[i]; // here is the new value
|
||||
// }
|
||||
// constraint = true;
|
||||
// if (this.m_CheckConstraints) {
|
||||
// for (int i=0;i<N;i++) {
|
||||
// if ((tmpD[i]<range[i][0]) || (tmpD[i]>range[i][1])) constraint = false;
|
||||
// }
|
||||
// if (!constraint) this.m_SigmaScalar = this.m_SigmaScalar/2;
|
||||
// if (this.m_SigmaScalar < 1.e-20) {
|
||||
// this.m_SigmaScalar = 1.e-10;
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// for (int i = 0; i < N; i++) x[i] = tmpD[i];
|
||||
// conservation of mutaion direction:
|
||||
double[] old = (double[]) this.m_Z.clone();
|
||||
for (int i = 0; i < this.m_D; i++) this.m_Z[i] = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
|
||||
this.m_C = (this.m_C.plus(this.m_C.transpose()).times(0.5)); // MAKE C SYMMETRIC
|
||||
this.m_Counter++;
|
||||
if (this.m_Counter >= this.m_frequency) {
|
||||
EigenvalueDecomposition helper;
|
||||
this.m_Counter = 0;
|
||||
helper = new EigenvalueDecomposition(this.m_C);
|
||||
this.B = helper.getV();
|
||||
this.m_Eigenvalues = helper.getRealEigenvalues();
|
||||
|
||||
}
|
||||
boolean constraint = false;
|
||||
int counter = 0;
|
||||
while (constraint == false && counter < this.m_constraint) {
|
||||
for (int i = 0; i < this.m_D; i++) {
|
||||
this.Bz[i] = 0;
|
||||
for (int j = 0; j < this.m_D; j++) {
|
||||
this.Bz[i] = this.Bz[i] + Math.sqrt(Math.abs(this.m_Eigenvalues[j])) * this.B.get(i, j) * this.m_Z[j];
|
||||
}
|
||||
x[i] = x[i] + this.m_SigmaGlobal * this.Bz[i]; // here is the new value
|
||||
}
|
||||
constraint = true;
|
||||
if (this.m_CheckConstraints == true) {
|
||||
for (int i = 0; i < m_D; i++) {
|
||||
if (x[i] < range[i][0] || x[i] > range[i][1]) {
|
||||
for (int j = 0; j < this.m_D; j++) x[j] = x[j] - this.m_SigmaGlobal * this.Bz[j];
|
||||
this.m_Z[i] = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
constraint = false;
|
||||
counter++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.m_CheckConstraints == true) { // CSpieth
|
||||
for (int i = 0; i < this.m_D; i++) {
|
||||
if (x[i] < range[i][0]) x[i] = range[i][0];
|
||||
if (x[i] > range[i][1]) x[i] = range[i][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "CMA 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 "CMA mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This is the most sophisticated CMA mutation.";
|
||||
}
|
||||
|
||||
/** Use only positive numbers this limits the freedom of effect.
|
||||
* @param bit The new representation for the inner constants.
|
||||
*/
|
||||
public void setCheckConstraints(boolean bit) {
|
||||
this.m_CheckConstraints = bit;
|
||||
}
|
||||
public boolean getCheckConstraints() {
|
||||
return this.m_CheckConstraints;
|
||||
}
|
||||
public String checkConstraintsTipText() {
|
||||
return "Toggle check constraints.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the initial sigma value.
|
||||
* @param d The initial sigma value.
|
||||
*/
|
||||
public void setInitSigmaScalar(double d) {
|
||||
this.m_InitSigmaScalar = d;
|
||||
}
|
||||
public double getInitSigmaScalar() {
|
||||
return this.m_InitSigmaScalar;
|
||||
}
|
||||
public String initSigmaScalarTipText() {
|
||||
return "Set the initial sigma value.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.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 alters one element of the double attributes.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 31.05.2005
|
||||
* Time: 14:22:13
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateESDerandomized implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
private int m_D;
|
||||
private double[] m_Z;
|
||||
private double[] m_Path;
|
||||
private double m_SigmaGlobal = 1.0;
|
||||
private double m_c;
|
||||
private boolean m_UsePath = true;
|
||||
|
||||
public MutateESDerandomized() {
|
||||
|
||||
}
|
||||
public MutateESDerandomized(MutateESDerandomized mutator) {
|
||||
this.m_UsePath = true;
|
||||
this.m_D = mutator.m_D;
|
||||
this.m_SigmaGlobal = mutator.m_SigmaGlobal;
|
||||
this.m_c = mutator.m_c;
|
||||
if (mutator.m_Z != null) this.m_Z = (double[]) mutator.m_Z.clone();
|
||||
if (mutator.m_Path != null) this.m_Path = (double[]) mutator.m_Path.clone();
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESDerandomized(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESDerandomized) {
|
||||
MutateESDerandomized mut = (MutateESDerandomized)mutator;
|
||||
// i assume if the C Matrix is equal then the mutation operators are equal
|
||||
if (this.m_D != mut.m_D) return false;
|
||||
if (this.m_SigmaGlobal != mut.m_SigmaGlobal) return false;
|
||||
if (this.m_c != mut.m_c) return false;
|
||||
if ((this.m_Z != null) && (mut.m_Z != null))
|
||||
for (int i = 0; i < this.m_Z.length; i++) if (this.m_Z[i] != mut.m_Z[i]) return false;
|
||||
if ((this.m_Path != null) && (mut.m_Path != null))
|
||||
for (int i = 0; i < this.m_Path.length; i++) if (this.m_Path[i] != mut.m_Path[i]) return false;
|
||||
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) {
|
||||
if (!(individual instanceof InterfaceESIndividual)) return;
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] ranges = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
this.m_D = x.length;
|
||||
if (this.m_UsePath == true) this.m_c = Math.sqrt(1.0 / (double) this.m_D);
|
||||
else this.m_c = 1.0;
|
||||
this.m_Z = new double[this.m_D];
|
||||
this.m_Path = new double[this.m_D];
|
||||
for (int i = 0; i < this.m_D; i++) this.m_Z[i] = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
evaluateNewObjectX(x, ranges);
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] ranges = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
this.adaptStrategy();
|
||||
for (int i = 0; i < m_D; i++) m_Z[i] = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
this.evaluateNewObjectX(x, ranges);
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
if (x[i] < ranges[i][0]) x[i] = ranges[i][0];
|
||||
if (x[i] > ranges[i][1]) x[i] = ranges[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
}
|
||||
//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
|
||||
}
|
||||
|
||||
private void adaptStrategy() {
|
||||
double length_of_Z = 0;
|
||||
for (int i = 0; i < m_D; i++) {
|
||||
m_Path [i] = (1.0 -m_c) * m_Path[i] + Math.sqrt(m_c*(2.0-m_c))*m_Z[i];
|
||||
length_of_Z = length_of_Z + m_Path[i] * m_Path[i];
|
||||
}
|
||||
length_of_Z = Math.sqrt(length_of_Z);
|
||||
double E_of_length_of_Z = Math.sqrt(((double)m_D)+0.5);
|
||||
double kappa_d = ((double)m_D)/4.0+1.0;
|
||||
double Exponent = (length_of_Z - E_of_length_of_Z)/(kappa_d*E_of_length_of_Z);
|
||||
m_SigmaGlobal = m_SigmaGlobal * Math.exp(Exponent);
|
||||
}
|
||||
|
||||
private void evaluateNewObjectX(double[] x,double[][] range) {
|
||||
for (int i = 0; i < x.length; i++)
|
||||
x[i] = x[i] + m_SigmaGlobal * m_Z[i];
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "CMA 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 "CMA mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This is the most sophisticated CMA mutation.";
|
||||
}
|
||||
|
||||
/** Use only positive numbers this limits the freedom of effect.
|
||||
* @param bit The new representation for the inner constants.
|
||||
*/
|
||||
public void setUsePath(boolean bit) {
|
||||
this.m_UsePath = bit;
|
||||
}
|
||||
public boolean getUsePath() {
|
||||
return this.m_UsePath;
|
||||
}
|
||||
public String usePathTipText() {
|
||||
return "Use path.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the initial sigma value.
|
||||
* @param d The initial sigma value.
|
||||
*/
|
||||
public void setSigmaGlobal(double d) {
|
||||
this.m_SigmaGlobal = d;
|
||||
}
|
||||
public double getSigmaGlobal() {
|
||||
return this.m_SigmaGlobal;
|
||||
}
|
||||
public String initSigmaGlobalTipText() {
|
||||
return "Set the initial global sigma value.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 08.09.2004
|
||||
* Time: 17:05:23
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateESFixedStepSize implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
private double m_Sigma = 0.005;
|
||||
|
||||
public MutateESFixedStepSize() {
|
||||
}
|
||||
|
||||
public MutateESFixedStepSize(MutateESFixedStepSize mutator) {
|
||||
this.m_Sigma = mutator.m_Sigma;
|
||||
}
|
||||
|
||||
public MutateESFixedStepSize(double sigma) {
|
||||
m_Sigma = sigma;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESFixedStepSize(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESFixedStepSize) {
|
||||
MutateESFixedStepSize mut = (MutateESFixedStepSize)mutator;
|
||||
if (this.m_Sigma != mut.m_Sigma) return false;
|
||||
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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] += ((range[i][1] -range[i][0])/2)*RandomNumberGenerator.gaussianDouble(this.m_Sigma);
|
||||
if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
|
||||
}
|
||||
//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 fixed step size 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 fixed step size mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The fixed step size mutation alters all elements with a fixed mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the value for Sigma with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setSigma(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Sigma = d;
|
||||
}
|
||||
public double getSigma() {
|
||||
return this.m_Sigma;
|
||||
}
|
||||
public String sigmaTipText() {
|
||||
return "Set the value for the fixed sigma.";
|
||||
}
|
||||
}
|
||||
203
src/javaeva/server/go/operators/mutation/MutateESGlobal.java
Normal file
203
src/javaeva/server/go/operators/mutation/MutateESGlobal.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
import javaeva.tools.Tag;
|
||||
import javaeva.tools.SelectedTag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 02.04.2003
|
||||
* Time: 16:29:47
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class MutateESGlobal implements InterfaceMutation, java.io.Serializable {
|
||||
protected double m_MutationStepSize = 0.2;
|
||||
protected double m_Tau1 = 0.15;
|
||||
protected double m_LowerLimitStepSize = 0.0000005;
|
||||
protected SelectedTag m_CrossoverType;
|
||||
|
||||
public MutateESGlobal() {
|
||||
Tag[] tag = new Tag[3];
|
||||
tag[0] = new Tag(0, "None");
|
||||
tag[1] = new Tag(1, "Intermediate");
|
||||
tag[2] = new Tag(2, "Discrete");
|
||||
this.m_CrossoverType = new SelectedTag(0, tag);
|
||||
}
|
||||
|
||||
public MutateESGlobal(MutateESGlobal mutator) {
|
||||
this.m_MutationStepSize = mutator.m_MutationStepSize;
|
||||
this.m_Tau1 = mutator.m_Tau1;
|
||||
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize;
|
||||
this.m_CrossoverType = (SelectedTag)mutator.m_CrossoverType.clone();
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESGlobal(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESGlobal) {
|
||||
MutateESGlobal mut = (MutateESGlobal)mutator;
|
||||
if (this.m_MutationStepSize != mut.m_MutationStepSize) return false;
|
||||
if (this.m_Tau1 != mut.m_Tau1) return false;
|
||||
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) return false;
|
||||
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 InterfaceESIndividual 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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
this.m_MutationStepSize = this.m_MutationStepSize * Math.exp(this.m_Tau1 * RandomNumberGenerator.gaussianDouble(1));
|
||||
if (this.m_MutationStepSize < this.m_LowerLimitStepSize) this.m_MutationStepSize = this.m_LowerLimitStepSize;
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] += ((range[i][1] -range[i][0])/2)*RandomNumberGenerator.gaussianDouble(this.m_MutationStepSize);
|
||||
if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
|
||||
}
|
||||
//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) {
|
||||
ArrayList tmpList = new ArrayList();
|
||||
if (indy1.getMutationOperator() instanceof MutateESGlobal) tmpList.add(new Double(((MutateESGlobal)indy1.getMutationOperator()).m_MutationStepSize));
|
||||
for (int i = 0; i < partners.size(); i++) {
|
||||
if (((AbstractEAIndividual)partners.get(i)).getMutationOperator() instanceof MutateESGlobal) tmpList.add(new Double(((MutateESGlobal)((AbstractEAIndividual)partners.get(i)).getMutationOperator()).m_MutationStepSize));
|
||||
}
|
||||
double[] list = new double[tmpList.size()];
|
||||
for (int i = 0; i < tmpList.size(); i++) list[i] = ((Double)tmpList.get(i)).doubleValue();
|
||||
if (list.length <= 1) return;
|
||||
switch (this.m_CrossoverType.getSelectedTag().getID()) {
|
||||
case 1 : {
|
||||
this.m_MutationStepSize = 0;
|
||||
for (int i = 0; i < list.length; i++) this.m_MutationStepSize += list[i];
|
||||
this.m_MutationStepSize = this.m_MutationStepSize/(double)list.length;
|
||||
break;
|
||||
}
|
||||
case 2 : {
|
||||
this.m_MutationStepSize = list[RandomNumberGenerator.randomInt(0, list.length-1)];
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "ES global 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 global mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The global mutation stores only one sigma for all double attributes.";
|
||||
}
|
||||
|
||||
/** Set the initial mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setMutationStepSize(double d) {
|
||||
if (d < 0) d = this.m_LowerLimitStepSize;
|
||||
this.m_MutationStepSize = d;
|
||||
}
|
||||
public double getMutationStepSize() {
|
||||
return this.m_MutationStepSize;
|
||||
}
|
||||
public String mutationStepSizeTipText() {
|
||||
return "Choose the initial mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setLowerLimitStepSize(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_LowerLimitStepSize = d;
|
||||
}
|
||||
public double getLowerLimitStepSize() {
|
||||
return this.m_LowerLimitStepSize;
|
||||
}
|
||||
public String lowerLimitStepSizeTipText() {
|
||||
return "Set the lower limit for the mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau1(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau1 = d;
|
||||
}
|
||||
public double getTau1() {
|
||||
return this.m_Tau1;
|
||||
}
|
||||
public String tau1TipText() {
|
||||
return "Set the value for tau1.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setCrossoverType(SelectedTag d) {
|
||||
this.m_CrossoverType = d;
|
||||
}
|
||||
public SelectedTag getCrossoverType() {
|
||||
return this.m_CrossoverType;
|
||||
}
|
||||
public String crossoverTypeTipText() {
|
||||
return "Choose the crossover type for the strategy parameters.";
|
||||
}
|
||||
}
|
||||
260
src/javaeva/server/go/operators/mutation/MutateESLocal.java
Normal file
260
src/javaeva/server/go/operators/mutation/MutateESLocal.java
Normal file
@@ -0,0 +1,260 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
import javaeva.tools.SelectedTag;
|
||||
import javaeva.tools.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 02.04.2003
|
||||
* Time: 17:58:30
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class MutateESLocal implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
protected double m_MutationStepSize = 0.2;
|
||||
protected double m_Tau1 = 0.15;
|
||||
protected double m_LowerLimitStepSize = 0.0000005;
|
||||
private double[] m_Sigmas;
|
||||
protected double m_Tau2 = 0.15;
|
||||
protected SelectedTag m_CrossoverType;
|
||||
|
||||
public MutateESLocal() {
|
||||
this.m_Sigmas = null;
|
||||
Tag[] tag = new Tag[3];
|
||||
tag[0] = new Tag(0, "None");
|
||||
tag[1] = new Tag(1, "Intermediate");
|
||||
tag[2] = new Tag(2, "Discrete");
|
||||
this.m_CrossoverType = new SelectedTag(0, tag);
|
||||
}
|
||||
|
||||
public MutateESLocal(MutateESLocal mutator) {
|
||||
if (mutator.m_Sigmas != null) {
|
||||
this.m_Sigmas = new double[mutator.m_Sigmas.length];
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) {
|
||||
this.m_Sigmas[i] = mutator.m_Sigmas[i];
|
||||
}
|
||||
}
|
||||
this.m_MutationStepSize = mutator.m_MutationStepSize;
|
||||
this.m_Tau1 = mutator.m_Tau1;
|
||||
this.m_Tau2 = mutator.m_Tau2;
|
||||
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize;
|
||||
this.m_CrossoverType = (SelectedTag)mutator.m_CrossoverType.clone();
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESLocal(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESLocal) {
|
||||
MutateESLocal mut = (MutateESLocal)mutator;
|
||||
if (this.m_Tau1 != mut.m_Tau1) return false;
|
||||
if (this.m_Tau2 != mut.m_Tau2) return false;
|
||||
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) return false;
|
||||
if (this.m_Sigmas != null) {
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) {
|
||||
if (this.m_Sigmas[i] != mut.m_Sigmas[i]) return false;
|
||||
}
|
||||
} else return false;
|
||||
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) {
|
||||
if (individual instanceof InterfaceESIndividual) {
|
||||
// init the Sigmas
|
||||
this.m_Sigmas = new double[((InterfaceESIndividual)individual).getDGenotype().length];
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) this.m_Sigmas[i] = this.m_MutationStepSize;
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will mutate a given AbstractEAIndividual. If the individual
|
||||
* doesn't implement InterfaceESIndividual 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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
double tmpR = RandomNumberGenerator.gaussianDouble(1);
|
||||
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
this.m_Sigmas[i] = this.m_Sigmas[i] * Math.exp(this.m_Tau1 * tmpR + this.m_Tau2 * RandomNumberGenerator.gaussianDouble(1));
|
||||
if (this.m_Sigmas[i] < this.m_LowerLimitStepSize) this.m_Sigmas[i] = this.m_LowerLimitStepSize;
|
||||
x[i] += ((range[i][1] -range[i][0])/2)*RandomNumberGenerator.gaussianDouble(this.m_Sigmas[i]);
|
||||
if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
}
|
||||
//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) {
|
||||
ArrayList tmpListA = new ArrayList();
|
||||
ArrayList tmpListB = new ArrayList();
|
||||
if (indy1.getMutationOperator() instanceof MutateESLocal) {
|
||||
tmpListA.add(new Double(((MutateESLocal)indy1.getMutationOperator()).m_MutationStepSize));
|
||||
tmpListB.add(((MutateESLocal)indy1.getMutationOperator()).m_Sigmas);
|
||||
}
|
||||
for (int i = 0; i < partners.size(); i++) {
|
||||
if (((AbstractEAIndividual)partners.get(i)).getMutationOperator() instanceof MutateESLocal) {
|
||||
tmpListA.add(new Double(((MutateESLocal)((AbstractEAIndividual)partners.get(i)).getMutationOperator()).m_MutationStepSize));
|
||||
tmpListB.add(((MutateESLocal)((AbstractEAIndividual)partners.get(i)).getMutationOperator()).m_Sigmas);
|
||||
}
|
||||
}
|
||||
double[] listA = new double[tmpListA.size()];
|
||||
double[][] listB = new double[tmpListA.size()][];
|
||||
for (int i = 0; i < tmpListA.size(); i++) {
|
||||
listA[i] = ((Double)tmpListA.get(i)).doubleValue();
|
||||
listB[i] = (double[])tmpListB.get(i);
|
||||
}
|
||||
if (listA.length <= 1) return;
|
||||
switch (this.m_CrossoverType.getSelectedTag().getID()) {
|
||||
case 1 : {
|
||||
this.m_MutationStepSize = 0;
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) this.m_Sigmas[i] = 0;
|
||||
for (int i = 0; i < listA.length; i++) {
|
||||
this.m_MutationStepSize += listA[i];
|
||||
for (int j = 0; j < this.m_Sigmas.length; j++) this.m_Sigmas[j] += listB[i][j];
|
||||
}
|
||||
this.m_MutationStepSize = this.m_MutationStepSize/(double)listA.length;
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) this.m_Sigmas[i] = this.m_Sigmas[i]/(double)listA.length;
|
||||
break;
|
||||
}
|
||||
case 2 : {
|
||||
int rn = RandomNumberGenerator.randomInt(0, listA.length-1);
|
||||
this.m_MutationStepSize = listA[rn];
|
||||
for (int i = 0; i < this.m_Sigmas.length; i++) {
|
||||
rn = RandomNumberGenerator.randomInt(0, listA.length-1);
|
||||
this.m_Sigmas[i] = listB[rn][i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "ES local 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 local mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The local mutation stores n sigmas for each double attribute.";
|
||||
}
|
||||
|
||||
/** Set the initial mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setMutationStepSize(double d) {
|
||||
if (d < 0) d = this.m_LowerLimitStepSize;
|
||||
this.m_MutationStepSize = d;
|
||||
}
|
||||
public double getMutationStepSize() {
|
||||
return this.m_MutationStepSize;
|
||||
}
|
||||
public String mutationStepSizeTipText() {
|
||||
return "Choose the initial mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setLowerLimitStepSize(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_LowerLimitStepSize = d;
|
||||
}
|
||||
public double getLowerLimitStepSize() {
|
||||
return this.m_LowerLimitStepSize;
|
||||
}
|
||||
public String lowerLimitStepSizeTipText() {
|
||||
return "Set the lower limit for the mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau1(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau1 = d;
|
||||
}
|
||||
public double getTau1() {
|
||||
return this.m_Tau1;
|
||||
}
|
||||
public String tau1TipText() {
|
||||
return "Set the value for tau1.";
|
||||
}
|
||||
|
||||
/** Set the value for tau2 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau2(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau2 = d;
|
||||
}
|
||||
public double getTau2() {
|
||||
return this.m_Tau2;
|
||||
}
|
||||
public String tau2TipText() {
|
||||
return "Set the value for tau2.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setCrossoverType(SelectedTag d) {
|
||||
this.m_CrossoverType = d;
|
||||
}
|
||||
public SelectedTag getCrossoverType() {
|
||||
return this.m_CrossoverType;
|
||||
}
|
||||
public String crossoverTypeTipText() {
|
||||
return "Choose the crossover type for the strategy parameters.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 26.03.2004
|
||||
* Time: 11:18:36
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateESMainVectorAdaption implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
private boolean m_CheckConstraints = true;
|
||||
static public final String Name = "MVA";
|
||||
private int N;
|
||||
private double[] m_Z;
|
||||
private double m_SigmaScalar = 1.0;
|
||||
private double m_InitSigmaScalar = 1.0;
|
||||
private double m_c;
|
||||
private double m_cov;
|
||||
private double m_Beta;
|
||||
private double[] s_N;
|
||||
private double[] s_d_N;
|
||||
private double[] m_main_v;
|
||||
private double xi_dach;
|
||||
private double Z1;
|
||||
private double w_v = 3.0;
|
||||
|
||||
public MutateESMainVectorAdaption() {
|
||||
|
||||
}
|
||||
public MutateESMainVectorAdaption(MutateESMainVectorAdaption mutator) {
|
||||
this.N = mutator.N;
|
||||
this.m_SigmaScalar = mutator.m_SigmaScalar;
|
||||
this.m_InitSigmaScalar = mutator.m_InitSigmaScalar;
|
||||
this.m_c = mutator.m_c;
|
||||
this.m_cov = mutator.m_cov;
|
||||
this.m_Beta = mutator.m_Beta;
|
||||
this.xi_dach = mutator.xi_dach;
|
||||
this.Z1 = mutator.Z1;
|
||||
this.w_v = mutator.w_v;
|
||||
if (mutator.m_main_v != null) this.m_main_v = (double[]) mutator.m_main_v.clone();
|
||||
if (mutator.m_Z != null) this.m_Z = (double[]) mutator.m_Z.clone();
|
||||
if (mutator.s_N != null) this.s_N = (double[]) mutator.s_N.clone();
|
||||
if (mutator.s_d_N != null) this.s_d_N = (double[]) mutator.s_d_N.clone();
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESMainVectorAdaption(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESMainVectorAdaption) {
|
||||
MutateESMainVectorAdaption mut = (MutateESMainVectorAdaption)mutator;
|
||||
// i assume if the main_V is equal then the mutation operators are equal
|
||||
if (this.m_main_v != null) {
|
||||
for (int i = 0; i < this.m_main_v.length; i++) {
|
||||
if (this.m_main_v[i] != mut.m_main_v[i]) return false;
|
||||
}
|
||||
} else return false;
|
||||
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) {
|
||||
if (!(individual instanceof InterfaceESIndividual)) return;
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] ranges = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
this.m_SigmaScalar = this.m_InitSigmaScalar;
|
||||
this.N = x.length;
|
||||
this.m_c = Math.sqrt(1.0 / (double) this.N); // Sigma-Path-Constant
|
||||
this.m_Beta = this. m_c;
|
||||
this.m_cov = 2.0 / ( (double) this.N * (double) this.N);
|
||||
this.m_Z = new double[this.N];
|
||||
this.s_N = new double[this.N];
|
||||
this.s_d_N = new double[this.N];
|
||||
this.m_main_v = new double[this.N];
|
||||
for (int i = 0; i < this.N; i++) {
|
||||
this.s_N[i] = 0;
|
||||
this.s_d_N[i] = 0;
|
||||
this.m_main_v[i] = 0;
|
||||
};
|
||||
this.xi_dach = Math.sqrt(this.N - 0.5);
|
||||
for (int i = 0; i < this.N; i++) this.m_Z[i] = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
this.Z1 = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
evaluateNewObjectX(x, ranges);
|
||||
}
|
||||
|
||||
/** This method will mutate a given AbstractEAIndividual. If the individual
|
||||
* doesn't implement InterfaceESIndividual 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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] ranges = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
this.adaptStrategy();
|
||||
for (int i = 0; i < N; i++) m_Z[i] = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
Z1 = RandomNumberGenerator.gaussianDouble(1.0);
|
||||
evaluateNewObjectX(x, ranges);
|
||||
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
}
|
||||
//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
|
||||
}
|
||||
|
||||
private void adaptStrategy() {
|
||||
double length = 0.0;
|
||||
for (int i = 0; i < this.N; i++) {
|
||||
this.s_d_N[i] = (1.0 - this.m_c) * this.s_d_N[i] + Math.sqrt(this.m_c*(2.0-this.m_c)) * this.m_Z[i]; // PATH
|
||||
length = length + this.s_d_N[i] * this.s_d_N[i];
|
||||
}
|
||||
this.m_SigmaScalar = this.m_SigmaScalar * Math.exp(this.m_Beta * this.m_c * (Math.sqrt(length) - this.xi_dach));
|
||||
// SIGN OF SCALAR PRODUCT
|
||||
double Product = 0.0;
|
||||
for (int i = 0; i < this.N; i++) Product = Product + this.s_N[i] * this.m_main_v[i];
|
||||
if (Product < 0.0) Product = -1.0;
|
||||
else Product = 1.0;
|
||||
for (int i = 0; i < this.N; i++) { // ADAPT MAIN VECTOR
|
||||
this.s_N[i] = (1.0 - this.m_c) * this.s_N[i] + Math.sqrt(this.m_c*(2.0-this.m_c)) * (this.m_Z[i] + this.Z1 * this.w_v * this.m_main_v[i]); // PATH MAIN VECTOR
|
||||
this.m_main_v[i] = (1.0 - this.m_cov) * Product * this.m_main_v[i] + this.m_cov * this.s_N[i];
|
||||
}
|
||||
}
|
||||
|
||||
private void evaluateNewObjectX(double[] x, double[][] range) {
|
||||
if (Double.isNaN((x[0]))) System.err.println("treffer in mva "+ x[0]);
|
||||
|
||||
// boolean constraint = false;
|
||||
// int counter = 0;
|
||||
// while (constraint == false) {
|
||||
// for (int i = 0; i < x.length; i++) x[i] = x[i] + m_SigmaScalar * (m_Z[i] + Z1 * w_v * m_main_v[i]);
|
||||
// constraint = true;
|
||||
// if (counter++ > 30) break;
|
||||
// if (m_CheckConstraints == true) {
|
||||
// for (int i = 0; i < x.length; i++) {
|
||||
// if (x[i] < range[i][0]) x[i] = range[i][0];
|
||||
// if (x[i] > range[i][1]) x[i] = range[i][1];
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
double[] v =(double[])this.m_main_v.clone();
|
||||
double[] grad = new double[x.length];
|
||||
double vl = 0;
|
||||
double gradl = 0;
|
||||
for (int i=0;i < x.length; i++) {
|
||||
grad[i] = 2*x[i];
|
||||
vl = vl + v[i]*v[i];
|
||||
gradl = gradl + grad[i]*grad[i];
|
||||
}
|
||||
vl = Math.sqrt(vl);
|
||||
gradl = Math.sqrt(gradl);
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
v[i] = v[i] / vl; grad[i] = grad[i] / gradl;
|
||||
x[i] = x[i] + this.m_SigmaScalar * (this.m_Z[i] + this.Z1 * this.w_v * this.m_main_v[i]);
|
||||
}
|
||||
if (getCheckConstraints()) { // MK: lets actually do a constraint check
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
if (x[i] < range[i][0]) x[i] = range[i][0];
|
||||
if (x[i] > range[i][1]) x[i] = range[i][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "MVA 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 "MVA mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This is the most sophisticated MVA mutation.";
|
||||
}
|
||||
|
||||
/** Use only positive numbers this limits the freedom of effect.
|
||||
* @param bit The new representation for the inner constants.
|
||||
*/
|
||||
public void setCheckConstraints(boolean bit) {
|
||||
this.m_CheckConstraints = bit;
|
||||
}
|
||||
public boolean getCheckConstraints() {
|
||||
return this.m_CheckConstraints;
|
||||
}
|
||||
public String checkConstraintsTipText() {
|
||||
return "Toggle check constraints.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 10.09.2004
|
||||
* Time: 14:23:37
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateESMutativeStepSizeControl implements InterfaceMutation, java.io.Serializable {
|
||||
protected double m_MutationStepSize = 0.2;
|
||||
protected double m_Alpha = 1.2;
|
||||
protected double m_LowerLimitStepSize = 0.0000005;
|
||||
|
||||
public MutateESMutativeStepSizeControl() {
|
||||
|
||||
}
|
||||
public MutateESMutativeStepSizeControl(MutateESMutativeStepSizeControl mutator) {
|
||||
this.m_MutationStepSize = mutator.m_MutationStepSize;
|
||||
this.m_Alpha = mutator.m_Alpha;
|
||||
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESMutativeStepSizeControl(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESMutativeStepSizeControl) {
|
||||
MutateESMutativeStepSizeControl mut = (MutateESMutativeStepSizeControl)mutator;
|
||||
if (this.m_MutationStepSize != mut.m_MutationStepSize) return false;
|
||||
if (this.m_Alpha != mut.m_Alpha) return false;
|
||||
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) return false;
|
||||
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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
if (RandomNumberGenerator.flipCoin(0.5))
|
||||
this.m_MutationStepSize = this.m_MutationStepSize * this.m_Alpha;
|
||||
else
|
||||
this.m_MutationStepSize = this.m_MutationStepSize / this.m_Alpha;
|
||||
if (this.m_MutationStepSize < this.m_LowerLimitStepSize) this.m_MutationStepSize = this.m_LowerLimitStepSize;
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] += ((range[i][1] -range[i][0])/2)*RandomNumberGenerator.gaussianDouble(this.m_MutationStepSize);
|
||||
if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
|
||||
}
|
||||
//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 mutative step size control";
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* These are for GUI
|
||||
*/
|
||||
/** This method allows the CommonJavaObjectEditorPanel to read the
|
||||
* name to the current object.
|
||||
* @return The name.
|
||||
*/
|
||||
public String getName() {
|
||||
return "MSR";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The mutative step size control mutation randomly increases/decreases the current step size.";
|
||||
}
|
||||
|
||||
/** Set the initial mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setMutationStepSize(double d) {
|
||||
if (d < 0) d = this.m_LowerLimitStepSize;
|
||||
this.m_MutationStepSize = d;
|
||||
}
|
||||
public double getMutationStepSize() {
|
||||
return this.m_MutationStepSize;
|
||||
}
|
||||
public String mutationStepSizeTipText() {
|
||||
return "Choose the initial mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setLowerLimitStepSize(double d) {
|
||||
if (d < 1) d = 1;
|
||||
this.m_LowerLimitStepSize = d;
|
||||
}
|
||||
public double getLowerLimitStepSize() {
|
||||
return this.m_LowerLimitStepSize;
|
||||
}
|
||||
public String lowerLimitStepSizeTipText() {
|
||||
return "Set the lower limit for the mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the value for Alpha with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setAlpha(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Alpha = d;
|
||||
}
|
||||
public double getAlpha() {
|
||||
return this.m_Alpha;
|
||||
}
|
||||
public String alphaTipText() {
|
||||
return "Set the value for alpha.";
|
||||
}
|
||||
}
|
||||
120
src/javaeva/server/go/operators/mutation/MutateESStandard.java
Normal file
120
src/javaeva/server/go/operators/mutation/MutateESStandard.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 15.05.2003
|
||||
* Time: 17:04:24
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class MutateESStandard implements InterfaceMutation, java.io.Serializable {
|
||||
private double m_MutationStepSize = 0.1;
|
||||
|
||||
public MutateESStandard() {
|
||||
}
|
||||
|
||||
public MutateESStandard(MutateESStandard d) {
|
||||
this.m_MutationStepSize = d.m_MutationStepSize;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESStandard(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESStandard) {
|
||||
MutateESStandard mut = (MutateESStandard)mutator;
|
||||
if (this.m_MutationStepSize != mut.m_MutationStepSize) return false;
|
||||
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 InterfaceESIndividual 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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] += ((range[i][1] -range[i][0])/2)*RandomNumberGenerator.gaussianDouble(this.m_MutationStepSize);
|
||||
if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
|
||||
}
|
||||
//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 standard 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 standard mutation ";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The standart mutation alters all elements of the double attributes with a fixed mutation step size.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the fixed mutation step size
|
||||
* @param step The new mutation step size
|
||||
*/
|
||||
public void setMutationStepSize(double step) {
|
||||
this.m_MutationStepSize = step;
|
||||
}
|
||||
public double getMutationStepSize() {
|
||||
return this.m_MutationStepSize;
|
||||
}
|
||||
public String mutationStepSizeTipText() {
|
||||
return "Set the value for the fixed mutation step size.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceESIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 10.05.2005
|
||||
* Time: 14:11:49
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateESSuccessRule implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
// it would be quite nice to make this variable static, but in that case
|
||||
// no one could runs n independent ES runs in parallel anymore *sigh*
|
||||
// protected static double m_MutationStepSize = 0.2;
|
||||
protected double m_MutationStepSize = 0.2;
|
||||
protected double m_SuccessRate = 0.2;
|
||||
protected double m_Alpha = 1.2;
|
||||
|
||||
public MutateESSuccessRule() {
|
||||
|
||||
}
|
||||
public MutateESSuccessRule(MutateESSuccessRule mutator) {
|
||||
this.m_MutationStepSize = mutator.m_MutationStepSize;
|
||||
this.m_SuccessRate = mutator.m_SuccessRate;
|
||||
this.m_Alpha = mutator.m_Alpha;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateESSuccessRule(this);
|
||||
}
|
||||
|
||||
/** 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 MutateESSuccessRule) {
|
||||
MutateESSuccessRule mut = (MutateESSuccessRule)mutator;
|
||||
if (this.m_MutationStepSize != mut.m_MutationStepSize) return false;
|
||||
if (this.m_SuccessRate != mut.m_SuccessRate) return false;
|
||||
if (this.m_Alpha != mut.m_Alpha) return false;
|
||||
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) {
|
||||
double[] x = ((InterfaceESIndividual)individual).getDGenotype();
|
||||
double[][] range = ((InterfaceESIndividual)individual).getDoubleRange();
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
x[i] += ((range[i][1] -range[i][0])/2)*RandomNumberGenerator.gaussianDouble(this.m_MutationStepSize);
|
||||
if (range[i][0] > x[i]) x[i] = range[i][0];
|
||||
if (range[i][1] < x[i]) x[i] = range[i][1];
|
||||
}
|
||||
((InterfaceESIndividual)individual).SetDGenotype(x);
|
||||
|
||||
}
|
||||
//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 1/5 Success Rule mutation";
|
||||
}
|
||||
|
||||
/** This method increases the mutation step size.
|
||||
*/
|
||||
public void increaseMutationStepSize() {
|
||||
this.m_MutationStepSize = this.m_MutationStepSize * this.m_Alpha;
|
||||
}
|
||||
/** This method decrease the mutation step size.
|
||||
*/
|
||||
public void decreaseMutationStepSize() {
|
||||
this.m_MutationStepSize = this.m_MutationStepSize / this.m_Alpha;
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* 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 1/5 Success Rule mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The 1/5 success rule is something special and works only together with an ES optimizer.";
|
||||
}
|
||||
|
||||
/** Set the initial mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setInitialMutationStepSize(double d) {
|
||||
if (d < 0) d = 0.0000001;
|
||||
this.m_MutationStepSize = d;
|
||||
}
|
||||
public double getInitialMutationStepSize() {
|
||||
return this.m_MutationStepSize;
|
||||
}
|
||||
public String initialMutationStepSizeTipText() {
|
||||
return "Choose the initial mutation step size.";
|
||||
}
|
||||
|
||||
/** Set success rate (0.2 is default).
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setSuccessRate(double d) {
|
||||
if (d < 0) d = 0;
|
||||
if (d > 1) d = 1;
|
||||
this.m_SuccessRate = d;
|
||||
}
|
||||
public double getSuccessRate() {
|
||||
return this.m_SuccessRate;
|
||||
}
|
||||
public String successRateTipText() {
|
||||
return "Set success rate (0.2 is default).";
|
||||
}
|
||||
|
||||
/** Choose the factor by which the mutation step size is to be increased/decrease.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setAlpha(double d) {
|
||||
if (d < 1) d = 1;
|
||||
this.m_Alpha = d;
|
||||
}
|
||||
public double getAlpha() {
|
||||
return this.m_Alpha;
|
||||
}
|
||||
public String alphaTipText() {
|
||||
return "Choose the factor by which the mutation step size is to be increased/decreased.";
|
||||
}
|
||||
}
|
||||
160
src/javaeva/server/go/operators/mutation/MutateGAAdaptive.java
Normal file
160
src/javaeva/server/go/operators/mutation/MutateGAAdaptive.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* The mutation probability is adapted using a parameter tau and stored in the individual.
|
||||
* Better mutation probabilities are selected indirectly as they produce better offspring.
|
||||
*
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 27.05.2003
|
||||
* Time: 19:52:16
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class MutateGAAdaptive implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
protected double m_MutationStep = 1;
|
||||
protected double m_Tau1 = 0.15;
|
||||
protected double m_LowerLimitStepSize = 0.0000005;
|
||||
|
||||
public MutateGAAdaptive() {
|
||||
|
||||
}
|
||||
public MutateGAAdaptive(MutateGAAdaptive mutator) {
|
||||
this.m_MutationStep = mutator.m_MutationStep;
|
||||
this.m_Tau1 = mutator.m_Tau1;
|
||||
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGAAdaptive(this);
|
||||
}
|
||||
|
||||
/** 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 MutateGAAdaptive) {
|
||||
MutateGAAdaptive mut = (MutateGAAdaptive)mutator;
|
||||
if (this.m_MutationStep != mut.m_MutationStep) return false;
|
||||
if (this.m_Tau1 != mut.m_Tau1) return false;
|
||||
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) return false;
|
||||
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) {
|
||||
BitSet tmpBitSet = ((InterfaceGAIndividual)individual).getBGenotype();
|
||||
this.m_MutationStep = this.m_MutationStep * Math.exp(this.m_Tau1 * RandomNumberGenerator.gaussianDouble(1));
|
||||
if (this.m_MutationStep < this.m_LowerLimitStepSize) this.m_MutationStep = this.m_LowerLimitStepSize;
|
||||
for (int i = 0; i < ((InterfaceGAIndividual)individual).getGenotypeLength(); i++) {
|
||||
if (RandomNumberGenerator.flipCoin(this.m_MutationStep/((InterfaceGAIndividual)individual).getGenotypeLength())) {
|
||||
tmpBitSet.flip(i);
|
||||
}
|
||||
}
|
||||
((InterfaceGAIndividual)individual).SetBGenotype(tmpBitSet);
|
||||
}
|
||||
//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 adaptive 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 adaptive mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The standard mutation switches n bits of the GA genotype.";
|
||||
}
|
||||
|
||||
/** Set the initial mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setMutationStep(double d) {
|
||||
if (d < 0) d = this.m_LowerLimitStepSize;
|
||||
this.m_MutationStep = d;
|
||||
}
|
||||
public double getMutationStepSize() {
|
||||
return this.m_MutationStep;
|
||||
}
|
||||
public String mutationStepSizeTipText() {
|
||||
return "Choose the initial mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setLowerLimitStepSize(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_LowerLimitStepSize = d;
|
||||
}
|
||||
public double getLowerLimitStepSize() {
|
||||
return this.m_LowerLimitStepSize;
|
||||
}
|
||||
public String lowerLimitStepSizeTipText() {
|
||||
return "Set the lower limit for the mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau1(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau1 = d;
|
||||
}
|
||||
public double getTau1() {
|
||||
return this.m_Tau1;
|
||||
}
|
||||
public String tau1TipText() {
|
||||
return "Set the value for tau1.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
|
||||
|
||||
/**
|
||||
* 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.";
|
||||
}
|
||||
}
|
||||
146
src/javaeva/server/go/operators/mutation/MutateGAInvertBits.java
Normal file
146
src/javaeva/server/go/operators/mutation/MutateGAInvertBits.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 05.08.2004
|
||||
* Time: 17:47:03
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGAInvertBits implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
private int m_NumberOfMutations = 1;
|
||||
private int m_MaxInveredBits = 5;
|
||||
|
||||
public MutateGAInvertBits() {
|
||||
|
||||
}
|
||||
public MutateGAInvertBits(MutateGAInvertBits mutator) {
|
||||
this.m_NumberOfMutations = mutator.m_NumberOfMutations;
|
||||
this.m_MaxInveredBits = mutator.m_MaxInveredBits;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGAInvertBits(this);
|
||||
}
|
||||
|
||||
/** 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 MutateGAInvertBits) {
|
||||
MutateGAInvertBits mut = (MutateGAInvertBits)mutator;
|
||||
if (this.m_NumberOfMutations != mut.m_NumberOfMutations) return false;
|
||||
if (this.m_MaxInveredBits != mut.m_MaxInveredBits) return false;
|
||||
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) {
|
||||
BitSet tmpBitSet = ((InterfaceGAIndividual)individual).getBGenotype();
|
||||
int[][] mutationIndices = new int[this.m_NumberOfMutations][2];
|
||||
for (int i = 0; i < mutationIndices.length; i++) {
|
||||
mutationIndices[i][0] = RandomNumberGenerator.randomInt(0, ((InterfaceGAIndividual)individual).getGenotypeLength());;
|
||||
mutationIndices[i][1] = RandomNumberGenerator.randomInt(0, this.m_MaxInveredBits);;
|
||||
}
|
||||
// double instances of mutationIndices could be checked here... *sigh*
|
||||
for (int i = 0; i < mutationIndices.length; i++) {
|
||||
tmpBitSet.flip(mutationIndices[i][0], Math.min(((InterfaceGAIndividual)individual).getGenotypeLength(), mutationIndices[i][0]+ mutationIndices[i][1]));
|
||||
if ((mutationIndices[i][0]+ mutationIndices[i][1]) > ((InterfaceGAIndividual)individual).getGenotypeLength()) {
|
||||
tmpBitSet.flip(0, (mutationIndices[i][0]+ mutationIndices[i][1])-((InterfaceGAIndividual)individual).getGenotypeLength());
|
||||
}
|
||||
}
|
||||
((InterfaceGAIndividual)individual).SetBGenotype(tmpBitSet);
|
||||
}
|
||||
//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 inversion 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 invert n bits mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mutation operator inverts n succesive bits.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the number of mutations that occur in the
|
||||
* genotype.
|
||||
* @param mutations The number of mutations.
|
||||
*/
|
||||
public void setNumberOfMutations(int mutations) {
|
||||
if (mutations < 0) mutations = 0;
|
||||
this.m_NumberOfMutations = mutations;
|
||||
}
|
||||
public int getNumberOfMutations() {
|
||||
return this.m_NumberOfMutations;
|
||||
}
|
||||
public String numberOfMutationsTipText() {
|
||||
return "The number of inversion events.";
|
||||
}
|
||||
/** This method allows you to set the macimun number if succesively
|
||||
* inverted bits
|
||||
* @param mutations The number of successively inverted bits.
|
||||
*/
|
||||
public void setMaxInveredBits(int mutations) {
|
||||
if (mutations < 0) mutations = 0;
|
||||
this.m_MaxInveredBits = mutations;
|
||||
}
|
||||
public int getMaxInveredBits() {
|
||||
return this.m_MaxInveredBits;
|
||||
}
|
||||
public String maxInveredBitsTipText() {
|
||||
return "The number of successive bits to be inverted.";
|
||||
}
|
||||
}
|
||||
122
src/javaeva/server/go/operators/mutation/MutateGAStandard.java
Normal file
122
src/javaeva/server/go/operators/mutation/MutateGAStandard.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 03.04.2003
|
||||
* Time: 10:03:37
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class MutateGAStandard implements InterfaceMutation, java.io.Serializable {
|
||||
private int m_NumberOfMutations = 1;
|
||||
|
||||
public MutateGAStandard() {
|
||||
|
||||
}
|
||||
public MutateGAStandard(MutateGAStandard mutator) {
|
||||
this.m_NumberOfMutations = mutator.m_NumberOfMutations;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGAStandard(this);
|
||||
}
|
||||
|
||||
/** 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 MutateGAStandard) {
|
||||
MutateGAStandard mut = (MutateGAStandard)mutator;
|
||||
if (this.m_NumberOfMutations != mut.m_NumberOfMutations) return false;
|
||||
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) {
|
||||
BitSet tmpBitSet = ((InterfaceGAIndividual)individual).getBGenotype();
|
||||
int[] mutationIndices = new int[this.m_NumberOfMutations];
|
||||
for (int i = 0; i < mutationIndices.length; i++) mutationIndices[i] = RandomNumberGenerator.randomInt(0, ((InterfaceGAIndividual)individual).getGenotypeLength());;
|
||||
// double instances of mutationIndices could be checked here... *sigh*
|
||||
for (int i = 0; i < mutationIndices.length; i++) {
|
||||
tmpBitSet.flip(mutationIndices[i]);
|
||||
}
|
||||
((InterfaceGAIndividual)individual).SetBGenotype(tmpBitSet);
|
||||
}
|
||||
//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 standard 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 standard mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The standard mutation switches n bits of the GA genotype.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the number of mutations that occur in the
|
||||
* genotype.
|
||||
* @param mutations The number of mutations.
|
||||
*/
|
||||
public void setNumberOfMutations(int mutations) {
|
||||
if (mutations < 0) mutations = 0;
|
||||
this.m_NumberOfMutations = mutations;
|
||||
}
|
||||
public int getNumberOfMutations() {
|
||||
return this.m_NumberOfMutations;
|
||||
}
|
||||
public String numberOfMutationsTipText() {
|
||||
return "The number of bits to be mutated.";
|
||||
}
|
||||
}
|
||||
128
src/javaeva/server/go/operators/mutation/MutateGASwapBits.java
Normal file
128
src/javaeva/server/go/operators/mutation/MutateGASwapBits.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 05.08.2004
|
||||
* Time: 17:45:36
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGASwapBits implements InterfaceMutation, java.io.Serializable {
|
||||
private int m_NumberOfMutations = 1;
|
||||
|
||||
public MutateGASwapBits() {
|
||||
|
||||
}
|
||||
public MutateGASwapBits(MutateGASwapBits mutator) {
|
||||
this.m_NumberOfMutations = mutator.m_NumberOfMutations;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGASwapBits(this);
|
||||
}
|
||||
|
||||
/** 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 MutateGASwapBits) {
|
||||
MutateGASwapBits mut = (MutateGASwapBits)mutator;
|
||||
if (this.m_NumberOfMutations != mut.m_NumberOfMutations) return false;
|
||||
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 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 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) {
|
||||
BitSet tmpBitSet = ((InterfaceGAIndividual)individual).getBGenotype();
|
||||
int[][] mutationIndices = new int[this.m_NumberOfMutations][2];
|
||||
boolean tmpBit;
|
||||
for (int i = 0; i < mutationIndices.length; i++) {
|
||||
mutationIndices[i][0] = RandomNumberGenerator.randomInt(0, ((InterfaceGAIndividual)individual).getGenotypeLength());;
|
||||
mutationIndices[i][1] = RandomNumberGenerator.randomInt(0, ((InterfaceGAIndividual)individual).getGenotypeLength());;
|
||||
}
|
||||
// double instances of mutationIndices could be checked here... *sigh*
|
||||
for (int i = 0; i < mutationIndices.length; i++) {
|
||||
tmpBit = tmpBitSet.get(mutationIndices[i][1]);
|
||||
tmpBitSet.set(mutationIndices[i][1], tmpBitSet.get(mutationIndices[i][0]));
|
||||
tmpBitSet.set(mutationIndices[i][0], tmpBit);
|
||||
}
|
||||
((InterfaceGAIndividual)individual).SetBGenotype(tmpBitSet);
|
||||
}
|
||||
//System.out.println("After Mutate: " +((GAIndividual)individual).getSolutionRepresentationFor());
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "GA swap bits 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 swap bits mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mutation operator swaps n random bits.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the number of mutations that occur in the
|
||||
* genotype.
|
||||
* @param mutations The number of mutations.
|
||||
*/
|
||||
public void setNumberOfMutations(int mutations) {
|
||||
if (mutations < 0) mutations = 0;
|
||||
this.m_NumberOfMutations = mutations;
|
||||
}
|
||||
public int getNumberOfMutations() {
|
||||
return this.m_NumberOfMutations;
|
||||
}
|
||||
public String numberOfMutationsTipText() {
|
||||
return "The number of bits to be swapped.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGIIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.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.
|
||||
*/
|
||||
public class MutateGIDefault 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();
|
||||
}
|
||||
|
||||
/** 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 MutateGIDefault) 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 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 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";
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************
|
||||
* These are for GUI
|
||||
*/
|
||||
/** This method allows the CommonJavaObjectEditorPanel to read the
|
||||
* name to the current object.
|
||||
* @return The name.
|
||||
*/
|
||||
public String getName() {
|
||||
return "GI 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.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGIIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 30.05.2005
|
||||
* Time: 17:33:46
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGIInsertDelete implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
int m_MaxLengthOfInsDel = 2;
|
||||
|
||||
public MutateGIInsertDelete() {
|
||||
|
||||
}
|
||||
public MutateGIInsertDelete(MutateGIInsertDelete mutator) {
|
||||
this.m_MaxLengthOfInsDel = mutator.m_MaxLengthOfInsDel;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGIInsertDelete();
|
||||
}
|
||||
|
||||
/** 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 MutateGIInsertDelete) {
|
||||
MutateGIInsertDelete mut = (MutateGIInsertDelete)mutator;
|
||||
if (this.m_MaxLengthOfInsDel != mut.m_MaxLengthOfInsDel) return false;
|
||||
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 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 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) {
|
||||
int[] x = ((InterfaceGIIndividual)individual).getIGenotype();
|
||||
int[][] range = ((InterfaceGIIndividual)individual).getIntRange();
|
||||
int[] newX;
|
||||
int[][] newRange;
|
||||
int length, position;
|
||||
//this.pintInt("Before ", x);
|
||||
length = RandomNumberGenerator.randomInt(1, this.m_MaxLengthOfInsDel);
|
||||
boolean insert = RandomNumberGenerator.flipCoin(0.5);
|
||||
if ((!insert) && (length >= x.length-1)) insert = true;
|
||||
if (insert) {
|
||||
// insert
|
||||
position = RandomNumberGenerator.randomInt(0, x.length-1);
|
||||
newX = new int[x.length + length];
|
||||
newRange = new int[range.length + length][2];
|
||||
for (int i = 0; i < position; i++) {
|
||||
newX[i] = x[i];
|
||||
newRange[i] = range[i];
|
||||
}
|
||||
for (int i = position; i < position+length; i++) {
|
||||
newX[i] = RandomNumberGenerator.randomInt(range[position][0], range[position][1]);
|
||||
newRange[i][0] = range[position][0];
|
||||
newRange[i][1] = range[position][1];
|
||||
}
|
||||
for (int i = position; i < x.length; i++) {
|
||||
newX[i+length] = x[i];
|
||||
newRange[i+length] = range[i];
|
||||
}
|
||||
} else {
|
||||
// delete
|
||||
position = RandomNumberGenerator.randomInt(0, x.length-1-length);
|
||||
newX = new int[x.length - length];
|
||||
newRange = new int[range.length - length][2];
|
||||
if (newX.length <=1) return;
|
||||
for (int i = 0; i < position; i++) {
|
||||
newX[i] = x[i];
|
||||
newRange[i] = range[i];
|
||||
}
|
||||
for (int i = position + length; i < x.length; i++) {
|
||||
newX[i-length] = x[i];
|
||||
newRange[i-length] = range[i];
|
||||
}
|
||||
}
|
||||
if (newX.length <= 1) System.out.println("newX " + newX.length);
|
||||
((InterfaceGIIndividual)individual).setIntegerDataLength(newX.length);
|
||||
((InterfaceGIIndividual)individual).SetIGenotype(newX);
|
||||
((InterfaceGIIndividual)individual).SetIntRange(newRange);
|
||||
newX = ((InterfaceGIIndividual)individual).getIGenotype();
|
||||
if (newX.length <= 1) System.out.println("newX " + newX.length);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "GI insert/delete 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 "GI insert/delete mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mutation operator inserts or adds elements to the array.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the max length of the insert or deletion.
|
||||
* @param n The max length of invert
|
||||
*/
|
||||
public void setMaxLengthOfInsDel(int n) {
|
||||
this.m_MaxLengthOfInsDel = n;
|
||||
}
|
||||
public int getMaxLengthOfInsDel() {
|
||||
return this.m_MaxLengthOfInsDel;
|
||||
}
|
||||
public String maxLengthOfInsDelTipText() {
|
||||
return "Gives the maximum length of an inserted or deleted segment.";
|
||||
}
|
||||
}
|
||||
132
src/javaeva/server/go/operators/mutation/MutateGIInvert.java
Normal file
132
src/javaeva/server/go/operators/mutation/MutateGIInvert.java
Normal file
@@ -0,0 +1,132 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGIIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 19.05.2005
|
||||
* Time: 16:15:20
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGIInvert implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
int m_MaxLengthOfInvert = 2;
|
||||
|
||||
public MutateGIInvert() {
|
||||
|
||||
}
|
||||
public MutateGIInvert(MutateGIInvert mutator) {
|
||||
this.m_MaxLengthOfInvert = mutator.m_MaxLengthOfInvert;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGIInvert();
|
||||
}
|
||||
|
||||
/** 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 MutateGIInvert) {
|
||||
MutateGIInvert mut = (MutateGIInvert)mutator;
|
||||
if (this.m_MaxLengthOfInvert != mut.m_MaxLengthOfInvert) return false;
|
||||
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) {
|
||||
if (individual instanceof InterfaceGIIndividual) {
|
||||
int[] x = ((InterfaceGIIndividual)individual).getIGenotype();
|
||||
int range, center, index = 0;
|
||||
//this.pintInt("Before ", x);
|
||||
range = RandomNumberGenerator.randomInt(1, this.m_MaxLengthOfInvert);
|
||||
if (2*range >= x.length) return;
|
||||
center = RandomNumberGenerator.randomInt(0+range, x.length-1-range);
|
||||
//System.out.println("Range: " + range + " Center: " + center);
|
||||
int[] tmp = new int[x.length];
|
||||
System.arraycopy(x, 0, tmp, 0, x.length);
|
||||
for (int i = center-range; i < center+range; i++) {
|
||||
x[center -1 + range - index] = tmp[i];
|
||||
index++;
|
||||
}
|
||||
//this.pintInt("After ", tmp);
|
||||
//this.pintInt("After ", x);
|
||||
((InterfaceGIIndividual)individual).SetIGenotype(x);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
}
|
||||
|
||||
private void pintInt(String s, int[] x) {
|
||||
String tmp = "{"+x[0];
|
||||
for (int i = 1; i < x.length; i++) tmp += ", "+x[i];
|
||||
System.out.println(s+tmp+"}");
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "GI invert 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 "GI invert mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The invert mutation inverts a segment of the int[].";
|
||||
}
|
||||
|
||||
/** This method allows you to set the max length of invert.
|
||||
* @param n The max length of invert
|
||||
*/
|
||||
public void setMaxLengthOfInvert(int n) {
|
||||
this.m_MaxLengthOfInvert = n;
|
||||
}
|
||||
public int getMaxLengthOfInvert() {
|
||||
return this.m_MaxLengthOfInvert;
|
||||
}
|
||||
public String maxLengthOfInvertTipText() {
|
||||
return "Gives half the maximum length of an inverted segment.";
|
||||
}
|
||||
}
|
||||
122
src/javaeva/server/go/operators/mutation/MutateGINominal.java
Normal file
122
src/javaeva/server/go/operators/mutation/MutateGINominal.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGIIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 19.05.2005
|
||||
* Time: 16:02:32
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGINominal implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
int m_NumberOfMutations = 2;
|
||||
|
||||
public MutateGINominal() {
|
||||
|
||||
}
|
||||
public MutateGINominal(MutateGINominal mutator) {
|
||||
this.m_NumberOfMutations = mutator.m_NumberOfMutations;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGINominal();
|
||||
}
|
||||
|
||||
/** 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 MutateGINominal) {
|
||||
MutateGINominal mut = (MutateGINominal)mutator;
|
||||
if (this.m_NumberOfMutations != mut.m_NumberOfMutations) return false;
|
||||
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) {
|
||||
if (individual instanceof InterfaceGIIndividual) {
|
||||
int[] x = ((InterfaceGIIndividual)individual).getIGenotype();
|
||||
int[][] range = ((InterfaceGIIndividual)individual).getIntRange();
|
||||
int mutInd = 0;
|
||||
for (int k = 0; k < this.m_NumberOfMutations; k++) {
|
||||
try {
|
||||
mutInd = RandomNumberGenerator.randomInt(0, x.length-1);
|
||||
} catch (java.lang.ArithmeticException e) {
|
||||
System.out.println("x.length " + x.length);
|
||||
}
|
||||
x[mutInd] = RandomNumberGenerator.randomInt(range[mutInd][0], range[mutInd][1]);
|
||||
}
|
||||
((InterfaceGIIndividual)individual).SetIGenotype(x);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 "GI nominal 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 "GI nominal mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The nominal mutation alters n element of the int attributes completely at random.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the number of mutations to occur.
|
||||
* @param n The number of mutations
|
||||
*/
|
||||
public void setNumberOfMutations(int n) {
|
||||
this.m_NumberOfMutations = n;
|
||||
}
|
||||
public int getNumberOfMutations() {
|
||||
return this.m_NumberOfMutations;
|
||||
}
|
||||
public String numberOfMutationsTipText() {
|
||||
return "Gives the number of mutations.";
|
||||
}
|
||||
}
|
||||
144
src/javaeva/server/go/operators/mutation/MutateGIOrdinal.java
Normal file
144
src/javaeva/server/go/operators/mutation/MutateGIOrdinal.java
Normal file
@@ -0,0 +1,144 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGIIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 19.05.2005
|
||||
* Time: 15:53:03
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
double m_StepSize = 0.1;
|
||||
int m_NumberOfMutations = 2;
|
||||
|
||||
public MutateGIOrdinal() {
|
||||
|
||||
}
|
||||
public MutateGIOrdinal(MutateGIOrdinal mutator) {
|
||||
this.m_StepSize = mutator.m_StepSize;
|
||||
this.m_NumberOfMutations = mutator.m_NumberOfMutations;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGIOrdinal();
|
||||
}
|
||||
|
||||
/** 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 MutateGIOrdinal) {
|
||||
MutateGIOrdinal mut = (MutateGIOrdinal)mutator;
|
||||
if (this.m_StepSize != mut.m_StepSize) return false;
|
||||
if (this.m_NumberOfMutations != mut.m_NumberOfMutations) return false;
|
||||
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) {
|
||||
if (individual instanceof InterfaceGIIndividual) {
|
||||
int[] x = ((InterfaceGIIndividual)individual).getIGenotype();
|
||||
int[][] range = ((InterfaceGIIndividual)individual).getIntRange();
|
||||
int mutInd, mut;
|
||||
double mutate;
|
||||
for (int k = 0; k < this.m_NumberOfMutations; k++) {
|
||||
mutInd = RandomNumberGenerator.randomInt(0, x.length-1);
|
||||
mutate = RandomNumberGenerator.gaussianDouble(this.m_StepSize);
|
||||
mutate = mutate * (range[mutInd][1] - range[mutInd][1]);
|
||||
mut = (int)Math.round(mutate);
|
||||
if (mut == 0) {
|
||||
if (RandomNumberGenerator.flipCoin(0.5)) mut = -1;
|
||||
else mut = 1;
|
||||
}
|
||||
x[mutInd] += mut;
|
||||
if (x[mutInd] < range[mutInd][0]) x[mutInd] = range[mutInd][0];
|
||||
if (x[mutInd] > range[mutInd][1]) x[mutInd] = range[mutInd][1];
|
||||
}
|
||||
((InterfaceGIIndividual)individual).SetIGenotype(x);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 "GI ordinal 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 "GI ordinal mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The ordinal mutation alters n element of the int attributes based on an oridinal ordering.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the mean step size.
|
||||
* @param n The step size
|
||||
*/
|
||||
public void setStepSize(double n) {
|
||||
this.m_StepSize = n;
|
||||
}
|
||||
public double getStepSize() {
|
||||
return this.m_StepSize;
|
||||
}
|
||||
public String stepSizeTipText() {
|
||||
return "Gives the mean step size on a normalized search space.";
|
||||
}
|
||||
|
||||
/** This method allows you to set the number of mutations to occur.
|
||||
* @param n The number of mutations
|
||||
*/
|
||||
public void setNumberOfMutations(int n) {
|
||||
this.m_NumberOfMutations = n;
|
||||
}
|
||||
public int getNumberOfMutations() {
|
||||
return this.m_NumberOfMutations;
|
||||
}
|
||||
public String numberOfMutationsTipText() {
|
||||
return "Gives the number of mutations.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGIIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 19.05.2005
|
||||
* Time: 16:15:37
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGITranslocate implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
int m_MaxLengthOfTranslocate = 4;
|
||||
|
||||
public MutateGITranslocate() {
|
||||
|
||||
}
|
||||
public MutateGITranslocate(MutateGITranslocate mutator) {
|
||||
this.m_MaxLengthOfTranslocate = mutator.m_MaxLengthOfTranslocate;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGITranslocate();
|
||||
}
|
||||
|
||||
/** 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 MutateGITranslocate) {
|
||||
MutateGITranslocate mut = (MutateGITranslocate)mutator;
|
||||
if (this.m_MaxLengthOfTranslocate != mut.m_MaxLengthOfTranslocate) return false;
|
||||
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) {
|
||||
if (individual instanceof InterfaceGIIndividual) {
|
||||
int[] x = ((InterfaceGIIndividual)individual).getIGenotype();
|
||||
int from, to, length;
|
||||
length = RandomNumberGenerator.randomInt(1, this.m_MaxLengthOfTranslocate);
|
||||
if (x.length < length+2) return;
|
||||
from = RandomNumberGenerator.randomInt(0, x.length - 1 - length);
|
||||
to = RandomNumberGenerator.randomInt(0, x.length - 1 - length);
|
||||
//this.pintInt("Before ", x);
|
||||
int[] tmp = new int[x.length];
|
||||
int[] without = new int[x.length - length];
|
||||
int[] insert = new int[length];
|
||||
for (int i = 0; i < length; i++) insert[i] = x[i+from];
|
||||
for (int i = 0; i < without.length; i++) {
|
||||
if (i < from) without[i] = x[i];
|
||||
else without[i] = x[i+length];
|
||||
}
|
||||
for (int i = 0; i < to; i++) {
|
||||
tmp[i] = without[i];
|
||||
}
|
||||
for (int i = to; i < to+length; i++) {
|
||||
tmp[i] = insert[i-to];
|
||||
}
|
||||
for (int i = to+length; i < x.length; i++) {
|
||||
tmp[i] = without[i-length];
|
||||
}
|
||||
//System.out.println(""+from+"/"+to+"/"+length);
|
||||
//this.pintInt("After ", tmp);
|
||||
((InterfaceGIIndividual)individual).SetIGenotype(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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
|
||||
}
|
||||
|
||||
private void pintInt(String s, int[] x) {
|
||||
String tmp = "{"+x[0];
|
||||
for (int i = 1; i < x.length; i++) tmp += ", "+x[i];
|
||||
System.out.println(s+tmp+"}");
|
||||
}
|
||||
|
||||
/** This method allows you to get a string representation of the mutation
|
||||
* operator
|
||||
* @return A descriptive string.
|
||||
*/
|
||||
public String getStringRepresentation() {
|
||||
return "GI translocation 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 "GI translocation mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mutation translocates a segment of the int[].";
|
||||
}
|
||||
|
||||
/** This method allows you to set the max length of invert.
|
||||
* @param n The max length of invert
|
||||
*/
|
||||
public void setMaxLengthOfTranslocate(int n) {
|
||||
this.m_MaxLengthOfTranslocate = n;
|
||||
}
|
||||
public int getMaxLengthOfTranslocate() {
|
||||
return this.m_MaxLengthOfTranslocate;
|
||||
}
|
||||
public String maxLengthOfTranslocateTipText() {
|
||||
return "Gives the maximum length of the translocated segment.";
|
||||
}
|
||||
}
|
||||
169
src/javaeva/server/go/operators/mutation/MutateGPAdaptive.java
Normal file
169
src/javaeva/server/go/operators/mutation/MutateGPAdaptive.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGPIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 11.06.2003
|
||||
* Time: 16:52:48
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class MutateGPAdaptive implements InterfaceMutation, java.io.Serializable {
|
||||
protected double m_MutationStep = 1;
|
||||
protected double m_Tau1 = 0.15;
|
||||
protected double m_Tau2 = 0.15;
|
||||
protected double m_LowerLimitStepSize = 0.0000005;
|
||||
|
||||
public MutateGPAdaptive() {
|
||||
|
||||
}
|
||||
public MutateGPAdaptive(MutateGPAdaptive mutator) {
|
||||
this.m_MutationStep = mutator.m_MutationStep;
|
||||
this.m_Tau1 = mutator.m_Tau1;
|
||||
this.m_Tau2 = mutator.m_Tau2;
|
||||
this.m_LowerLimitStepSize = mutator.m_LowerLimitStepSize;
|
||||
}
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGPAdaptive(this);
|
||||
}
|
||||
|
||||
/** 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 MutateGPAdaptive) {
|
||||
MutateGPAdaptive mut = (MutateGPAdaptive)mutator;
|
||||
if (this.m_MutationStep != mut.m_MutationStep) return false;
|
||||
if (this.m_Tau1 != mut.m_Tau1) return false;
|
||||
if (this.m_Tau2 != mut.m_Tau2) return false;
|
||||
if (this.m_LowerLimitStepSize != mut.m_LowerLimitStepSize) return false;
|
||||
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 InterfaceGPIndividual) {
|
||||
this.m_MutationStep = this.m_MutationStep * Math.exp(this.m_Tau1 * RandomNumberGenerator.gaussianDouble(1) + this.m_Tau2 * RandomNumberGenerator.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 (RandomNumberGenerator.flipCoin(this.m_MutationStep)) ((InterfaceGPIndividual)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 "GP adaptive 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 adaptive mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mutation replaces a random node with a new random subtree.";
|
||||
}
|
||||
|
||||
/** Set the initial mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setMutationStep(double d) {
|
||||
if (d < 0) d = this.m_LowerLimitStepSize;
|
||||
this.m_MutationStep = d;
|
||||
}
|
||||
public double getMutationStepSize() {
|
||||
return this.m_MutationStep;
|
||||
}
|
||||
public String mutationStepSizeTipText() {
|
||||
return "Choose the initial mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the lower limit for the mutation step size with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setLowerLimitStepSize(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_LowerLimitStepSize = d;
|
||||
}
|
||||
public double getLowerLimitStepSize() {
|
||||
return this.m_LowerLimitStepSize;
|
||||
}
|
||||
public String lowerLimitStepSizeTipText() {
|
||||
return "Set the lower limit for the mutation step size.";
|
||||
}
|
||||
|
||||
/** Set the value for tau1 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau1(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau1 = d;
|
||||
}
|
||||
public double getTau1() {
|
||||
return this.m_Tau1;
|
||||
}
|
||||
public String tau1TipText() {
|
||||
return "Set the value for tau1.";
|
||||
}
|
||||
|
||||
/** Set the value for tau2 with this method.
|
||||
* @param d The mutation operator.
|
||||
*/
|
||||
public void setTau2(double d) {
|
||||
if (d < 0) d = 0;
|
||||
this.m_Tau2 = d;
|
||||
}
|
||||
public double getTau2() {
|
||||
return this.m_Tau2;
|
||||
}
|
||||
public String tau2TipText() {
|
||||
return "Set the value for tau2.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceGPIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.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.";
|
||||
}
|
||||
}
|
||||
117
src/javaeva/server/go/operators/mutation/MutateGPSingleNode.java
Normal file
117
src/javaeva/server/go/operators/mutation/MutateGPSingleNode.java
Normal file
@@ -0,0 +1,117 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypeProgram;
|
||||
import javaeva.server.go.individuals.InterfaceGPIndividual;
|
||||
import javaeva.server.go.individuals.codings.gp.AbstractGPNode;
|
||||
import javaeva.server.go.individuals.codings.gp.GPArea;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 09.09.2004
|
||||
* Time: 17:08:37
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class MutateGPSingleNode implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new MutateGPSingleNode();
|
||||
}
|
||||
|
||||
/** 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 MutateGPSingleNode) 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) {
|
||||
ArrayList allNodes = new ArrayList();
|
||||
AbstractGPNode[] programs = ((InterfaceGPIndividual)individual).getPGenotype();
|
||||
GPArea[] areas = (GPArea[])((InterfaceGPIndividual)individual).getFunctionArea();
|
||||
for (int i = 0; i < programs.length; i++) {
|
||||
programs[i].addNodesTo(allNodes);
|
||||
AbstractGPNode nodeToMutate = (AbstractGPNode) allNodes.get(RandomNumberGenerator.randomInt(0, allNodes.size()-1));
|
||||
int orgArity = nodeToMutate.getArity();
|
||||
AbstractGPNode newNode = (AbstractGPNode)areas[i].getRandomNodeWithArity(orgArity).clone();
|
||||
// System.out.println("OldNode "+ nodeToMutate.getName() + ":"+nodeToMutate.getArity() + " / NewNode "+newNode.getName() + ":"+newNode.getArity());
|
||||
AbstractGPNode parent = nodeToMutate.getParent();
|
||||
if (parent != null) {
|
||||
newNode.setParent(parent);
|
||||
} else {
|
||||
((InterfaceGPIndividual)individual).SetPGenotype(newNode, i);
|
||||
}
|
||||
// now reconnect the children
|
||||
newNode.initNodeArray();
|
||||
for (int j = 0; j < nodeToMutate.getArity(); j++) {
|
||||
if (nodeToMutate.getNode(j) == null) {
|
||||
System.out.println("j"+j);
|
||||
}
|
||||
newNode.setNode(nodeToMutate.getNode(j), j);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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 node 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 node mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "The node mutation replaces a random node but keeps the descendants.";
|
||||
}
|
||||
}
|
||||
107
src/javaeva/server/go/operators/mutation/MutateOBGAFlip.java
Normal file
107
src/javaeva/server/go/operators/mutation/MutateOBGAFlip.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypePermutation;
|
||||
import javaeva.server.go.individuals.InterfaceOBGAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Title: The JavaEvA</p>
|
||||
*
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* <p>Copyright: Copyright (c) 2003</p>
|
||||
*
|
||||
* <p>Company: </p>
|
||||
* Mutates a permutation by flipping edges a given nubmer of times.
|
||||
*
|
||||
* @author planatsc
|
||||
* @version 1.0
|
||||
*/
|
||||
public class MutateOBGAFlip implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
/**
|
||||
* times How many edges getting flipped by the mutation.
|
||||
*/
|
||||
int times = 2;
|
||||
|
||||
public MutateOBGAFlip() {
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** 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 MutateOBGAFlip) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
|
||||
//nothing to init
|
||||
}
|
||||
|
||||
public void mutate(AbstractEAIndividual individual) {
|
||||
|
||||
int[][] perm = ( (InterfaceOBGAIndividual) individual).
|
||||
getOBGenotype();
|
||||
for (int p = 0; p < perm.length; p++) {
|
||||
for (int i = 0; i < times; i++) {
|
||||
int p1 = RandomNumberGenerator.randomInt(0, perm[p].length - 1);
|
||||
int p2 = RandomNumberGenerator.randomInt(0, perm[p].length - 1);
|
||||
int temp = perm[p][p1];
|
||||
perm[p][p1] = perm[p][p2];
|
||||
perm[p][p2] = temp;
|
||||
}
|
||||
}
|
||||
( (InterfaceOBGAIndividual) individual).SetOBGenotype(perm);
|
||||
}
|
||||
|
||||
/** 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 "OBGA flip 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 "OBGA flip mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mutation operators flips edges of the OBGA.";
|
||||
}
|
||||
public int getTimes() {
|
||||
return times;
|
||||
}
|
||||
public void setTimes(int times) {
|
||||
this.times = times;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.individuals.InterfaceDataTypePermutation;
|
||||
import javaeva.server.go.individuals.InterfaceOBGAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
import javaeva.server.go.tools.RandomNumberGenerator;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Title: The JavaEvA</p>
|
||||
* <p>Description: </p>
|
||||
* <p>Copyright: Copyright (c) 2003</p>
|
||||
* <p>Company: </p>
|
||||
* @author planatsc
|
||||
* @version 1.0
|
||||
*
|
||||
* Mutates a permutation by inversion a part of the permutation.
|
||||
* <br><br>
|
||||
* <b>Example: </b>
|
||||
* <pre>
|
||||
* 1 2 | 3 4 5 | 6 7 8 9 ->
|
||||
* 1 2 | 5 4 3 | 6 7 8 9
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
|
||||
public class MutateOBGAInversion implements java.io.Serializable, InterfaceMutation {
|
||||
|
||||
public MutateOBGAInversion() {
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** 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 MutateOBGAInversion) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
|
||||
//nothing to init
|
||||
}
|
||||
|
||||
public void mutate(AbstractEAIndividual individual) {
|
||||
int[][] permnew = (int[][]) ((InterfaceOBGAIndividual) individual). getOBGenotype().clone();
|
||||
int[][] perm = ((InterfaceDataTypePermutation) individual).getPermutationData();
|
||||
for (int p = 0; p < perm.length; p++) {
|
||||
int p1 = RandomNumberGenerator.randomInt(0, perm[p].length - 1);
|
||||
int p2 = RandomNumberGenerator.randomInt(p1, perm[p].length - 1);
|
||||
for (int i = 0; i <= (p2-p1); i++) {
|
||||
permnew[p][p1+i] = perm[p][p2-i];
|
||||
}
|
||||
}
|
||||
( (InterfaceOBGAIndividual) individual).SetOBGenotype(permnew);
|
||||
}
|
||||
|
||||
/** 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 "OBGA inversion 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 "OBGA inversion mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This mutation operators inverts a certain section of the OBGA.";
|
||||
}
|
||||
|
||||
}
|
||||
81
src/javaeva/server/go/operators/mutation/NoMutation.java
Normal file
81
src/javaeva/server/go/operators/mutation/NoMutation.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
|
||||
import javaeva.server.go.individuals.AbstractEAIndividual;
|
||||
import javaeva.server.go.populations.Population;
|
||||
import javaeva.server.go.problems.InterfaceOptimizationProblem;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 25.03.2003
|
||||
* Time: 11:42:42
|
||||
* To change this template use Options | File Templates.
|
||||
*/
|
||||
public class NoMutation implements InterfaceMutation, java.io.Serializable {
|
||||
|
||||
/** This method will enable you to clone a given mutation operator
|
||||
* @return The clone
|
||||
*/
|
||||
public Object clone() {
|
||||
return new NoMutation();
|
||||
}
|
||||
|
||||
/** 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 NoMutation) 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) {
|
||||
}
|
||||
|
||||
/** 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 "No 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 "No mutation";
|
||||
}
|
||||
/** This method returns a global info string
|
||||
* @return description
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "This thing does nothing, really!";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 20.05.2005
|
||||
* Time: 13:54:25
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyMutationMixer implements java.io.Serializable {
|
||||
|
||||
public InterfaceMutation[] m_AvailableTargets;
|
||||
public InterfaceMutation[] m_SelectedTargets;
|
||||
public double[] m_Weights;
|
||||
public String m_DescriptiveString = "No Description given.";
|
||||
public String m_WeightsLabel = "-";
|
||||
public boolean m_NormalizationEnabled = true;
|
||||
|
||||
public PropertyMutationMixer(InterfaceMutation[] d) {
|
||||
this.m_Weights = new double[d.length];
|
||||
for (int i = 0; i < d.length; i++) this.m_Weights[i] = 1/((double)d.length);
|
||||
this.m_AvailableTargets = d;
|
||||
this.m_SelectedTargets = null;
|
||||
}
|
||||
public PropertyMutationMixer(PropertyMutationMixer d) {
|
||||
this.m_DescriptiveString = d.m_DescriptiveString;
|
||||
this.m_WeightsLabel = d.m_WeightsLabel;
|
||||
this.m_NormalizationEnabled = d.m_NormalizationEnabled;
|
||||
this.m_AvailableTargets = new InterfaceMutation[d.m_AvailableTargets.length];
|
||||
for (int i = 0; i < this.m_AvailableTargets.length; i++) {
|
||||
//this.m_AvailableTargets[i] = (InterfaceMutation)d.m_AvailableTargets[i].clone();
|
||||
this.m_AvailableTargets[i] = d.m_AvailableTargets[i];
|
||||
}
|
||||
this.m_SelectedTargets = new InterfaceMutation[d.m_SelectedTargets.length];
|
||||
for (int i = 0; i < this.m_SelectedTargets.length; i++) {
|
||||
this.m_SelectedTargets[i] = (InterfaceMutation)d.m_SelectedTargets[i].clone();
|
||||
}
|
||||
if (d.m_Weights != null) {
|
||||
this.m_Weights = new double[d.m_Weights.length];
|
||||
System.arraycopy(d.m_Weights, 0, this.m_Weights, 0, this.m_Weights.length);
|
||||
}
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return (Object) new PropertyMutationMixer(this);
|
||||
}
|
||||
|
||||
/** This method will allow you to set the value of the InterfaceOptimizationTarget array
|
||||
* @param d The InterfaceOptimizationTarget[]
|
||||
*/
|
||||
public void setSelectedMutators(InterfaceMutation[] d) {
|
||||
this.m_SelectedTargets = d;
|
||||
|
||||
if (this.m_Weights == null) {
|
||||
this.m_Weights = new double[d.length];
|
||||
for (int i = 0; i < this.m_Weights.length; i++) this.m_Weights[i] = 1/((double)d.length);
|
||||
return;
|
||||
}
|
||||
|
||||
if (d.length == this.m_Weights.length) return;
|
||||
|
||||
if (d.length > this.m_Weights.length) {
|
||||
double[] newWeights = new double[d.length];
|
||||
for (int i = 0; i < this.m_Weights.length; i++) newWeights[i] = this.m_Weights[i];
|
||||
this.m_Weights = newWeights;
|
||||
} else {
|
||||
double[] newWeights = new double[d.length];
|
||||
for (int i = 0; i < d.length; i++) newWeights[i] = this.m_Weights[i];
|
||||
this.m_Weights = newWeights;
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will return the InterfaceOptimizationTarget array
|
||||
* @return The InterfaceOptimizationTarget[].
|
||||
*/
|
||||
public InterfaceMutation[] getSelectedMutators() {
|
||||
return this.m_SelectedTargets;
|
||||
}
|
||||
|
||||
/** This method will return the InterfaceOptimizationTarget array
|
||||
* @return The InterfaceOptimizationTarget[].
|
||||
*/
|
||||
public InterfaceMutation[] getAvailableMutators() {
|
||||
return this.m_AvailableTargets;
|
||||
}
|
||||
|
||||
/** This method allows you to read the weights
|
||||
* @return the weights
|
||||
*/
|
||||
public double[] getWeights() {
|
||||
return this.m_Weights;
|
||||
}
|
||||
public void setWeights(double[] d) {
|
||||
this.m_Weights = d;
|
||||
for (int i = 0; i < this.m_Weights.length; i++) this.m_Weights[i] = Math.abs(this.m_Weights[i]);
|
||||
}
|
||||
|
||||
/** This method allows you to set/get the descriptive string
|
||||
* @return the string
|
||||
*/
|
||||
public String getDescriptiveString() {
|
||||
return this.m_DescriptiveString;
|
||||
}
|
||||
public void setDescriptiveString(String d) {
|
||||
this.m_DescriptiveString = d;
|
||||
}
|
||||
|
||||
/** This method allows you to set/get the weights label
|
||||
* @return the string
|
||||
*/
|
||||
public String getWeigthsLabel() {
|
||||
return this.m_WeightsLabel;
|
||||
}
|
||||
public void setWeightsLabel(String d) {
|
||||
this.m_WeightsLabel = d;
|
||||
}
|
||||
|
||||
public void normalizeWeights() {
|
||||
double sum = 0;
|
||||
for (int i = 0; i < this.m_Weights.length; i++) {
|
||||
sum += this.m_Weights[i];
|
||||
}
|
||||
if (sum > 0) {
|
||||
for (int i = 0; i < this.m_Weights.length; i++) {
|
||||
this.m_Weights[i] = this.m_Weights[i]/sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method allows you to remove a Target from the list
|
||||
* @param index The index of the target to be removed.
|
||||
*/
|
||||
public void removeMutator(int index) {
|
||||
if ((index < 0) || (index >= this.m_SelectedTargets.length)) return;
|
||||
|
||||
InterfaceMutation[] newList = new InterfaceMutation[this.m_SelectedTargets.length-1];
|
||||
double[] newWeights = new double[this.m_Weights.length - 1];
|
||||
int j = 0;
|
||||
for (int i = 0; i < this.m_SelectedTargets.length; i++) {
|
||||
if (index != i) {
|
||||
newList[j] = this.m_SelectedTargets[i];
|
||||
newWeights[j] = this.m_Weights[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
this.m_SelectedTargets = newList;
|
||||
this.m_Weights = newWeights;
|
||||
}
|
||||
|
||||
/** This method allows you to add a new target to the list
|
||||
* @param optTarget
|
||||
*/
|
||||
public void addMutator(InterfaceMutation optTarget) {
|
||||
InterfaceMutation[] newList = new InterfaceMutation[this.m_SelectedTargets.length+1];
|
||||
double[] newWeights = new double[this.m_Weights.length + 1];
|
||||
for (int i = 0; i < this.m_SelectedTargets.length; i++) {
|
||||
newList[i] = this.m_SelectedTargets[i];
|
||||
newWeights[i] = this.m_Weights[i];
|
||||
}
|
||||
newList[this.m_SelectedTargets.length] = optTarget;
|
||||
newWeights[this.m_SelectedTargets.length] = 1.0;
|
||||
this.m_SelectedTargets = newList;
|
||||
this.m_Weights = newWeights;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
package javaeva.server.go.operators.mutation;
|
||||
|
||||
import javaeva.server.go.tools.GeneralGEOFaker;
|
||||
import javaeva.server.go.tools.GeneralGOEProperty;
|
||||
import javaeva.gui.*;
|
||||
import javax.swing.*;
|
||||
import java.beans.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import wsi.ra.tool.BasicResourceLoader;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: streiche
|
||||
* Date: 20.05.2005
|
||||
* Time: 13:56:36
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class PropertyMutationMixerEditor extends JPanel implements PropertyEditor, java.beans.PropertyChangeListener {
|
||||
|
||||
/** Handles property change notification */
|
||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||
/** The label for when we can't edit that type */
|
||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||
/** The FilePath that is to be edited*/
|
||||
private PropertyMutationMixer m_MutatorsWithWeights;
|
||||
|
||||
/** The gaphix stuff */
|
||||
private JComponent m_Editor;
|
||||
private JPanel m_TargetList;
|
||||
private JTextField[] m_Weights;
|
||||
private JComponent[] m_Targets;
|
||||
private JButton[] m_Delete;
|
||||
private JScrollPane m_ScrollTargets;
|
||||
private GeneralGOEProperty[] m_Editors;
|
||||
private GeneralGEOFaker m_Component;
|
||||
private PropertyChangeListener m_self;
|
||||
|
||||
public PropertyMutationMixerEditor() {
|
||||
m_self = this;
|
||||
}
|
||||
|
||||
/** This method will init the CustomEditor Panel
|
||||
*/
|
||||
private void initCustomEditor() {
|
||||
m_self = this;
|
||||
this.m_Editor = new JPanel();
|
||||
this.m_Editor.setPreferredSize(new Dimension(450, 200));
|
||||
this.m_Editor.setMinimumSize(new Dimension(450, 200));
|
||||
|
||||
// init the editors
|
||||
InterfaceMutation[] list = this.m_MutatorsWithWeights.getSelectedMutators();
|
||||
this.m_Editors = new GeneralGOEProperty[list.length];
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
this.m_Editors[i] = new GeneralGOEProperty();
|
||||
this.m_Editors[i].m_Name = list[i].getStringRepresentation();
|
||||
try {
|
||||
this.m_Editors[i].m_Value = list[i];
|
||||
this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(this.m_Editors[i].m_Value.getClass());
|
||||
if (this.m_Editors[i].m_Editor == null) this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(InterfaceMutation.class);
|
||||
if (this.m_Editors[i].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) this.m_Editors[i].m_Editor).setClassType(InterfaceMutation.class);
|
||||
this.m_Editors[i].m_Editor.setValue(this.m_Editors[i].m_Value);
|
||||
this.m_Editors[i].m_Editor.addPropertyChangeListener(this);
|
||||
this.findViewFor(this.m_Editors[i]);
|
||||
if (this.m_Editors[i].m_View != null) this.m_Editors[i].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
}
|
||||
this.m_TargetList = new JPanel();
|
||||
this.updateTargetList();
|
||||
this.m_ScrollTargets = new JScrollPane(this.m_TargetList);
|
||||
|
||||
this.m_Editor.setLayout(new BorderLayout());
|
||||
this.m_Editor.add(this.m_ScrollTargets, BorderLayout.CENTER);
|
||||
|
||||
// The Button Panel
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new GridLayout(1,2));
|
||||
JButton addButton = new JButton("Add Mutator");
|
||||
JButton normButton = new JButton("Normalize Propabilities");
|
||||
normButton.setEnabled(true);
|
||||
normButton.addActionListener(normalizeWeights);
|
||||
addButton.addActionListener(addTarget);
|
||||
buttonPanel.add(normButton);
|
||||
buttonPanel.add(addButton);
|
||||
|
||||
this.m_Editor.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Some description would be nice
|
||||
JTextArea jt = new JTextArea();
|
||||
jt.setFont(new Font("SansSerif", Font.PLAIN,12));
|
||||
jt.setEditable(false);
|
||||
jt.setLineWrap(true);
|
||||
jt.setWrapStyleWord(true);
|
||||
jt.setText(this.m_MutatorsWithWeights.getDescriptiveString());
|
||||
jt.setBackground(getBackground());
|
||||
JPanel jp = new JPanel();
|
||||
jp.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Info"),
|
||||
BorderFactory.createEmptyBorder(0, 5, 5, 5)
|
||||
));
|
||||
jp.setLayout(new BorderLayout());
|
||||
jp.add(jt, BorderLayout.CENTER);
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new BorderLayout());
|
||||
JButton help = new JButton("Help");
|
||||
help.setEnabled(false);
|
||||
p2.add(help, BorderLayout.NORTH);
|
||||
jp.add(p2, BorderLayout.EAST);
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
|
||||
this.m_Editor.add(jp, BorderLayout.NORTH);
|
||||
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
/** This method updates the server list
|
||||
*
|
||||
*/
|
||||
private void updateTargetList() {
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes;
|
||||
InterfaceMutation[] list = this.m_MutatorsWithWeights.getSelectedMutators();
|
||||
double[] weights = this.m_MutatorsWithWeights.getWeights();
|
||||
|
||||
this.m_TargetList.removeAll();
|
||||
this.m_TargetList.setLayout(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
this.m_Weights = new JTextField[list.length];
|
||||
this.m_Targets = new JComponent[list.length];
|
||||
this.m_Delete = new JButton[list.length];
|
||||
String[] cups = new String[8];
|
||||
for (int i = 0; i < cups.length; i++) cups[i] = ""+(i+1);
|
||||
// The head title
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 2;
|
||||
this.m_TargetList.add(new JLabel(this.m_MutatorsWithWeights.getWeigthsLabel()), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 10;
|
||||
this.m_TargetList.add(new JLabel("Target"), gbc);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 1;
|
||||
this.m_TargetList.add(new JLabel("Remove"), gbc);
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
// the weight
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 0;
|
||||
gbc.weightx = 2;
|
||||
this.m_Weights[i] = new JTextField(""+weights[i]);
|
||||
this.m_Weights[i].addKeyListener(this.readDoubleArrayAction);
|
||||
this.m_TargetList.add(this.m_Weights[i], gbc);
|
||||
// the status indicator
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 10;
|
||||
this.m_Targets[i] = this.m_Editors[i].m_View;
|
||||
this.m_TargetList.add(this.m_Targets[i], gbc);
|
||||
// The delete button
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 1;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
try {
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find sub24 icon, please move rescoure folder to working directory!");
|
||||
this.m_Delete[i] = new JButton("Sub");
|
||||
}
|
||||
this.m_Delete[i].addActionListener(deleteTarget);
|
||||
this.m_TargetList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
this.m_TargetList.repaint();
|
||||
this.m_TargetList.validate();
|
||||
if (this.m_ScrollTargets != null) {
|
||||
this.m_ScrollTargets.validate();
|
||||
this.m_ScrollTargets.repaint();
|
||||
}
|
||||
if (this.m_Editor != null) {
|
||||
this.m_Editor.validate();
|
||||
this.m_Editor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener updateTargets = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener addTarget = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_MutatorsWithWeights.addMutator((InterfaceMutation)m_MutatorsWithWeights.getAvailableMutators()[0].clone());
|
||||
int l = m_MutatorsWithWeights.getSelectedMutators().length;
|
||||
GeneralGOEProperty[] newEdit = new GeneralGOEProperty[l];
|
||||
for (int i = 0; i < m_Editors.length; i++) {
|
||||
newEdit[i] = m_Editors[i];
|
||||
}
|
||||
InterfaceMutation[] list = m_MutatorsWithWeights.getSelectedMutators();
|
||||
l--;
|
||||
newEdit[l] = new GeneralGOEProperty();
|
||||
newEdit[l].m_Name = list[l].getStringRepresentation();
|
||||
try {
|
||||
newEdit[l].m_Value = list[l];
|
||||
newEdit[l].m_Editor = PropertyEditorProvider.findEditor(newEdit[l].m_Value.getClass());
|
||||
if (newEdit[l].m_Editor == null) newEdit[l].m_Editor = PropertyEditorProvider.findEditor(InterfaceMutation.class);
|
||||
if (newEdit[l].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) newEdit[l].m_Editor).setClassType(InterfaceMutation.class);
|
||||
newEdit[l].m_Editor.setValue(newEdit[l].m_Value);
|
||||
newEdit[l].m_Editor.addPropertyChangeListener(m_self);
|
||||
findViewFor(newEdit[l]);
|
||||
if (newEdit[l].m_View != null) newEdit[l].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
m_Editors = newEdit;
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener deleteTarget = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
int l = m_MutatorsWithWeights.getSelectedMutators().length, j = 0;
|
||||
GeneralGOEProperty[] newEdit = new GeneralGOEProperty[l-1];
|
||||
for (int i = 0; i < m_Delete.length; i++) {
|
||||
if (event.getSource().equals(m_Delete[i])) m_MutatorsWithWeights.removeMutator(i);
|
||||
else {
|
||||
newEdit[j] = m_Editors[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
m_Editors = newEdit;
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener,...
|
||||
*/
|
||||
ActionListener normalizeWeights = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
m_MutatorsWithWeights.normalizeWeights();
|
||||
updateTargetList();
|
||||
}
|
||||
};
|
||||
|
||||
/** This action listener reads all values
|
||||
*/
|
||||
KeyListener readDoubleArrayAction = new KeyListener() {
|
||||
public void keyPressed(KeyEvent event) {
|
||||
}
|
||||
public void keyTyped(KeyEvent event) {
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent event) {
|
||||
double[] newW = m_MutatorsWithWeights.getWeights();
|
||||
|
||||
for (int i = 0; i < newW.length; i++) {
|
||||
try {
|
||||
double d = 0;
|
||||
d = new Double(m_Weights[i].getText()).doubleValue();
|
||||
newW[i] = d;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
m_MutatorsWithWeights.setWeights(newW);
|
||||
}
|
||||
};
|
||||
|
||||
/** The object may have changed update the editor.
|
||||
*/
|
||||
private void updateEditor() {
|
||||
if (this.m_Editor != null) {
|
||||
this.m_TargetList.validate();
|
||||
this.m_TargetList.repaint();
|
||||
this.m_ScrollTargets.validate();
|
||||
this.m_ScrollTargets.repaint();
|
||||
this.m_Editor.validate();
|
||||
this.m_Editor.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/** This method will set the value of object that is to be edited.
|
||||
* @param o an object that must be an array.
|
||||
*/
|
||||
public void setValue(Object o) {
|
||||
if (o instanceof PropertyMutationMixer) {
|
||||
this.m_MutatorsWithWeights= (PropertyMutationMixer) o;
|
||||
this.updateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the current object.
|
||||
* @return the current object
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.m_MutatorsWithWeights;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** This is used to hook an action listener to the ok button
|
||||
* @param a The action listener.
|
||||
*/
|
||||
public void addOkListener(ActionListener a) {
|
||||
//m_OKButton.addActionListener(a);
|
||||
}
|
||||
|
||||
/** This is used to remove an action listener from the ok button
|
||||
* @param a The action listener
|
||||
*/
|
||||
public void removeOkListener(ActionListener a) {
|
||||
//m_OKButton.removeActionListener(a);
|
||||
}
|
||||
|
||||
/** Returns true since the Object can be shown
|
||||
* @return true
|
||||
*/
|
||||
public boolean isPaintable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Paints a representation of the current classifier.
|
||||
*
|
||||
* @param gfx the graphics context to use
|
||||
* @param box the area we are allowed to paint into
|
||||
*/
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
FontMetrics fm = gfx.getFontMetrics();
|
||||
int vpad = (box.height - fm.getAscent()) / 2;
|
||||
String rep = "Mixed Mutators";
|
||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||
}
|
||||
|
||||
/** Returns true because we do support a custom editor.
|
||||
* @return true
|
||||
*/
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the array editing component.
|
||||
* @return a value of type 'java.awt.Component'
|
||||
*/
|
||||
public Component getCustomEditor() {
|
||||
if (this.m_Component == null) {
|
||||
this.initCustomEditor();
|
||||
this.m_Component = new GeneralGEOFaker((PropertyEditor)this, (JPanel)this.m_Editor);
|
||||
}
|
||||
return this.m_Component;
|
||||
}
|
||||
|
||||
/** This method will udate the status of the object taking the values from all
|
||||
* supsequent editors and setting them to my object.
|
||||
*/
|
||||
public void updateCenterComponent(PropertyChangeEvent evt) {
|
||||
//this.updateTargetList();
|
||||
this.updateEditor();
|
||||
}
|
||||
|
||||
public void findViewFor(GeneralGOEProperty editor) {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.BoolEditor) {
|
||||
editor.m_View = new PropertyBoolSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor instanceof sun.beans.editors.DoubleEditor) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.isPaintable() && editor.m_Editor.supportsCustomEditor()) {
|
||||
editor.m_View = new PropertyPanel(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getTags() != null ) {
|
||||
editor.m_View = new PropertyValueSelector(editor.m_Editor);
|
||||
} else {
|
||||
if (editor.m_Editor.getAsText() != null) {
|
||||
editor.m_View = new PropertyText(editor.m_Editor);
|
||||
} else {
|
||||
System.out.println("Warning: Property \"" + editor.m_Name
|
||||
+ "\" has non-displayabale editor. Skipping.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/********************************* java.beans.PropertyChangeListener *************************/
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.addPropertyChangeListener(l);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
m_Support.removePropertyChangeListener(l);
|
||||
}
|
||||
/** This will wait for the GenericObjectEditor to finish
|
||||
* editing an object.
|
||||
* @param evt
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Object newVal = evt.getNewValue();
|
||||
Object oldVal = evt.getOldValue();
|
||||
InterfaceMutation[] list = this.m_MutatorsWithWeights.getSelectedMutators();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (oldVal.equals(list[i])) {
|
||||
list[i] = (InterfaceMutation)newVal;
|
||||
this.m_Editors[i].m_Name = list[i].getStringRepresentation();
|
||||
try {
|
||||
this.m_Editors[i].m_Value = list[i];
|
||||
this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(this.m_Editors[i].m_Value.getClass());
|
||||
if (this.m_Editors[i].m_Editor == null) this.m_Editors[i].m_Editor = PropertyEditorProvider.findEditor(InterfaceMutation.class);
|
||||
if (this.m_Editors[i].m_Editor instanceof GenericObjectEditor)
|
||||
((GenericObjectEditor) this.m_Editors[i].m_Editor).setClassType(InterfaceMutation.class);
|
||||
this.m_Editors[i].m_Editor.setValue(this.m_Editors[i].m_Value);
|
||||
this.m_Editors[i].m_Editor.addPropertyChangeListener(this);
|
||||
this.findViewFor(this.m_Editors[i]);
|
||||
if (this.m_Editors[i].m_View != null) this.m_Editors[i].m_View.repaint();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Darn can't read the value...");
|
||||
}
|
||||
this.m_Targets[i] = this.m_Editors[i].m_View;
|
||||
i = list.length;
|
||||
}
|
||||
}
|
||||
//this.m_OptimizationTargets.setSelectedTargets(list);
|
||||
this.updateCenterComponent(evt); // Let our panel update before guys downstream
|
||||
m_Support.firePropertyChange("", m_MutatorsWithWeights, m_MutatorsWithWeights);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user