Some updates, mainly GP stuff...
This commit is contained in:
parent
a370c45029
commit
257c0965c0
@ -221,6 +221,7 @@ public class GOEPanel extends JPanel implements ItemListener {
|
|||||||
// System.out.println("Copying " + BeanInspector.toString(source));
|
// System.out.println("Copying " + BeanInspector.toString(source));
|
||||||
SerializedObject so = new SerializedObject(source);
|
SerializedObject so = new SerializedObject(source);
|
||||||
result = so.getObject();
|
result = so.getObject();
|
||||||
|
so=null;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.println("GenericObjectEditor: Problem making backup object");
|
System.err.println("GenericObjectEditor: Problem making backup object");
|
||||||
System.err.println(source.getClass().getName());
|
System.err.println(source.getClass().getName());
|
||||||
|
@ -114,6 +114,7 @@ implements PropertyEditor {
|
|||||||
try {
|
try {
|
||||||
SerializedObject so = new SerializedObject(addObj);
|
SerializedObject so = new SerializedObject(addObj);
|
||||||
addObj = so.getObject();
|
addObj = so.getObject();
|
||||||
|
so=null;
|
||||||
if (selected != -1) {
|
if (selected != -1) {
|
||||||
m_ListModel.insertElementAt(addObj, selected);
|
m_ListModel.insertElementAt(addObj, selected);
|
||||||
} else {
|
} else {
|
||||||
|
@ -949,7 +949,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
|
|||||||
if ((i+1) < b.length) sb.append(separator);
|
if ((i+1) < b.length) sb.append(separator);
|
||||||
}
|
}
|
||||||
} else if (individual instanceof InterfaceDataTypeProgram) {
|
} else if (individual instanceof InterfaceDataTypeProgram) {
|
||||||
InterfaceProgram[] b = ((InterfaceDataTypeProgram)individual).getProgramData();
|
InterfaceProgram[] b = ((InterfaceDataTypeProgram)individual).getProgramDataWithoutUpdate();
|
||||||
for (int i = 0; i < b.length; i++) {
|
for (int i = 0; i < b.length; i++) {
|
||||||
sb.append(b[i].getStringRepresentation());
|
sb.append(b[i].getStringRepresentation());
|
||||||
if ((i+1) < b.length) sb.append(separator);
|
if ((i+1) < b.length) sb.append(separator);
|
||||||
|
@ -27,7 +27,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
protected GPArea[] m_Area;
|
protected GPArea[] m_Area;
|
||||||
protected double m_InitFullGrowRatio = 0.5;
|
protected double m_InitFullGrowRatio = 0.5;
|
||||||
protected int m_InitDepth = 4;
|
protected int m_InitDepth = 4;
|
||||||
protected int m_maxDepth = 8;
|
protected int m_maxAllowedDepth = 8;
|
||||||
protected boolean m_CheckMaxDepth = true;
|
protected boolean m_CheckMaxDepth = true;
|
||||||
|
|
||||||
public GPIndividualProgramData() {
|
public GPIndividualProgramData() {
|
||||||
@ -58,7 +58,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
}
|
}
|
||||||
this.m_InitFullGrowRatio = individual.m_InitFullGrowRatio;
|
this.m_InitFullGrowRatio = individual.m_InitFullGrowRatio;
|
||||||
this.m_InitDepth = individual.m_InitDepth;
|
this.m_InitDepth = individual.m_InitDepth;
|
||||||
this.m_maxDepth = individual.m_maxDepth;
|
this.m_maxAllowedDepth = individual.m_maxAllowedDepth;
|
||||||
this.m_CheckMaxDepth = individual.m_CheckMaxDepth;
|
this.m_CheckMaxDepth = individual.m_CheckMaxDepth;
|
||||||
|
|
||||||
// cloning the members of AbstractEAIndividual
|
// cloning the members of AbstractEAIndividual
|
||||||
@ -90,7 +90,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
if (individual instanceof GPIndividualProgramData) {
|
if (individual instanceof GPIndividualProgramData) {
|
||||||
GPIndividualProgramData indy = (GPIndividualProgramData) individual;
|
GPIndividualProgramData indy = (GPIndividualProgramData) individual;
|
||||||
//@todo Eigendlich k<EFBFBD>nnte ich noch die Areas vergleichen
|
//@todo Eigendlich k<EFBFBD>nnte ich noch die Areas vergleichen
|
||||||
if (this.m_maxDepth != indy.m_maxDepth)
|
if (this.m_maxAllowedDepth != indy.m_maxAllowedDepth)
|
||||||
return false;
|
return false;
|
||||||
if ((this.m_Genotype == null) || (indy.m_Genotype == null))
|
if ((this.m_Genotype == null) || (indy.m_Genotype == null))
|
||||||
return false;
|
return false;
|
||||||
@ -134,9 +134,13 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
this.m_Phenotype = new AbstractGPNode[this.m_Genotype.length];
|
this.m_Phenotype = new AbstractGPNode[this.m_Genotype.length];
|
||||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||||
this.m_Phenotype[i] = (AbstractGPNode)this.m_Genotype[i].clone();
|
this.m_Phenotype[i] = (AbstractGPNode)this.m_Genotype[i].clone();
|
||||||
if ((this.m_CheckMaxDepth) && (this.m_Phenotype[i].isMaxDepthViolated(this.m_maxDepth))) {
|
// if (!m_Phenotype[0].checkDepth(0)) {
|
||||||
//System.out.println("Trying to meet the Target Depth!");
|
// System.err.println("error... " + m_Genotype[0].checkDepth(0));
|
||||||
this.m_Phenotype[i].repairMaxDepth(this.m_Area[i], this.m_maxDepth);
|
// }
|
||||||
|
|
||||||
|
if ((this.m_CheckMaxDepth) && (this.m_Phenotype[i].isMaxDepthViolated(this.m_maxAllowedDepth))) {
|
||||||
|
System.err.println("Trying to meet the Target Depth! " + this.m_Phenotype[i].isMaxDepthViolated(this.m_maxAllowedDepth) + " "+ m_Phenotype[i].getMaxDepth());
|
||||||
|
this.m_Phenotype[i].repairMaxDepth(this.m_Area[i], this.m_maxAllowedDepth);
|
||||||
//System.out.println("TragetDepth: " + this.m_TargetDepth + " : " + this.m_Program.getMaxDepth());
|
//System.out.println("TragetDepth: " + this.m_TargetDepth + " : " + this.m_Program.getMaxDepth());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +152,8 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
* @return InterfaceProgram[] representing the Program.
|
* @return InterfaceProgram[] representing the Program.
|
||||||
*/
|
*/
|
||||||
public InterfaceProgram[] getProgramDataWithoutUpdate() {
|
public InterfaceProgram[] getProgramDataWithoutUpdate() {
|
||||||
return this.m_Phenotype;
|
if (this.m_Phenotype==null) return getProgramData();
|
||||||
|
else return this.m_Phenotype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to set the program phenotype.
|
/** This method allows you to set the program phenotype.
|
||||||
@ -244,6 +249,7 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
*/
|
*/
|
||||||
public void SetPGenotype(AbstractGPNode[] b) {
|
public void SetPGenotype(AbstractGPNode[] b) {
|
||||||
this.m_Genotype = b;
|
this.m_Genotype = b;
|
||||||
|
this.m_Phenotype=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will allow the user to set the current program 'genotype'.
|
/** This method will allow the user to set the current program 'genotype'.
|
||||||
@ -252,28 +258,41 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
*/
|
*/
|
||||||
public void SetPGenotype(AbstractGPNode b, int i) {
|
public void SetPGenotype(AbstractGPNode b, int i) {
|
||||||
this.m_Genotype[i] = b;
|
this.m_Genotype[i] = b;
|
||||||
|
m_Genotype[i].updateDepth(0);
|
||||||
|
// System.out.println("Setting pheno of depth " + b.getMaxDepth() + " " + b.getStringRepresentation());
|
||||||
|
this.m_Phenotype=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method performs a simple one element mutation on the program
|
/**
|
||||||
|
* This method performs a simple one element mutation on the program
|
||||||
*/
|
*/
|
||||||
public void defaultMutate() {
|
public void defaultMutate() {
|
||||||
ArrayList allNodes = new ArrayList();
|
|
||||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||||
this.m_Genotype[i].addNodesTo(allNodes);
|
AbstractGPNode nodeToMutate = this.m_Genotype[i].getRandomNode();
|
||||||
AbstractGPNode nodeToMutate = (AbstractGPNode) allNodes.get(RNG.randomInt(0, allNodes.size()-1));
|
if (nodeToMutate.getParent() == null) { // mutate at root
|
||||||
if (nodeToMutate.getParent() == null) {
|
|
||||||
this.defaultInit(null);
|
this.defaultInit(null);
|
||||||
} else {
|
} else {
|
||||||
AbstractGPNode parent = nodeToMutate.getParent();
|
AbstractGPNode parent = nodeToMutate.getParent();
|
||||||
AbstractGPNode newNode = (AbstractGPNode)(((AbstractGPNode)this.m_Area[i].getRandomNode().clone()));
|
if (m_CheckMaxDepth && (nodeToMutate.getDepth()==m_maxAllowedDepth)) { // mutate with a constant
|
||||||
newNode.setDepth(nodeToMutate.getDepth());
|
AbstractGPNode newNode = (AbstractGPNode)(((AbstractGPNode)this.m_Area[i].getRandomNodeWithArity(0).clone()));
|
||||||
newNode.initGrow(this.m_Area[i], this.m_maxDepth);
|
newNode.setDepth(nodeToMutate.getDepth());
|
||||||
parent.setNode(newNode, nodeToMutate);
|
parent.setNode(newNode, nodeToMutate);
|
||||||
|
} else {
|
||||||
|
AbstractGPNode newNode = (AbstractGPNode)(((AbstractGPNode)this.m_Area[i].getRandomNode().clone()));
|
||||||
|
newNode.setDepth(nodeToMutate.getDepth());
|
||||||
|
newNode.initGrow(this.m_Area[i], this.m_maxAllowedDepth);
|
||||||
|
parent.setNode(newNode, nodeToMutate);
|
||||||
|
}
|
||||||
|
//if (!m_Genotype[i].checkDepth(0) || (m_Genotype[i].isMaxDepthViolated(m_maxAllowedDepth))) {
|
||||||
|
// System.err.println("Error in GPIndividualProgramData.defaultMutate!");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_Phenotype=null; // reset pheno
|
||||||
}
|
}
|
||||||
|
|
||||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||||
|
m_Phenotype=null; // reset pheno
|
||||||
for (int i = 0; i < this.m_Area.length; i++) {
|
for (int i = 0; i < this.m_Area.length; i++) {
|
||||||
if (this.m_Area[i] == null) {
|
if (this.m_Area[i] == null) {
|
||||||
EVAERROR.errorMsgOnce("Error in GPIndividualProgramData.defaultInit(): Area["+i+"] == null !!");
|
EVAERROR.errorMsgOnce("Error in GPIndividualProgramData.defaultInit(): Area["+i+"] == null !!");
|
||||||
@ -339,9 +358,9 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
* @param b The new init Depth of the GP Tree.
|
* @param b The new init Depth of the GP Tree.
|
||||||
*/
|
*/
|
||||||
public void setInitDepth(int b) {
|
public void setInitDepth(int b) {
|
||||||
if (b > this.m_maxDepth) {
|
if (b > this.m_maxAllowedDepth) {
|
||||||
System.out.println("Waring Init Depth will be set to Target Depth!");
|
System.out.println("Waring Init Depth will be set to Target Depth!");
|
||||||
b = this.m_maxDepth;
|
b = this.m_maxAllowedDepth;
|
||||||
}
|
}
|
||||||
this.m_InitDepth = b;
|
this.m_InitDepth = b;
|
||||||
}
|
}
|
||||||
@ -355,17 +374,29 @@ public class GPIndividualProgramData extends AbstractEAIndividual implements Int
|
|||||||
/** This method set/get the target depth.
|
/** This method set/get the target depth.
|
||||||
* @param b The new target Depth of the GP Tree.
|
* @param b The new target Depth of the GP Tree.
|
||||||
*/
|
*/
|
||||||
public void setMaxDepth(int b) {
|
public void setMaxAllowedDepth(int b) {
|
||||||
this.m_maxDepth = b;
|
this.m_maxAllowedDepth = b;
|
||||||
}
|
}
|
||||||
public int getMaxDepth() {
|
public int getMaxAllowedDepth() {
|
||||||
return this.m_maxDepth;
|
return this.m_maxAllowedDepth;
|
||||||
}
|
}
|
||||||
public String maxDepthTipText() {
|
public String maxAllowedDepthTipText() {
|
||||||
return "The maximum depth of the GP tree.";
|
return "The maximum depth allowed for the GP tree.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] customPropertyOrder() {
|
public String[] customPropertyOrder() {
|
||||||
return new String[] {"initDepth", "checkMaxDepth", "maxDepth"};
|
return new String[] {"initDepth", "checkMaxDepth", "maxAllowedDepth"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateDepth() {
|
||||||
|
for (int i=0; i<m_Genotype.length; i++) {
|
||||||
|
m_Genotype[i].updateDepth(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkDepth() {
|
||||||
|
for (int i=0; i<m_Genotype.length; i++) {
|
||||||
|
m_Genotype[i].checkDepth(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,9 @@ public interface InterfaceGPIndividual {
|
|||||||
*/
|
*/
|
||||||
public Object[] getFunctionArea();
|
public Object[] getFunctionArea();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the maximal allowed depth of a GP tree (or -1 if it does not apply).
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getMaxAllowedDepth();
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import eva2.server.go.problems.InterfaceProgramProblem;
|
|||||||
import eva2.tools.Pair;
|
import eva2.tools.Pair;
|
||||||
import eva2.tools.ReflectPackage;
|
import eva2.tools.ReflectPackage;
|
||||||
import eva2.tools.math.Mathematics;
|
import eva2.tools.math.Mathematics;
|
||||||
|
import eva2.tools.math.RNG;
|
||||||
|
|
||||||
|
|
||||||
/** This gives an abstract node, with default functionality for get and set methods.
|
/** This gives an abstract node, with default functionality for get and set methods.
|
||||||
@ -56,6 +57,18 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively perform deep cloning of the members of this instance and all sub-nodes.
|
||||||
|
*
|
||||||
|
* @param node the node to clone values from
|
||||||
|
**/
|
||||||
|
protected void cloneMembers(AbstractGPNode node) {
|
||||||
|
this.m_Depth = node.m_Depth;
|
||||||
|
this.m_Parent = node.m_Parent;
|
||||||
|
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
||||||
|
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
||||||
|
}
|
||||||
|
|
||||||
private static void appendStringRepresentation(AbstractGPNode node, StringBuffer sbuf) {
|
private static void appendStringRepresentation(AbstractGPNode node, StringBuffer sbuf) {
|
||||||
String op = node.getOpIdentifier();
|
String op = node.getOpIdentifier();
|
||||||
sbuf.append(op);
|
sbuf.append(op);
|
||||||
@ -350,14 +363,20 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
|||||||
this.m_Nodes[index] = node;
|
this.m_Nodes[index] = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to set a node specified by the index
|
/**
|
||||||
|
* This method allows you to set a node specified by the reference.
|
||||||
* @param newnode The new node.
|
* @param newnode The new node.
|
||||||
* @param oldnode The old node.
|
* @param oldnode The old node.
|
||||||
*/
|
*/
|
||||||
public void setNode(AbstractGPNode newnode, AbstractGPNode oldnode) {
|
public void setNode(AbstractGPNode newnode, AbstractGPNode oldnode) {
|
||||||
newnode.setParent(this);
|
newnode.setParent(this);
|
||||||
newnode.setDepth(this.m_Depth+1);
|
newnode.updateDepth(this.m_Depth+1);
|
||||||
for (int i = 0; i < this.m_Nodes.length; i++) if (this.m_Nodes[i].equals(oldnode)) this.m_Nodes[i] = newnode;
|
for (int i = 0; i < this.m_Nodes.length; i++) {
|
||||||
|
if (this.m_Nodes[i] == oldnode) {
|
||||||
|
this.m_Nodes[i] = newnode;
|
||||||
|
// System.out.println("SWITCHED " + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/** This method returns all nodes begining with the current node.
|
/** This method returns all nodes begining with the current node.
|
||||||
* @param ListOfNodes This ArrayList will contain all nodes
|
* @param ListOfNodes This ArrayList will contain all nodes
|
||||||
@ -367,6 +386,27 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
|||||||
for (int i = 0; i < this.m_Nodes.length; i++) this.m_Nodes[i].addNodesTo(ListOfNodes);
|
for (int i = 0; i < this.m_Nodes.length; i++) this.m_Nodes[i].addNodesTo(ListOfNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a shallow reference to a random node within this tree.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public AbstractGPNode getRandomNode() {
|
||||||
|
ArrayList allNodes = new ArrayList(10);
|
||||||
|
addNodesTo(allNodes);
|
||||||
|
return (AbstractGPNode) allNodes.get(RNG.randomInt(allNodes.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a shallow reference to a random leaf of this tree.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public AbstractGPNode getRandomLeaf() {
|
||||||
|
if (m_Nodes.length>0) {
|
||||||
|
int k=RNG.randomInt(m_Nodes.length);
|
||||||
|
return m_Nodes[k].getRandomLeaf();
|
||||||
|
} else return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** This method allows you to set the parent of the node
|
/** This method allows you to set the parent of the node
|
||||||
* @param parent The new parent
|
* @param parent The new parent
|
||||||
*/
|
*/
|
||||||
@ -435,7 +475,8 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will return the max depth of the tree
|
/**
|
||||||
|
* Return the maximal depth of the tree starting here, but relating to the whole tree.
|
||||||
* @return The max depth.
|
* @return The max depth.
|
||||||
*/
|
*/
|
||||||
public int getMaxDepth() {
|
public int getMaxDepth() {
|
||||||
@ -446,6 +487,16 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the depth of the subtree only.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getSubtreeDepth() {
|
||||||
|
int maxDepth = getMaxDepth();
|
||||||
|
return maxDepth-m_Depth;
|
||||||
|
}
|
||||||
|
|
||||||
/** This method will check if maxdepth is violated
|
/** This method will check if maxdepth is violated
|
||||||
* @param maxDepth The max depth.
|
* @param maxDepth The max depth.
|
||||||
* @return True if MaxDepth is violated
|
* @return True if MaxDepth is violated
|
||||||
@ -503,4 +554,32 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the depth of this node tree starting with the given initial depth of the root.
|
||||||
|
*
|
||||||
|
* @param myDepth
|
||||||
|
*/
|
||||||
|
public void updateDepth(int myDepth) {
|
||||||
|
m_Depth=myDepth;
|
||||||
|
for (int i=0; i<m_Nodes.length; i++) {
|
||||||
|
m_Nodes[i].updateDepth(myDepth+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the depth of this node tree starting with the given initial depth of the root.
|
||||||
|
*
|
||||||
|
* @param myDepth
|
||||||
|
*/
|
||||||
|
public boolean checkDepth(int myDepth) {
|
||||||
|
if (m_Depth!=myDepth) {
|
||||||
|
System.err.println("Depth was wrong at level " + myDepth);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i=0; i<m_Nodes.length; i++) {
|
||||||
|
if (!m_Nodes[i].checkDepth(myDepth+1)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,7 @@ public class GPNodeAbs extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeAbs() {
|
public GPNodeAbs() {
|
||||||
}
|
}
|
||||||
public GPNodeAbs(GPNodeAbs node) {
|
public GPNodeAbs(GPNodeAbs node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -18,10 +18,7 @@ public class GPNodeAdd extends AbstractGPNode implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GPNodeAdd(GPNodeAdd node) {
|
public GPNodeAdd(GPNodeAdd node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -16,10 +16,7 @@ public class GPNodeConst extends AbstractGPNode implements java.io.Serializable
|
|||||||
|
|
||||||
public GPNodeConst(GPNodeConst node) {
|
public GPNodeConst(GPNodeConst node) {
|
||||||
value = node.value;
|
value = node.value;
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,10 +14,7 @@ public class GPNodeCos extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeCos() {
|
public GPNodeCos() {
|
||||||
}
|
}
|
||||||
public GPNodeCos(GPNodeCos node) {
|
public GPNodeCos(GPNodeCos node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -22,10 +22,7 @@ public class GPNodeDiv extends AbstractGPNode implements java.io.Serializable {
|
|||||||
|
|
||||||
public GPNodeDiv(GPNodeDiv node) {
|
public GPNodeDiv(GPNodeDiv node) {
|
||||||
this.m_LowerBorderForSec = node.m_LowerBorderForSec;
|
this.m_LowerBorderForSec = node.m_LowerBorderForSec;
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -14,10 +14,7 @@ public class GPNodeExp extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeExp() {
|
public GPNodeExp() {
|
||||||
}
|
}
|
||||||
public GPNodeExp(GPNodeExp node) {
|
public GPNodeExp(GPNodeExp node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -15,10 +15,7 @@ public class GPNodeFlowExec2 extends AbstractGPNode implements java.io.Serializa
|
|||||||
|
|
||||||
}
|
}
|
||||||
public GPNodeFlowExec2(GPNodeFlowExec2 node) {
|
public GPNodeFlowExec2(GPNodeFlowExec2 node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -15,10 +15,7 @@ public class GPNodeFlowExec3 extends AbstractGPNode implements java.io.Serializa
|
|||||||
|
|
||||||
}
|
}
|
||||||
public GPNodeFlowExec3(GPNodeFlowExec3 node) {
|
public GPNodeFlowExec3(GPNodeFlowExec3 node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -30,10 +30,7 @@ public class GPNodeInput extends AbstractGPNode implements java.io.Serializable
|
|||||||
|
|
||||||
public GPNodeInput(GPNodeInput node) {
|
public GPNodeInput(GPNodeInput node) {
|
||||||
this.m_Identifier = node.m_Identifier;
|
this.m_Identifier = node.m_Identifier;
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdentifier(String str) {
|
public void setIdentifier(String str) {
|
||||||
|
@ -15,10 +15,7 @@ public class GPNodeMult extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeMult() {
|
public GPNodeMult() {
|
||||||
}
|
}
|
||||||
public GPNodeMult(GPNodeMult node) {
|
public GPNodeMult(GPNodeMult node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -15,10 +15,7 @@ public class GPNodeNeg extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeNeg() {
|
public GPNodeNeg() {
|
||||||
}
|
}
|
||||||
public GPNodeNeg(GPNodeNeg node) {
|
public GPNodeNeg(GPNodeNeg node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -9,10 +9,14 @@ public class GPNodeOne extends GPNodeConst implements java.io.Serializable {
|
|||||||
super(1.);
|
super(1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GPNodeOne(GPNodeOne node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
/** This method allows you to clone the Nodes
|
/** This method allows you to clone the Nodes
|
||||||
* @return the clone
|
* @return the clone
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return (Object) new GPNodeOne();
|
return (Object) new GPNodeOne(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,7 @@ public class GPNodeOutput extends AbstractGPNode implements java.io.Serializable
|
|||||||
|
|
||||||
public GPNodeOutput(GPNodeOutput node) {
|
public GPNodeOutput(GPNodeOutput node) {
|
||||||
this.m_Identifier = node.m_Identifier;
|
this.m_Identifier = node.m_Identifier;
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,11 +9,15 @@ public class GPNodePi extends GPNodeConst implements java.io.Serializable {
|
|||||||
super(Math.PI);
|
super(Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method allows you to clone the Nodes
|
public GPNodePi(GPNodePi node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This method allows you to clone the Nodes
|
||||||
* @return the clone
|
* @return the clone
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return (Object) new GPNodePi();
|
return (Object) new GPNodePi(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -14,10 +14,7 @@ public class GPNodePow2 extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodePow2() {
|
public GPNodePow2() {
|
||||||
}
|
}
|
||||||
public GPNodePow2(GPNodePow2 node) {
|
public GPNodePow2(GPNodePow2 node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -14,10 +14,7 @@ public class GPNodePow3 extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodePow3() {
|
public GPNodePow3() {
|
||||||
}
|
}
|
||||||
public GPNodePow3(GPNodePow3 node) {
|
public GPNodePow3(GPNodePow3 node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -14,10 +14,7 @@ public class GPNodeProd extends AbstractGPNode implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GPNodeProd(GPNodeProd node) {
|
public GPNodeProd(GPNodeProd node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -14,10 +14,7 @@ public class GPNodeSin extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeSin() {
|
public GPNodeSin() {
|
||||||
}
|
}
|
||||||
public GPNodeSin(GPNodeSin node) {
|
public GPNodeSin(GPNodeSin node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -15,10 +15,7 @@ public class GPNodeSqrt extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeSqrt() {
|
public GPNodeSqrt() {
|
||||||
}
|
}
|
||||||
public GPNodeSqrt(GPNodeSqrt node) {
|
public GPNodeSqrt(GPNodeSqrt node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -15,10 +15,7 @@ public class GPNodeSub extends AbstractGPNode implements java.io.Serializable {
|
|||||||
public GPNodeSub() {
|
public GPNodeSub() {
|
||||||
}
|
}
|
||||||
public GPNodeSub(GPNodeSub node) {
|
public GPNodeSub(GPNodeSub node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -14,10 +14,7 @@ public class GPNodeSum extends AbstractGPNode implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GPNodeSum(GPNodeSum node) {
|
public GPNodeSum(GPNodeSum node) {
|
||||||
this.m_Depth = node.m_Depth;
|
this.cloneMembers(node);
|
||||||
this.m_Parent = node.m_Parent;
|
|
||||||
this.m_Nodes = new AbstractGPNode[node.m_Nodes.length];
|
|
||||||
for (int i = 0; i < node.m_Nodes.length; i++) this.m_Nodes[i] = (AbstractGPNode) node.m_Nodes[i].clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will be used to identify the node in the GPAreaEditor
|
/** This method will be used to identify the node in the GPAreaEditor
|
||||||
|
@ -4,6 +4,7 @@ package eva2.server.go.operators.crossover;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||||
|
import eva2.server.go.individuals.GPIndividualProgramData;
|
||||||
import eva2.server.go.individuals.InterfaceGPIndividual;
|
import eva2.server.go.individuals.InterfaceGPIndividual;
|
||||||
import eva2.server.go.individuals.codings.gp.AbstractGPNode;
|
import eva2.server.go.individuals.codings.gp.AbstractGPNode;
|
||||||
import eva2.server.go.populations.Population;
|
import eva2.server.go.populations.Population;
|
||||||
@ -18,12 +19,18 @@ import eva2.tools.math.RNG;
|
|||||||
* To change this template use Options | File Templates.
|
* To change this template use Options | File Templates.
|
||||||
*/
|
*/
|
||||||
public class CrossoverGPDefault implements InterfaceCrossover, java.io.Serializable {
|
public class CrossoverGPDefault implements InterfaceCrossover, java.io.Serializable {
|
||||||
private InterfaceOptimizationProblem m_OptimizationProblem;
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 8900427365914281930L;
|
||||||
|
private InterfaceOptimizationProblem m_OptimizationProblem;
|
||||||
|
private boolean maintainMaxDepth = true;
|
||||||
|
private static final boolean TRACE=false;
|
||||||
|
|
||||||
public CrossoverGPDefault() {
|
public CrossoverGPDefault() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public CrossoverGPDefault(CrossoverGPDefault c) {
|
public CrossoverGPDefault(CrossoverGPDefault c) {
|
||||||
|
this.maintainMaxDepth = c.maintainMaxDepth;
|
||||||
this.m_OptimizationProblem = c.m_OptimizationProblem;
|
this.m_OptimizationProblem = c.m_OptimizationProblem;
|
||||||
}
|
}
|
||||||
/** This method will enable you to clone a given mutation operator
|
/** This method will enable you to clone a given mutation operator
|
||||||
@ -33,53 +40,67 @@ public class CrossoverGPDefault implements InterfaceCrossover, java.io.Serializa
|
|||||||
return new CrossoverGPDefault(this);
|
return new CrossoverGPDefault(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method performs crossover on two individuals. If the individuals do
|
/**
|
||||||
* not implement InterfaceGAIndividual, then nothing will happen.
|
* Exchange subtrees of two GP nodes. Allows to keep the depth restriction.
|
||||||
|
*
|
||||||
* @param indy1 The first individual
|
* @param indy1 The first individual
|
||||||
* @param partners The second individual
|
* @param partners The second individual
|
||||||
*/
|
*/
|
||||||
public AbstractEAIndividual[] mate(AbstractEAIndividual indy1, Population partners) {
|
public AbstractEAIndividual[] mate(AbstractEAIndividual indy1, Population partners) {
|
||||||
|
if (partners.size()>1) System.err.println("Warning, crossover may not work on more than one partner! " + this.getClass());
|
||||||
AbstractEAIndividual[] result = null;
|
AbstractEAIndividual[] result = null;
|
||||||
result = new AbstractEAIndividual[partners.size()+1];
|
result = new AbstractEAIndividual[partners.size()+1];
|
||||||
result[0] = (AbstractEAIndividual) (indy1).clone();
|
result[0] = (AbstractEAIndividual) (indy1).clone();
|
||||||
for (int i = 0; i < partners.size(); i++) result[i+1] = (AbstractEAIndividual) ((AbstractEAIndividual)partners.get(i)).clone();
|
for (int i = 0; i < partners.size(); i++) result[i+1] = (AbstractEAIndividual) ((AbstractEAIndividual)partners.get(i)).clone();
|
||||||
//for (int i = 0; i < result.length; i++) System.out.println("Before Crossover: " +result[i].getSolutionRepresentationFor());
|
if (TRACE) for (int i = 0; i < result.length; i++) System.out.println("Before Crossover: " +result[i].getStringRepresentation());
|
||||||
if (partners.size() == 0) return result;
|
if (partners.size() == 0) return result;
|
||||||
if ((indy1 instanceof InterfaceGPIndividual) && (partners.get(0) instanceof InterfaceGPIndividual)) {
|
if ((indy1 instanceof InterfaceGPIndividual) && (partners.get(0) instanceof InterfaceGPIndividual)) {
|
||||||
|
int allowedDepth = ((InterfaceGPIndividual)indy1).getMaxAllowedDepth();
|
||||||
//select node from 0 and memorize parent
|
|
||||||
ArrayList allNodes = new ArrayList();
|
|
||||||
AbstractGPNode[] nodes = ((InterfaceGPIndividual)result[0]).getPGenotype();
|
AbstractGPNode[] nodes = ((InterfaceGPIndividual)result[0]).getPGenotype();
|
||||||
for (int t = 0; t < nodes.length; t++) {
|
for (int t = 0; t < nodes.length; t++) { // for each of the genotypes (multiploidy??)
|
||||||
allNodes = new ArrayList();
|
((InterfaceGPIndividual)result[0]).getPGenotype()[t].getRandomNode();
|
||||||
((InterfaceGPIndividual)result[0]).getPGenotype()[t].addNodesTo(allNodes);
|
AbstractGPNode selNodeThis = ((InterfaceGPIndividual)result[0]).getPGenotype()[t].getRandomNode();
|
||||||
AbstractGPNode oldNode = (AbstractGPNode) allNodes.get(RNG.randomInt(0, allNodes.size()-1));
|
AbstractGPNode selNodeOther = ((InterfaceGPIndividual)result[1]).getPGenotype()[t].getRandomNode();
|
||||||
AbstractGPNode newNode, memorizingNode = oldNode, tmpNode;
|
if (maintainMaxDepth) {//System.err.print(".");
|
||||||
AbstractGPNode oldParent, newParent;
|
int maxTries=10;
|
||||||
oldParent = oldNode.getParent();
|
// if the echange would violate the depth restriction, choose new nodes for a few times...
|
||||||
for (int i = 1; i < result.length; i++) {
|
while (maxTries>=0 && ((selNodeOther.getSubtreeDepth()+selNodeThis.getDepth()>allowedDepth) ||
|
||||||
// choose Node from i and add it to i-1
|
(selNodeThis.getSubtreeDepth()+selNodeOther.getDepth()>allowedDepth))) {
|
||||||
allNodes = new ArrayList();
|
if (RNG.flipCoin(0.5)) selNodeThis = ((InterfaceGPIndividual)result[0]).getPGenotype()[t].getRandomNode();
|
||||||
((InterfaceGPIndividual)result[i]).getPGenotype()[t].addNodesTo(allNodes);
|
else selNodeOther = ((InterfaceGPIndividual)result[1]).getPGenotype()[t].getRandomNode();
|
||||||
newNode = (AbstractGPNode) allNodes.get(RNG.randomInt(0, allNodes.size()-1));
|
maxTries--;
|
||||||
tmpNode = newNode;
|
}
|
||||||
newParent = tmpNode.getParent();
|
if (maxTries<0) { // on a failure, at least exchange two leaves, which always works
|
||||||
if (oldParent == null) ((InterfaceGPIndividual)result[i-1]).SetPGenotype(newNode, t);
|
// System.err.println("Unable to select fitting nodes! Just switch leaves...");
|
||||||
else oldParent.setNode(newNode, oldNode);
|
selNodeThis = ((InterfaceGPIndividual)result[0]).getPGenotype()[t].getRandomLeaf();
|
||||||
oldNode = tmpNode;
|
selNodeOther = ((InterfaceGPIndividual)result[1]).getPGenotype()[t].getRandomLeaf();
|
||||||
oldParent = newParent;
|
}
|
||||||
}
|
}
|
||||||
// add node from 0 to result.length-1
|
if (TRACE) {
|
||||||
if (oldParent == null) {
|
System.out.println("Selected t " + selNodeThis.getStringRepresentation());
|
||||||
((InterfaceGPIndividual)result[result.length-1]).SetPGenotype(memorizingNode, t);
|
System.out.println("Selected o " + selNodeOther.getStringRepresentation());
|
||||||
} else {
|
|
||||||
oldParent.setNode(memorizingNode, oldNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractGPNode selNodeThisParent, selNodeOtherParent;
|
||||||
|
selNodeThisParent = selNodeThis.getParent();
|
||||||
|
selNodeOtherParent = selNodeOther.getParent();
|
||||||
|
|
||||||
|
// actually switch individuals!
|
||||||
|
if (selNodeThisParent == null) ((InterfaceGPIndividual)result[0]).SetPGenotype((AbstractGPNode)selNodeOther.clone(), t);
|
||||||
|
else selNodeThisParent.setNode((AbstractGPNode)selNodeOther.clone(), selNodeThis);
|
||||||
|
// for (int i = 0; i < result.length; i++) System.out.println("-- Betw Crossover: " +result[i].getStringRepresentation());
|
||||||
|
if (selNodeOtherParent == null) ((InterfaceGPIndividual)result[1]).SetPGenotype((AbstractGPNode)selNodeThis.clone(), t);
|
||||||
|
else selNodeOtherParent.setNode((AbstractGPNode)selNodeThis.clone(), selNodeOther);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//in case the crossover was successfull lets give the mutation operators a chance to mate the strategy parameters
|
//in case the crossover was successfull lets give the mutation operators a chance to mate the strategy parameters
|
||||||
for (int i = 0; i < result.length; i++) result[i].getMutationOperator().crossoverOnStrategyParameters(indy1, partners);
|
for (int i = 0; i < result.length; i++) {
|
||||||
//for (int i = 0; i < result.length; i++) System.out.println("After Crossover: " +result[i].getSolutionRepresentationFor());
|
((GPIndividualProgramData)result[i]).checkDepth();
|
||||||
|
result[i].getMutationOperator().crossoverOnStrategyParameters(indy1, partners);
|
||||||
|
}
|
||||||
|
if (TRACE) for (int i = 0; i < result.length; i++) System.out.println("After Crossover: " +result[i].getStringRepresentation());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
|
|||||||
*/
|
*/
|
||||||
public static int getIndySize(AbstractEAIndividual indy) {
|
public static int getIndySize(AbstractEAIndividual indy) {
|
||||||
if (indy instanceof InterfaceDataTypeProgram) {
|
if (indy instanceof InterfaceDataTypeProgram) {
|
||||||
InterfaceProgram prog = ((InterfaceDataTypeProgram)indy).getProgramData()[0];
|
InterfaceProgram prog = ((InterfaceDataTypeProgram)indy).getProgramDataWithoutUpdate()[0];
|
||||||
if (prog instanceof AbstractGPNode) {
|
if (prog instanceof AbstractGPNode) {
|
||||||
AbstractGPNode gpNode = (AbstractGPNode)prog;
|
AbstractGPNode gpNode = (AbstractGPNode)prog;
|
||||||
return gpNode.getNumberOfNodes();
|
return gpNode.getNumberOfNodes();
|
||||||
@ -584,7 +584,7 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the depth of an individual representing a program or null
|
* Return the maximal depth of an individual representing a program or null
|
||||||
* if it is of an incompatible type.
|
* if it is of an incompatible type.
|
||||||
*
|
*
|
||||||
* @param indy
|
* @param indy
|
||||||
@ -592,10 +592,14 @@ public class PSymbolicRegression extends AbstractOptimizationProblem implements
|
|||||||
*/
|
*/
|
||||||
public static int getIndyDepth(AbstractEAIndividual indy) {
|
public static int getIndyDepth(AbstractEAIndividual indy) {
|
||||||
if (indy instanceof InterfaceDataTypeProgram) {
|
if (indy instanceof InterfaceDataTypeProgram) {
|
||||||
InterfaceProgram prog = ((InterfaceDataTypeProgram)indy).getProgramData()[0];
|
InterfaceProgram prog = ((InterfaceDataTypeProgram)indy).getProgramDataWithoutUpdate()[0];
|
||||||
if (prog instanceof AbstractGPNode) {
|
if (prog instanceof AbstractGPNode) {
|
||||||
AbstractGPNode gpNode = (AbstractGPNode)prog;
|
AbstractGPNode gpNode = (AbstractGPNode)prog;
|
||||||
return gpNode.getMaxDepth();
|
int d = gpNode.getMaxDepth();
|
||||||
|
//if (!gpNode.checkDepth(0)) {
|
||||||
|
// System.out.println(d + "\n" + gpNode.getStringRepresentation());
|
||||||
|
//}
|
||||||
|
return d;
|
||||||
} else return 0;
|
} else return 0;
|
||||||
} else return 0;
|
} else return 0;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
|
|||||||
// plot the column as indicated by the graph description
|
// plot the column as indicated by the graph description
|
||||||
if (currentStatDoubleData[colIndex]!=null) plotFitnessPoint(0, subGraph++, functionCalls, currentStatDoubleData[colIndex]);
|
if (currentStatDoubleData[colIndex]!=null) plotFitnessPoint(0, subGraph++, functionCalls, currentStatDoubleData[colIndex]);
|
||||||
else {
|
else {
|
||||||
EVAERROR.errorMsgOnce("Error, data field " + graphDesc.get(i).head + " does not contain primitive data and cannot be plotted.");
|
// EVAERROR.errorMsgOnce("Error, data field " + graphDesc.get(i).head + " does not contain primitive data and cannot be plotted.");
|
||||||
subGraph++; // increase index anyways or the name assignment gets inconsistent
|
subGraph++; // increase index anyways or the name assignment gets inconsistent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user