AForge.Genetic.GPCustomTreeNode.Generate C# (CSharp) Метод

Generate() публичный Метод

public Generate ( IEnumerable notes ) : void
notes IEnumerable
Результат void
        public void Generate(IEnumerable<Note> notes)
        {
            var node = this;
            foreach (Note n in notes)
            {
                node.Gene = new NoteGene(0, 0, 0, NoteGene.FunctionTypes.Concatenation, GPGeneType.Function);
                node.Children = new List<GPCustomTreeNode>(2);
                node.Children.Add(new GPCustomTreeNode(new NoteGene(n.NotePitch, (Durations)n.Duration, n.Octave, NoteGene.FunctionTypes.Concatenation, GPGeneType.Argument)));
                node.Children.Add(new GPCustomTreeNode(new NoteGene(0, 0, 0, NoteGene.FunctionTypes.Concatenation, GPGeneType.Function)));
                node = node.Children[1];
            }
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Generate chromosome's subtree of specified level.
        /// </summary>
        /// 
        /// <param name="node">Sub tree's node to generate.</param>
        /// <param name="level">Sub tree's level to generate.</param>
        /// 
        protected void Generate(GPCustomTreeNode node, int level)
        {
            if(generator != null)
            {
                if (level == 0)
                {
                    node.Gene = root.Gene.CreateNew(GPGeneType.Argument);
                }
                else
                {
                    var notes = generator.Generate();
                    List<Note> notes_cut = new List<Note>();
                    int j = 0;
                    int max = (int)Math.Pow(2,level-1);
                    foreach(Note n in notes.Notes)
                    {
                        if(j>max)
                        {
                            if (n.Velocity <= 0 || n.Pitch < 0)
                                break;
                        }
                        notes_cut.Add(n);
                    }
                    node.Generate(notes_cut);
                }
                return;
            }

            /// OLD !!!
            // create gene for the node
            if (level == 0)
            {
                // the gene should be an argument
                node.Gene = root.Gene.CreateNew(GPGeneType.Argument);
            }
            else
            {
                // the gene can be function or argument
                node.Gene = root.Gene.CreateNew();
            }

            // add children
            if (node.Gene.ArgumentsCount != 0)
            {
                node.Children = new List<GPCustomTreeNode>();
                for (int i = 0; i < node.Gene.ArgumentsCount; i++)
                {
                    // create new child
                    GPCustomTreeNode child = new GPCustomTreeNode();
                    Generate(child, level - 1);
                    // add the new child
                    node.Children.Add(child);
                }
            }
        }