|
// AForge Genetic Library
//
// Copyright � Andrew Kirillov, 2006
// andrew.kirillov@gmail.com
//
namespace AForge.Genetic
{
using System;
using System.Collections;
using System.Text;
/// <summary>
/// Represents tree node of genetic programming tree
/// </summary>
public class GPTreeNode : ICloneable
{
// node's gene
public IGPGene Gene;
//
public ArrayList Children;
/// <summary>
/// Constructor
/// </summary>
public GPTreeNode( ) { }
/// <summary>
/// Constructor
/// </summary>
public GPTreeNode( IGPGene gene )
{
Gene = gene;
}
/// <summary>
/// Get string representation of the node
/// </summary>
public override string ToString( )
{
StringBuilder sb = new StringBuilder( );
if ( Children != null )
{
// walk through all nodes
foreach ( GPTreeNode node in Children )
{
sb.Append( node.ToString( ) );
}
}
// add gene value
sb.Append( Gene.ToString( ) );
sb.Append( " " );
return sb.ToString( );
}
/// <summary>
/// Clone the tree node
/// </summary>
public object Clone( )
{
GPTreeNode clone = new GPTreeNode( );
// clone gene
clone.Gene = this.Gene.Clone( );
// clone its children
if ( this.Children != null )
{
clone.Children = new ArrayList( );
// clone each child gene
foreach ( GPTreeNode node in Children )
{
clone.Children.Add( node.Clone( ) );
}
}
return clone;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like
AForge.NET,
Computer Vision Sandbox,
cam2web,
ANNT, etc.