Пример #1
0
        public string WriteTree()
        {
            StringBuilder sb = new StringBuilder();

            GSTreeTraverse.TraverseTreeWrite(root, sb);
            return(sb.ToString());
        }
Пример #2
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;
        }
Пример #3
0
        public void MutateRandomNode()
        {
            List <GSTreeNode> nodes = new List <GSTreeNode>();

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

            if (GSDictionaries.BasicFunctions.ContainsKey(node.value) ||
                GSDictionaries.DoubleArgFunctions.ContainsKey(node.value))
            {
                node.value = GSDictionaries.GetDifferentDoubleArgFunction(node.value);
            }
            else if (GSDictionaries.SingleArgFunctions.ContainsKey(node.value))
            {
                node.value = GSDictionaries.GetDifferentSingleArgFunction(node.value);
            }
        }
Пример #4
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();
        }
Пример #5
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;
            }
        }