Example #1
0
        public double Evaluate(Program program)
        {
            Tree.Variable XVariable = program.Variables[0];
            double        fitness   = 0;

            for (int x = -5; x < 5; x += 1)
            {
                XVariable.Value = x;
                program.Run();
                double desiredResult = (x * x) - x;
                fitness += Math.Abs(program.Result - desiredResult);
            }

            fitness += (double)program.TreeSize / 5D;

            return(fitness);
        }
Example #2
0
        public double Evaluate(Program program)
        {
            Tree.Variable XVariable = program.Variables[0];
            double        fitness   = 0;

            int[] Ys = new int[] { 0, 2, -4, 6, -8, 10, -12, 14, -16, 18, -20 };

            for (int x = 0; x < 10; x += 1)
            {
                XVariable.Value = x;
                program.Run();
                double desiredResult = Ys[x];
                fitness += Math.Abs(program.Result - desiredResult);
            }

            fitness += (double)program.TreeSize / 5D;

            return(fitness);
        }
Example #3
0
        public double Evaluate(Program program)
        {
            Tree.Variable XVariable = program.Variables[0];
            double        fitness   = 0;

            int[] Xs = new int[] { 1, 2, 6, 12, 20 };

            for (int x = 0; x < 8; x += 1)
            {
                XVariable.Value = x;
                program.Run();
                double desiredResult = Xs[x];
                fitness += Math.Abs(program.Result - desiredResult);
            }

            fitness += (double)program.TreeSize / 5D;

            return(fitness);
        }
Example #4
0
        public Engine(IFitnessFunction fitnessFunction)
        {
            m_FitnessFunction = fitnessFunction;

            m_Variables = new Tree.Variable[m_FitnessFunction.Variables.Length];
            for (int i = 0; i < m_FitnessFunction.Variables.Length; i++)
            {
                m_Variables[i] = new Tree.Variable(m_FitnessFunction.Variables[i], -1000);
            }

            m_Functions = new Tree.Func[] {
                //new Tree.FuncMultiply(),
                new Tree.FuncAdd(),
                //new Tree.FuncModulo(),
                new Tree.FuncSubtract(),
                new Tree.FuncMax(),
                new Tree.FuncIf(Tree.Comparator.GreaterThan),
                new Tree.FuncIf(Tree.Comparator.Equal),
                //new Tree.FuncIf(Tree.Comparator.GreaterThanOrEqual),
                new Tree.FuncAnd(),
                new Tree.FuncOr()
            };
            m_Values = new int[] { 0, 1, 2, 3 };
        }
Example #5
0
 public VariableNode(Variable variable)
 {
     m_Variable = variable;
 }