コード例 #1
0
ファイル: GeneticTree.cs プロジェクト: natsirt20/School
        public IEnumerable<GeneticTree> Combine(GeneticTree otherParent)
        {
            var binaryNodeMom = _nodes as BinaryOperator;
            var binaryNodeDad = otherParent._nodes as BinaryOperator;
            if (binaryNodeMom != null && binaryNodeDad != null)
            {
                var firstChild = (BinaryOperator) Activator.CreateInstance(binaryNodeMom.GetType());
                firstChild.LeftElement = binaryNodeMom.LeftElement;
                firstChild.RightElement = binaryNodeDad.RightElement;
                var tree = new GeneticTree(_lowerBoundary, _upperBoundary)
                {
                    Name = "Algorithm " + AlgorithmFactory.BabyNumbah++,
                };
                tree.AddOperations(firstChild);
                yield return tree;

                var secondChild = (BinaryOperator)Activator.CreateInstance(binaryNodeMom.GetType());
                secondChild.LeftElement = binaryNodeMom.RightElement;
                secondChild.RightElement = binaryNodeDad.LeftElement;
                tree = new GeneticTree(_lowerBoundary, _upperBoundary)
                {
                    Name = "Algorithm " + AlgorithmFactory.BabyNumbah++,
                };
                tree.AddOperations(secondChild);
                yield return tree;
            }

            yield return this;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: natsirt20/School
 private static void PrintTree(GeneticTree tree)
 {
     var output = string.Format("{0}: {1:0}{2, 15}[{3}]", tree.Name, tree.GetResult(), string.Empty, tree.GetDisplay());
     Console.WriteLine(output);
 }