Class TreeIndividual
Represents an individual in genetic programming with a tree structure.
public class TreeIndividual : IEvolvable<NodeGene, double>
- Inheritance
-
TreeIndividual
- Implements
- Inherited Members
Constructors
TreeIndividual(NodeGene)
Creates a tree individual with the specified root node.
public TreeIndividual(NodeGene rootNode)
Parameters
rootNodeNodeGeneThe root node of the tree.
TreeIndividual(Random, List<string>, bool)
Creates a new tree individual with a random tree.
public TreeIndividual(Random random, List<string> terminals, bool fullMethod = false)
Parameters
randomRandomRandom number generator for initialization.
terminalsList<string>The terminal symbols available.
fullMethodboolWhether to use the full or grow method.
Methods
Clone()
Creates a deep clone of this individual.
public IEvolvable<NodeGene, double> Clone()
Returns
- IEvolvable<NodeGene, double>
A clone of this individual.
Evaluate(Dictionary<string, double>)
Evaluates the tree for a given input and returns the result.
public double Evaluate(Dictionary<string, double> variables)
Parameters
variablesDictionary<string, double>
Returns
GetDepth()
Gets the depth of the tree.
public int GetDepth()
Returns
GetExpression()
Gets a string representation of the tree.
public string GetExpression()
Returns
GetFitness()
Gets the fitness of this individual.
public double GetFitness()
Returns
- double
The fitness score.
GetGenes()
Gets the genes of this individual.
public ICollection<NodeGene> GetGenes()
Returns
- ICollection<NodeGene>
The collection of genes.
PermutationMutation()
Performs permutation mutation by randomizing the order of arguments.
public void PermutationMutation()
PointMutation()
Performs point mutation on the tree by changing a random terminal or function.
public void PointMutation()
ReplaceSubtree(NodeGene, NodeGene)
Replaces a subtree with another subtree.
public void ReplaceSubtree(NodeGene target, NodeGene replacement)
Parameters
SelectRandomNode()
Selects a random node from the tree.
public NodeGene SelectRandomNode()
Returns
SetFitness(double)
Sets the fitness of this individual.
public void SetFitness(double fitness)
Parameters
fitnessdoubleThe fitness score to set.
SetGenes(ICollection<NodeGene>)
Sets the genes of this individual.
public void SetGenes(ICollection<NodeGene> genes)
Parameters
genesICollection<NodeGene>The genes to set.
SubtreeMutation()
Performs subtree mutation by replacing a random subtree with a new one.
public void SubtreeMutation()