예제 #1
0
파일: ADF.cs 프로젝트: lulzzz/BraneCloud
        public override void Eval(IEvolutionState state, int thread, GPData input, ADFStack stack, GPIndividual individual, IProblem problem)
        {
            // get a context and prepare it
            var c = stack.Take();

            c.PrepareADF(this, (GPProblem)problem);

            // evaluate my Arguments and load 'em in
            for (var x = 0; x < Children.Length; x++)
            {
                input.CopyTo(c.Arguments[x]);
                Children[x].Eval(state, thread, c.Arguments[x], stack, individual, problem);
            }

            // Now push the context onto the stack.
            stack.Push(c);

            // evaluate the top of the associatedTree
            individual.Trees[AssociatedTree].Child.Eval(state, thread, input, stack, individual, problem);

            // pop the context off, and we're done!
            if (stack.Pop(1) != 1)
            {
                state.Output.Fatal("Stack prematurely empty for " + ToStringForError());
            }
        }
예제 #2
0
        public override void Eval(IEvolutionState state, int thread, GPData input, ADFStack stack, GPIndividual individual, IProblem problem)
        {
            // get the current context
            var c = stack.Top(0);

            if (c == null)
            {
                // uh oh
                state.Output.Fatal("No context with which to evaluate ADFArgument terminal " + ToStringForError()
                                   + ".  This often happens if you evaluate a tree by hand  which is supposed to only be an ADF's associated tree.");
            }

            c.Evaluate(state, thread, input, stack, individual, problem, Argument);
        }
예제 #3
0
        public override void Eval(IEvolutionState state, int thread, GPData input, ADFStack stack, GPIndividual individual, IProblem problem)
        {
            // prepare a context
            var c = stack.Push(stack.Take());

            c.PrepareADM(this);

            // evaluate the top of the associatedTree
            individual.Trees[AssociatedTree].Child.Eval(state, thread, input, stack, individual, problem);

            // pop the context off, and we're done!
            if (stack.Pop(1) != 1)
            {
                state.Output.Fatal("Stack prematurely empty for " + ToStringForError());
            }
        }
예제 #4
0
        /// <summary>
        /// Evaluates the argument number in the current context
        /// </summary>
        public virtual void Evaluate(IEvolutionState state, int thread, GPData input, ADFStack stack,
                                     GPIndividual individual, IProblem problem, int argument)
        {
            // do I have that many Arguments?
            if ((argument >= Adf.Children.Length) || argument < 0)
            // uh oh
            {
                individual.PrintIndividual(state, 0);
                state.Output.Fatal("Invalid argument number for " + Adf.ErrorInfo());
            }

            // Am I an ADM or an ADF?
            //if (Adf == null)
            //    state.Output.Fatal("ADF is null for " + Adf.ErrorInfo());
            //else

            if (!(Adf is ADM)) // it's an ADF
            {
                Arguments[argument].CopyTo(input);
            }
            else // it's an ADM
            {
                // get rid of my context temporarily
                if (stack.MoveOntoSubstack(1) != 1)
                {
                    state.Output.Fatal("Substack prematurely empty for " + Adf.ErrorInfo());
                }

                // Call the GPNode
                Adf.Children[argument].Eval(state, thread, input, stack, individual, problem);

                // restore my context
                if (stack.MoveFromSubstack(1) != 1)
                {
                    state.Output.Fatal("Stack prematurely empty for " + Adf.ErrorInfo());
                }
            }
        }