Пример #1
0
        public void PermutateRandomNode()
        {
            List <GSTreeNode> nodes = new List <GSTreeNode>();

            GSTreeTraverse.GetDoubleArgFunctionNodes(root, nodes);
            System.Random rand = new System.Random();
            GSTreeNode    node = nodes[rand.Next(nodes.Count)];
            GSTreeNode    temp = node.left;

            node.left  = node.right;
            node.right = temp;
        }
Пример #2
0
        public void CrossoverRandom(GSTree treeB)
        {
            List <GSTreeNode> nodes = new List <GSTreeNode>();

            GSTreeTraverse.GetDoubleArgFunctionNodes(treeB.root, nodes);
            System.Random rand  = new System.Random();
            GSTreeNode    nodeB = nodes[rand.Next(nodes.Count)];

            nodes = new List <GSTreeNode>();
            GSTreeTraverse.GetDoubleArgFunctionNodes(root, nodes);
            rand = new System.Random();
            GSTreeNode nodeA = nodes[rand.Next(nodes.Count)];

            GSTreeNode newTree = new GSTreeNode();

            newTree.left  = nodeB.left;
            newTree.right = nodeA.right;
            nodeA         = (GSTreeNode)newTree.Clone();
        }
Пример #3
0
        public void InsertRandomNode()
        {
            System.Random     rand  = new System.Random();
            List <GSTreeNode> nodes = new List <GSTreeNode>();

            GSTreeTraverse.GetDoubleArgFunctionNodes(root, nodes);
            GSTreeNode selNode  = nodes[rand.Next(nodes.Count)];
            GSTreeNode tempNode = selNode.left;

            GSTreeNode newNode = new GSTreeNode();

            selNode.left = newNode;

            if (rand.Next(0, 2) == 1)
            {
                newNode.value = GSDictionaries.GetRandomDoubleArgFunction();
                newNode.left  = tempNode;
                newNode.right = new GSTreeNode();
                string randValue;
                if (rand.Next(0, 2) == 1)
                {
                    randValue = "(" + GetRandomFloat() + ")";
                }
                else
                {
                    if (positionTree)
                    {
                        randValue = "(" + GSDictionaries.GetRandomPositionVariable() + ")";
                    }
                    else
                    {
                        randValue = "(" + GSDictionaries.GetRandomColorVariable() + ")";
                    }
                }
                newNode.right.value = randValue;
            }
            else
            {
                newNode.value = GSDictionaries.GetRandomSingleArgFunction();
                newNode.left  = tempNode;
            }
        }