Reformat all Code.

This commit is contained in:
2013-07-22 15:37:52 +02:00
parent 4bbcf937dc
commit 09cf295554
681 changed files with 57140 additions and 51465 deletions

View File

@@ -9,10 +9,12 @@ import eva2.optimization.operator.mutation.InterfaceMutation;
import eva2.optimization.operator.mutation.MutateDefault;
import eva2.optimization.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG;
import java.util.ArrayList;
import java.util.BitSet;
/** This individual uses a binary genotype to code for a tree-based representation
/**
* This individual uses a binary genotype to code for a tree-based representation
* using a BNF grammar, see also Grammatical Evolution.
* Created by IntelliJ IDEA.
* User: streiche
@@ -22,25 +24,25 @@ import java.util.BitSet;
*/
public class GEIndividualProgramData extends AbstractEAIndividual implements InterfaceGAIndividual, InterfaceDataTypeProgram, java.io.Serializable {
protected GPArea[] m_Area;
protected double m_InitFullGrowRatio = 0.5;
protected int m_InitDepth = 5;
protected int m_TargetDepth = 10;
protected boolean m_CheckTargetDepth = true;
protected GPArea[] m_Area;
protected double m_InitFullGrowRatio = 0.5;
protected int m_InitDepth = 5;
protected int m_TargetDepth = 10;
protected boolean m_CheckTargetDepth = true;
protected BitSet m_Genotype;
protected AbstractGPNode[] m_Phenotype;
protected int m_GenotypeLengthPerProgram = 240; // this is the overall length
protected int m_MaxNumberOfNodes = 80;
protected int m_NumberOfBitPerInt = 6;
protected int m_CurrentIndex = 0;
protected int m_CurrentNumberOfNodes = 0;
protected Object[][] m_Rules;
protected BitSet m_Genotype;
protected AbstractGPNode[] m_Phenotype;
protected int m_GenotypeLengthPerProgram = 240; // this is the overall length
protected int m_MaxNumberOfNodes = 80;
protected int m_NumberOfBitPerInt = 6;
protected int m_CurrentIndex = 0;
protected int m_CurrentNumberOfNodes = 0;
protected Object[][] m_Rules;
public GEIndividualProgramData() {
this.m_Area = new GPArea[1];
this.m_GenotypeLengthPerProgram = 240;
this.m_Genotype = new BitSet();
this.m_Area = new GPArea[1];
this.m_GenotypeLengthPerProgram = 240;
this.m_Genotype = new BitSet();
this.mutationOperator = new MutateDefault();
this.crossoverOperator = new CrossoverGADefault();
this.mutationProbability = 0.5;
@@ -51,20 +53,20 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
if (individual.m_Phenotype != null) {
this.m_Phenotype = new AbstractGPNode[individual.m_Phenotype.length];
for (int i = 0; i < individual.m_Phenotype.length; i++) {
this.m_Phenotype[i] = (AbstractGPNode)individual.m_Phenotype[i].clone();
this.m_Phenotype[i] = (AbstractGPNode) individual.m_Phenotype[i].clone();
}
}
this.m_GenotypeLengthPerProgram = individual.m_GenotypeLengthPerProgram;
this.m_GenotypeLengthPerProgram = individual.m_GenotypeLengthPerProgram;
this.m_MaxNumberOfNodes = individual.m_MaxNumberOfNodes;
this.m_NumberOfBitPerInt= individual.m_NumberOfBitPerInt;
this.m_CurrentIndex = individual.m_CurrentIndex;
this.m_NumberOfBitPerInt = individual.m_NumberOfBitPerInt;
this.m_CurrentIndex = individual.m_CurrentIndex;
if (individual.m_Genotype != null) {
this.m_Genotype = (BitSet)individual.m_Genotype.clone();
this.m_Genotype = (BitSet) individual.m_Genotype.clone();
}
if (individual.m_Area != null) {
this.m_Area = new GPArea[individual.m_Area.length];
this.m_Area = new GPArea[individual.m_Area.length];
for (int i = 0; i < this.m_Area.length; i++) {
this.m_Area[i] = (GPArea)individual.m_Area[i].clone();
this.m_Area[i] = (GPArea) individual.m_Area[i].clone();
}
}
// User : "Copy the rules set!"
@@ -80,9 +82,9 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
System.arraycopy(orgRulz[i], 0, copyRulz[i], 0, orgRulz[i].length);
}
this.m_Rules[t][0] = copyRulz;
AbstractGPNode[] copyNode, orgNode;
AbstractGPNode[] copyNode, orgNode;
for (int i = 1; i < this.m_Rules[t].length; i++) {
orgNode = (AbstractGPNode[])individual.m_Rules[t][i];
orgNode = (AbstractGPNode[]) individual.m_Rules[t][i];
copyNode = new AbstractGPNode[orgNode.length];
for (int j = 0; j < orgNode.length; j++) {
copyNode[j] = (AbstractGPNode) orgNode[j].clone();
@@ -95,7 +97,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
this.age = individual.age;
this.crossoverOperator = individual.crossoverOperator;
this.crossoverProbability = individual.crossoverProbability;
this.mutationOperator = (InterfaceMutation)individual.mutationOperator.clone();
this.mutationOperator = (InterfaceMutation) individual.mutationOperator.clone();
this.mutationProbability = individual.mutationProbability;
this.selectionProbability = new double[individual.selectionProbability.length];
for (int i = 0; i < this.selectionProbability.length; i++) {
@@ -113,8 +115,10 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
return (Object) new GEIndividualProgramData(this);
}
/** This method checks on equality regarding genotypic equality
* @param individual The individual to compare to.
/**
* This method checks on equality regarding genotypic equality
*
* @param individual The individual to compare to.
* @return boolean if equal true else false.
*/
@Override
@@ -142,7 +146,8 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
}
}
/** This method compiles the area
/**
* This method compiles the area
*/
private void compileArea() {
if (this.m_Area == null) {
@@ -152,7 +157,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
//this.m_Rules = new Object[this.m_Area.length][];
for (int t = 0; t < this.m_Area.length; t++) {
// first lets find out what kind of elements are available
int arity, maxArity = 0;
int arity, maxArity = 0;
// first find out the max arity in the GPArea
this.m_Area[t].compileReducedList();
@@ -173,21 +178,21 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
directList[((AbstractGPNode) area.get(i)).getArity()].add(area.get(i));
}
// Now write the rules
this.m_Rules[t] = new Object[maxArity+2];
this.m_Rules[t] = new Object[maxArity + 2];
// the first rule describes how to decode an <expr>
int numberOfRules = 0, index = 0;
int[] tmpRule;
int[][] tmpExpr = new int[directList.length+1][];
int numberOfRules = 0, index = 0;
int[] tmpRule;
int[][] tmpExpr = new int[directList.length + 1][];
for (int i = 0; i < directList.length; i++) {
tmpRule = new int[i+1];
tmpRule = new int[i + 1];
if (i == 0) {
// this is a <var>
tmpRule[0] = 1;
} else {
// this is a <opX> <expr> <expr>....
if (directList[i].size() > 0) {
tmpRule[0] = i+1;
for (int j = 1; j < i+1; j++) {
tmpRule[0] = i + 1;
for (int j = 1; j < i + 1; j++) {
tmpRule[j] = 0;
}
} else {
@@ -208,41 +213,40 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
index++;
}
}
this.m_Rules[t][0] =trueExpr;
this.m_Rules[t][0] = trueExpr;
// now the rules that define <var>, <op1>, <op2>, ....
AbstractGPNode[] tmpListOfGPNodes;
AbstractGPNode[] tmpListOfGPNodes;
for (int i = 0; i < directList.length; i++) {
tmpListOfGPNodes = new AbstractGPNode[directList[i].size()];
for (int j = 0; j < directList[i].size(); j++) {
tmpListOfGPNodes[j] = (AbstractGPNode)directList[i].get(j);
tmpListOfGPNodes[j] = (AbstractGPNode) directList[i].get(j);
}
this.m_Rules[t][i+1] = tmpListOfGPNodes;
this.m_Rules[t][i + 1] = tmpListOfGPNodes;
}
// this should be the complete rules set
//this.printRuleSet();
}
}
/** This method will print the currently used rule set
/**
* This method will print the currently used rule set
*/
private void printRuleSet() {
String result = "";
AbstractGPNode[] tmpNodes;
String result = "";
AbstractGPNode[] tmpNodes;
for (int t = 0; t < this.m_Area.length; t++) {
// first the Non-Terminals
result += "N \t := \t{";
for (int i = 0; i < this.m_Rules[t].length; i++) {
if (i == 0) {
result += "expr, ";
}
else {
} else {
if (i == 1) {
result += "var, ";
}
else {
if (((AbstractGPNode[])this.m_Rules[t][i]).length > 0) {
result += "op"+(i-1)+", ";
} else {
if (((AbstractGPNode[]) this.m_Rules[t][i]).length > 0) {
result += "op" + (i - 1) + ", ";
}
}
}
@@ -253,7 +257,7 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
this.m_Area[t].compileReducedList();
ArrayList area = this.m_Area[t].getReducedList();
for (int i = 0; i < area.size(); i++) {
result += ((AbstractGPNode)area.get(i)).getStringRepresentation()+", ";
result += ((AbstractGPNode) area.get(i)).getStringRepresentation() + ", ";
}
result += "}\n";
// now the S
@@ -265,10 +269,10 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
// the first rules
result += "0. \t := \t<expr> \t::\t";
System.out.println("i: " + i);
int[][] rulz = (int[][])this.m_Rules[t][i];
int[][] rulz = (int[][]) this.m_Rules[t][i];
for (int j = 0; j < rulz.length; j++) {
result += this.getRuleString(rulz[j]) + "\n";
if ((j+1) < rulz.length) {
if ((j + 1) < rulz.length) {
result += "\t \t \t \t \t \t";
}
}
@@ -276,18 +280,18 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
// now the rules for the terminals
if (i == 1) {
// These are the GP-Terminals
tmpNodes = (AbstractGPNode[])this.m_Rules[t][i];
result += "1. \t := \t<var> \t::\t"+ tmpNodes[0].getStringRepresentation()+"\n";
tmpNodes = (AbstractGPNode[]) this.m_Rules[t][i];
result += "1. \t := \t<var> \t::\t" + tmpNodes[0].getStringRepresentation() + "\n";
for (int j = 1; j < tmpNodes.length; j++) {
result += "\t \t \t \t \t \t"+ tmpNodes[j].getStringRepresentation()+"\n";
result += "\t \t \t \t \t \t" + tmpNodes[j].getStringRepresentation() + "\n";
}
} else {
// These are the GP-Functions
tmpNodes = (AbstractGPNode[])this.m_Rules[t][i];
tmpNodes = (AbstractGPNode[]) this.m_Rules[t][i];
if (tmpNodes.length > 0) {
result += i+". \t := \t<op"+(i-1)+"> \t::\t"+ tmpNodes[0].getStringRepresentation()+"\n";
result += i + ". \t := \t<op" + (i - 1) + "> \t::\t" + tmpNodes[0].getStringRepresentation() + "\n";
for (int j = 1; j < tmpNodes.length; j++) {
result += "\t \t \t \t \t \t"+ tmpNodes[j].getStringRepresentation()+"\n";
result += "\t \t \t \t \t \t" + tmpNodes[j].getStringRepresentation() + "\n";
}
}
}
@@ -297,24 +301,25 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
}
// Now print the result:
System.out.println(""+result);
System.out.println("" + result);
}
/** This method returns a string for the BitSet
/**
* This method returns a string for the BitSet
*
* @return A String
*/
private String getBitSetString() {
String result = "";
result += "{";
for (int i = 0; i < this.m_GenotypeLengthPerProgram*this.m_Area.length; i++) {
for (int i = 0; i < this.m_GenotypeLengthPerProgram * this.m_Area.length; i++) {
if (i % this.m_NumberOfBitPerInt == 0) {
result += " ";
}
if (this.m_Genotype.get(i)) {
result += "1";
}
else {
} else {
result += "0";
}
}
@@ -322,12 +327,14 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
return result;
}
/** This method returns a String for a given rule
* @param rule The rulz to transform into a string
/**
* This method returns a String for a given rule
*
* @param rule The rulz to transform into a string
* @return String
*/
private String getRuleString(int[] rule) {
String result ="";
String result = "";
for (int k = 0; k < rule.length; k++) {
if (rule[k] == 0) {
result += "<expr> ";
@@ -335,8 +342,8 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
if (rule[k] == 1) {
result += "<var> ";
}
if (rule[k] > 1) {
result += "<op"+(rule[k]-1)+"> ";
if (rule[k] > 1) {
result += "<op" + (rule[k] - 1) + "> ";
}
}
return result;
@@ -345,28 +352,30 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
/************************************************************************************
* InterfaceDataTypeProgram methods
*/
/** This method allows you to request a certain amount of double data
* @param length The lenght of the double[] that is to be optimized
/**
* This method allows you to request a certain amount of double data
*
* @param length The lenght of the double[] that is to be optimized
*/
@Override
public void setProgramDataLength (int length) {
GPArea[] oldArea = this.m_Area;
Object[][] oldRulz = this.m_Rules;
public void setProgramDataLength(int length) {
GPArea[] oldArea = this.m_Area;
Object[][] oldRulz = this.m_Rules;
this.m_Area = new GPArea[length];
this.m_Area = new GPArea[length];
for (int t = 0; ((t < this.m_Area.length) && (t < oldArea.length)); t++) {
this.m_Area[t] = oldArea[t];
this.m_Area[t] = oldArea[t];
}
for (int t = oldArea.length; t < this.m_Area.length; t++) {
this.m_Area[t] = oldArea[oldArea.length-1];
this.m_Area[t] = oldArea[oldArea.length - 1];
}
this.m_Rules = new Object[length][];
this.m_Rules = new Object[length][];
if (oldRulz == null) {
return;
}
for (int t = 0; ((t < this.m_Area.length) && (t < oldArea.length)); t++) {
if (oldRulz[t] != null) {
this.m_Rules[t] = new Object[oldRulz[t].length];
this.m_Rules[t] = new Object[oldRulz[t].length];
int[][] copyRulz, orgRulz = (int[][]) oldRulz[t][0];
copyRulz = new int[orgRulz.length][];
for (int i = 0; i < copyRulz.length; i++) {
@@ -374,9 +383,9 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
System.arraycopy(orgRulz[i], 0, copyRulz[i], 0, orgRulz[i].length);
}
this.m_Rules[t][0] = copyRulz;
AbstractGPNode[] copyNode, orgNode;
AbstractGPNode[] copyNode, orgNode;
for (int i = 1; i < this.m_Rules[t].length; i++) {
orgNode = (AbstractGPNode[])oldRulz[t][i];
orgNode = (AbstractGPNode[]) oldRulz[t][i];
copyNode = new AbstractGPNode[orgNode.length];
for (int j = 0; j < orgNode.length; j++) {
copyNode[j] = (AbstractGPNode) orgNode[j].clone();
@@ -386,18 +395,18 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
}
}
for (int t = oldArea.length; t < this.m_Area.length; t++) {
if (oldRulz[oldArea.length-1] != null) {
this.m_Rules[t] = new Object[oldRulz[oldArea.length-1].length];
int[][] copyRulz, orgRulz = (int[][]) oldRulz[oldArea.length-1][0];
if (oldRulz[oldArea.length - 1] != null) {
this.m_Rules[t] = new Object[oldRulz[oldArea.length - 1].length];
int[][] copyRulz, orgRulz = (int[][]) oldRulz[oldArea.length - 1][0];
copyRulz = new int[orgRulz.length][];
for (int i = 0; i < copyRulz.length; i++) {
copyRulz[i] = new int[orgRulz[i].length];
System.arraycopy(orgRulz[i], 0, copyRulz[i], 0, orgRulz[i].length);
}
this.m_Rules[t][0] = copyRulz;
AbstractGPNode[] copyNode, orgNode;
AbstractGPNode[] copyNode, orgNode;
for (int i = 1; i < this.m_Rules[t].length; i++) {
orgNode = (AbstractGPNode[])oldRulz[oldArea.length-1][i];
orgNode = (AbstractGPNode[]) oldRulz[oldArea.length - 1][i];
copyNode = new AbstractGPNode[orgNode.length];
for (int j = 0; j < orgNode.length; j++) {
copyNode[j] = (AbstractGPNode) orgNode[j].clone();
@@ -408,42 +417,46 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
}
}
/** This method will fetch the next int value from the BitSet. If necessary the
/**
* This method will fetch the next int value from the BitSet. If necessary the
* method will continue at the beginning of the BitSet if m_Genotype length is
* exceeded.
* Note: You need to set the current ReadingIndx = 0 before starting to decode
* the BitSet
* @param t The index of the program.
* @return The int value
*
* @param t The index of the program.
* @return The int value
*/
private int decodeNextInt(int t) {
int result = 0;
for (int i = 0; i < this.m_NumberOfBitPerInt; i++) {
if (this.m_Genotype.get(this.m_CurrentIndex+(t*this.m_GenotypeLengthPerProgram))) {
if (this.m_Genotype.get(this.m_CurrentIndex + (t * this.m_GenotypeLengthPerProgram))) {
result += Math.pow(2, i);
}
this.m_CurrentIndex++;
if (this.m_CurrentIndex >= (t+1)*this.m_GenotypeLengthPerProgram) {
this.m_CurrentIndex = t*this.m_GenotypeLengthPerProgram;
if (this.m_CurrentIndex >= (t + 1) * this.m_GenotypeLengthPerProgram) {
this.m_CurrentIndex = t * this.m_GenotypeLengthPerProgram;
}
}
return result;
}
/** This method will decode a GPNode from the BitSet
* @param t The index of the program
* @param mode The modex
/**
* This method will decode a GPNode from the BitSet
*
* @param t The index of the program
* @param mode The modex
* @return GPNode
*/
private AbstractGPNode decodeGPNode(int t, int mode) {
AbstractGPNode result = null;
int value = this.decodeNextInt(t);
AbstractGPNode result = null;
int value = this.decodeNextInt(t);
// System.out.println("Decoding mode: " + mode);
if (mode == 0) {
int[][] rulz = (int[][]) this.m_Rules[t][0];
int[] myRule = rulz[value%rulz.length];
int[] myRule = rulz[value % rulz.length];
// System.out.print("Value % rulz : "+ value +" % " + rulz.length + " = " +(value%rulz.length));
// System.out.println(" => my rule " + this.getRuleString(myRule));
this.m_CurrentNumberOfNodes += myRule.length;
@@ -455,18 +468,20 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
result = this.decodeGPNode(t, myRule[0]);
result.initNodeArray();
for (int i = 0; i < result.getArity(); i++) {
result.setNode(this.decodeGPNode(t, myRule[i+1]), i);
result.setNode(this.decodeGPNode(t, myRule[i + 1]), i);
}
} else {
AbstractGPNode[] availableNodes = (AbstractGPNode[]) this.m_Rules[t][mode];
// System.out.print("Choosing a terminal : "+ value +" % " + availableNodes.length + " = " +(value%availableNodes.length));
// System.out.println(" => " +availableNodes[value % availableNodes.length].getStringRepresentation());
result = (AbstractGPNode)availableNodes[value % availableNodes.length].clone();
result = (AbstractGPNode) availableNodes[value % availableNodes.length].clone();
}
return result;
}
/** This method allows you to read the program stored as Koza style node tree
/**
* This method allows you to read the program stored as Koza style node tree
*
* @return GPNode representing the binary data.
*/
@Override
@@ -489,13 +504,13 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
return null;
}
}
this.m_CurrentIndex = 0;
this.m_CurrentIndex = 0;
this.m_CurrentNumberOfNodes = 0;
int mode = 0;
int mode = 0;
this.m_Phenotype = new AbstractGPNode[this.m_Area.length];
for (int t = 0; t < this.m_Area.length; t++) {
mode = 0;
this.m_CurrentIndex = t*this.m_GenotypeLengthPerProgram;
mode = 0;
this.m_CurrentIndex = t * this.m_GenotypeLengthPerProgram;
this.m_CurrentNumberOfNodes = 0;
this.m_Phenotype[t] = this.decodeGPNode(t, mode);
}
@@ -504,8 +519,10 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
return this.m_Phenotype;
}
/** This method allows you to read the Program data without
/**
* This method allows you to read the Program data without
* an update from the genotype
*
* @return InterfaceProgram[] representing the Program.
*/
@Override
@@ -513,22 +530,25 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
return this.m_Phenotype;
}
/** This method allows you to set the program phenotype.
* @param program The new program.
/**
* This method allows you to set the program phenotype.
*
* @param program The new program.
*/
@Override
public void SetProgramPhenotype(InterfaceProgram[] program) {
if (program instanceof AbstractGPNode[]) {
this.m_Phenotype = new AbstractGPNode[program.length];
for (int t = 0; t < program.length; t++) {
this.m_Phenotype[t] = (AbstractGPNode)((AbstractGPNode)program[t]).clone();
this.m_Phenotype[t] = (AbstractGPNode) ((AbstractGPNode) program[t]).clone();
}
}
}
/**
/**
* Warning - this is not implemented, it only sets the phenotype using SetProgramData.
* @param program The new program.
*
* @param program The new program.
*/
@Override
public void SetProgramGenotype(InterfaceProgram[] program) {
@@ -538,13 +558,15 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
}
}
/** This method allows you to set the function area
* @param area The area contains functions and terminals
/**
* This method allows you to set the function area
*
* @param area The area contains functions and terminals
*/
@Override
public void SetFunctionArea(Object[] area) {
if (area instanceof GPArea[]) {
this.m_Area = new GPArea[area.length];
this.m_Area = new GPArea[area.length];
for (int t = 0; t < this.m_Area.length; t++) {
this.m_Area[t] = (GPArea) area[t];
}
@@ -552,7 +574,9 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
}
}
/** This method allows you to set the function area
/**
* This method allows you to set the function area
*
* @return The function area
*/
@Override
@@ -563,15 +587,17 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
/************************************************************************************
* InterfaceEAIndividual methods
*/
/** This method will init the individual with a given value for the
/**
* This method will init the individual with a given value for the
* phenotype.
* @param obj The initial value for the phenotype
* @param opt The optimization problem that is to be solved.
*
* @param obj The initial value for the phenotype
* @param opt The optimization problem that is to be solved.
*/
@Override
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
if (obj instanceof InterfaceProgram) {
this.SetProgramGenotype((InterfaceProgram[])obj);
this.SetProgramGenotype((InterfaceProgram[]) obj);
} else {
this.defaultInit(opt);
System.out.println("Initial value for GPIndividualDoubleData is no InterfaceProgram[]!");
@@ -580,8 +606,10 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
this.crossoverOperator.init(this, opt);
}
/** This method will return a string description of the GAIndividal
/**
* This method will return a string description of the GAIndividal
* noteably the Genotype.
*
* @return A descriptive string
*/
@Override
@@ -589,11 +617,10 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
String result = "";
result += "GEIndividual coding program:\n";
result += "{";
for (int i = 0; i < this.m_GenotypeLengthPerProgram*this.m_Area.length; i++) {
for (int i = 0; i < this.m_GenotypeLengthPerProgram * this.m_Area.length; i++) {
if (this.m_Genotype.get(i)) {
result += "1";
}
else {
} else {
result += "0";
}
}
@@ -609,65 +636,72 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
* InterfaceGAIndividual methods
*/
/** This method allows you to read the binary data
* @return BitSet representing the binary data.
*/
/**
* This method allows you to read the binary data
*
* @return BitSet representing the binary data.
*/
@Override
public BitSet getBGenotype() {
return this.m_Genotype;
}
public BitSet getBGenotype() {
return this.m_Genotype;
}
/** This method allows you to set the binary data, this can be used for
* memetic algorithms.
* @param binaryData The new binary data.
*/
/**
* This method allows you to set the binary data, this can be used for
* memetic algorithms.
*
* @param binaryData The new binary data.
*/
@Override
public void SetBGenotype(BitSet binaryData) {
this.m_Genotype = binaryData;
}
public void SetBGenotype(BitSet binaryData) {
this.m_Genotype = binaryData;
}
/** This method allows the user to read the length of the genotype.
* This may be necessary since BitSet.lenght only returns the index
* of the last significat bit.
* @return The length of the genotype.
*/
/**
* This method allows the user to read the length of the genotype.
* This may be necessary since BitSet.lenght only returns the index
* of the last significat bit.
*
* @return The length of the genotype.
*/
@Override
public int getGenotypeLength() {
return this.m_GenotypeLengthPerProgram*this.m_Area.length;
}
public int getGenotypeLength() {
return this.m_GenotypeLengthPerProgram * this.m_Area.length;
}
@Override
public void defaultInit(InterfaceOptimizationProblem prob) {
for (int i = 0; i < this.m_GenotypeLengthPerProgram*this.m_Area.length; i++) {
if (RNG.flipCoin(0.5)) {
this.m_Genotype.set(i);
}
else {
this.m_Genotype.clear(i);
}
public void defaultInit(InterfaceOptimizationProblem prob) {
for (int i = 0; i < this.m_GenotypeLengthPerProgram * this.m_Area.length; i++) {
if (RNG.flipCoin(0.5)) {
this.m_Genotype.set(i);
} else {
this.m_Genotype.clear(i);
}
}
}
/** This method performs a simple one point mutation in the genotype
*/
/**
* This method performs a simple one point mutation in the genotype
*/
@Override
public void defaultMutate() {
int mutationIndex = RNG.randomInt(0, this.m_GenotypeLengthPerProgram*this.m_Area.length);
//if (mutationIndex > 28) System.out.println("Mutate: " + this.getSolutionRepresentationFor());
if (this.m_Genotype.get(mutationIndex)) {
this.m_Genotype.clear(mutationIndex);
}
else {
this.m_Genotype.set(mutationIndex);
}
//if (mutationIndex > 28) System.out.println(this.getSolutionRepresentationFor());
public void defaultMutate() {
int mutationIndex = RNG.randomInt(0, this.m_GenotypeLengthPerProgram * this.m_Area.length);
//if (mutationIndex > 28) System.out.println("Mutate: " + this.getSolutionRepresentationFor());
if (this.m_Genotype.get(mutationIndex)) {
this.m_Genotype.clear(mutationIndex);
} else {
this.m_Genotype.set(mutationIndex);
}
//if (mutationIndex > 28) System.out.println(this.getSolutionRepresentationFor());
}
/**********************************************************************************************************************
* These are for GUI
*/
/** This method allows the CommonJavaObjectEditorPanel to read the
/**
* This method allows the CommonJavaObjectEditorPanel to read the
* name to the current object.
*
* @return The name.
*/
@Override
@@ -675,50 +709,64 @@ public class GEIndividualProgramData extends AbstractEAIndividual implements Int
return "GE individual";
}
/** This method returns a global info string
/**
* This method returns a global info string
*
* @return description
*/
public static String globalInfo() {
return "This is a GE individual suited to optimize programs.";
}
/** This method allows you to set the length of the binary genotype
* @param size The length
/**
* This method allows you to set the length of the binary genotype
*
* @param size The length
*/
public void setGenotypeLengthPerProgram(int size) {
this.m_GenotypeLengthPerProgram = size;
}
public int getGenotypeLengthPerProgram() {
return this.m_GenotypeLengthPerProgram;
}
public String genotypeLengthPerProgramTipText() {
return "Choose the length of the genotype.";
}
/** This method allows you to set the maximum number of
/**
* This method allows you to set the maximum number of
* nodes allowed for the program.
* @param nodes The maximum number of nodes
*
* @param nodes The maximum number of nodes
*/
public void setMaxNumberOfNodes(int nodes) {
this.m_MaxNumberOfNodes = nodes;
}
public int getMaxNumberOfNodes() {
return this.m_MaxNumberOfNodes;
}
public String maxNumberOfNodesTipText() {
return "Set the maximum number of nodes for the program.";
}
/** This method allows you to set the number of bits per int value
/**
* This method allows you to set the number of bits per int value
* stored on the BitSet
* @param length The number of bits per int.
*
* @param length The number of bits per int.
*/
public void setNumberOfBitPerInt(int length) {
this.m_NumberOfBitPerInt = length;
}
public int getNumberOfBitPerInt() {
return this.m_NumberOfBitPerInt;
}
public String numberOfBitPerIntTipText() {
return "Choose the number of bits ber int.";
}