Beispiel #1
0
        protected override Gene <Function>[] MutationFunction(Gene <Function>[] genes)
        {
            var func    = genes[0].Value;
            var funcVal = CalculateFunctionValue(func);

            INode randomOp = null;

            Function tempFunc            = null;
            var      betterSolutionFound = false;
            int      c = 0;

            while (!betterSolutionFound && c < 1000)
            {
                c++;
                tempFunc = func.Clone();
                randomOp = null;
                while (randomOp == null)
                {
                    randomOp = tempFunc.GetRandomOp();
                }

                _fGen.GenerateFromStartNode(_ffabric, randomOp.GetMaxDepth(0), randomOp);

                var tempFuncVal = CalculateFunctionValue(tempFunc);
                if (tempFuncVal < funcVal)
                {
                    betterSolutionFound = true;
                }
            }

            if (!betterSolutionFound)
            {
                tempFunc = func.Clone();
            }

            return(new Gene <Function>[] { new Gene <Function>(tempFunc) });
        }