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); }
/// <summary> /// Increases Arguments to accommodate space if necessary. Sets adf to a. /// You need to then fill out the Arguments yourself. /// </summary> public void PrepareADF(ADF a, GPProblem problem) { // set to the length requested or longer if (a.Children.Length > Arguments.Length) { var newArguments = new GPData[a.Children.Length]; Array.Copy(Arguments, 0, newArguments, 0, Arguments.Length); // fill gap -- ugh, luckily this doesn't happen but a few times for (var x = Arguments.Length; x < newArguments.Length; x++) { newArguments[x] = (GPData)problem.Input.Clone(); } Arguments = newArguments; } Adf = a; }
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()); } }
public override void Setup(IEvolutionState state, IParameter paramBase) { var def = DefaultBase; // BRS: MUST set up GPData before ADFStack, so that ADFContext has access to state.Evaluator.p_problem.Data // This avoids a reference to GPProblem.P_DATA, and thus allows us to use interfaces instead of concrete types // Important for decoupling and Inversion of Control (IoC). IParameter p = paramBase.Push(P_DATA); Input = (GPData)state.Parameters.GetInstanceForParameterEq(p, def.Push(P_DATA), typeof(GPData)); Input.Setup(state, p); p = paramBase.Push(P_STACK); Stack = (ADFStack)state.Parameters.GetInstanceForParameterEq(p, def.Push(P_STACK), typeof(ADFStack)); Stack.Setup(state, p); }
/// <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()); } } }
/// <summary> /// Modifies gpd so that gpd is equivalent to us. You may /// safely assume that gpd is of the same class as we are. /// Do not share references with the other object, except to /// read-only data: instead, copy any read-write data as necessary. /// </summary> public virtual void CopyTo(GPData gpd) { }