示例#1
0
        public virtual void DoWork(RunFitnessCaseCompletedHandler handler)
        {
            IGPEnvironment        env = mPop.Environment as IGPEnvironment;
            int                   fitness_case_count = env.GetFitnessCaseCount();
            List <IGPFitnessCase> cases = new List <IGPFitnessCase>();

            for (int i = 0; i < fitness_case_count; ++i)
            {
                IGPFitnessCase fitness_case = env.CreateFitnessCase(i);

                for (int tindex = 0; tindex < mTrees.Count; ++tindex)
                {
                    fitness_case.StoreOutput(mTrees[tindex].ExecuteOnFitnessCase(fitness_case), tindex);
                }

                handler(fitness_case);
            }
        }
        /// <summary>
        /// Method that executes the GP based on a fitness case and return a value as the output of the GP tree
        /// </summary>
        /// <param name="fitness_case">The fitness case which contains' the program's external inputs and stores the program's output</param>
        /// <returns>The output returned after executing the GP program</returns>
        public virtual object ExecuteOnFitnessCase(IGPFitnessCase fitness_case, params object[] tags)
        {
            mConstantSet.Update(tags);
            List <string> variable_names = mVariableSet.TerminalNames;

            foreach (string variable_name in variable_names)
            {
                object input;
                if (fitness_case.QueryInput(variable_name, out input))
                {
                    mVariableSet.FindTerminalBySymbol(variable_name).Value = input;
                }
                else
                {
                    mVariableSet.FindTerminalBySymbol(variable_name).Value = 0;
                }
            }
            return(mRootNode.Evaluate(tags));
        }
 public override object ExecuteOnFitnessCase(IGPFitnessCase fitness_case, params object[] tags)
 {
     Express();
     return(base.ExecuteOnFitnessCase(fitness_case, tags));
 }