示例#1
0
        static void TestHashSet()
        {
            ICrossedTree root = FunctionContainer.CreateFunctionContainer_TwoArgs("Сложение");

            ICrossedTree sin = FunctionContainer.CreateFunctionContainer_OneArg("Синус");

            ICrossedTree cos = FunctionContainer.CreateFunctionContainer_OneArg("Косинус");

            ICrossedTree arg1 = FunctionContainer.CreateFunctionContainer_SameArgs(1);

            ICrossedTree arg2 = FunctionContainer.CreateFunctionContainer_SameArgs(2);

            root.AddChild(sin);
            root.AddChild(cos);

            sin.AddChild(arg1);
            cos.AddChild(arg2);

            HashSet <ICrossedTree> crossedTrees = new HashSet <ICrossedTree>();

            crossedTrees.Add(root);
            crossedTrees.Add(root);
            crossedTrees.Add(root);
            crossedTrees.Add(root);

            Console.WriteLine(crossedTrees.Count);

            crossedTrees.Add(root.Clone);
            crossedTrees.Add(root.Clone);
            crossedTrees.Add(root.Clone);

            Console.WriteLine(crossedTrees.Count);
        }
示例#2
0
        public static ICrossedTree CrossRouletteTrees(ICrossedTree[] trees)
        {
            ICrossedTree resultTree = trees[Auxiliary.SelectCandidateIndex(trees.Select(t => t.Rating).ToArray())].Clone;

            while (resultTree.NeedMoreChilds())
            {
                List <ICrossedTree> childs = new List <ICrossedTree>();

                foreach (var tree in trees)
                {
                    childs.AddRange(tree.GetChilds());
                }

                resultTree.AddChild(CrossRouletteTrees(childs.ToArray()));
            }

            return(resultTree);
        }