Exemplo n.º 1
0
        /// <summary>
        /// Provides a brand-new individual to fill in a population.  The default form
        /// simply calls clone(), creates a fitness, sets evaluated to false, and sets
        /// the species.  If you need to make a more custom genotype (as is the case
        /// for GPSpecies, which requires a light rather than deep clone),
        /// you will need to override this method as you see fit.
        /// </summary>
        public virtual Individual NewIndividual(IEvolutionState state, int thread)
        {
            var newind = (Individual)I_Prototype.Clone();

            // Set the fitness
            newind.Fitness   = (Fitness)F_Prototype.Clone();
            newind.Evaluated = false;

            // Set the species to me
            newind.Species = this;

            // ...and we're ready!
            return(newind);
        }
Exemplo n.º 2
0
 public virtual object Clone()
 {
     try
     {
         var myobj = (Species)(base.MemberwiseClone());
         myobj.I_Prototype    = (Individual)I_Prototype.Clone();
         myobj.F_Prototype    = (Fitness)F_Prototype.Clone();
         myobj.Pipe_Prototype = (BreedingPipeline)Pipe_Prototype.Clone();
         return(myobj);
     }
     catch (Exception)
     {
         throw new ApplicationException();
     } // never happens
 }
Exemplo n.º 3
0
        /// <summary>
        /// Provides an individual read from a DataInput source, including
        /// the fitness.  Doesn't
        /// close the DataInput.  Sets evaluated to false and sets the species.
        /// If you need to make a more custom mechanism (as is the case
        /// for GPSpecies, which requires a light rather than deep clone),
        /// you will need to override this method as you see fit.
        /// </summary>
        public virtual Individual NewIndividual(IEvolutionState state, BinaryReader dataInput)
        {
            var newInd = (Individual)(I_Prototype.Clone());

            // Set the fitness
            newInd.Fitness   = (Fitness)(F_Prototype.Clone());
            newInd.Evaluated = false; // for sanity's sake, though it's a useless line

            // Set the species to me
            newInd.Species = this;

            // load that sucker
            newInd.ReadIndividual(state, dataInput);

            // and we're ready!
            return(newInd);
        }
Exemplo n.º 4
0
/**
 * Reverse of the original map() function, takes a GPIndividual and returns
 * a corresponding GEIndividual; The GPIndividual may contain more than one trees,
 * and such cases are handled accordingly, see the 3rd bullet below --
 *
 * NOTE:
 * This reverse mapping is only valid for S-expression trees ;
 *
 * This procedure supports ERC for the current population (not for population
 * /subpopulation from other islands); However, that could be done by merging
 * all ERCBanks from all the sub-populations but that is not done yet ;
 *
 * Support for the ADF's are done as follows -- suppose in one GPIndividual,
 * there are N trees -- T1, T2, ,,, Tn and each of them follows n different
 * grammars G1, G2, ,,, Gn respectively; now if they are reverse-mapped to
 * int arrays, there will be n int arrays A1[], A2[], ,,, An[]; and suppose
 * the i-th tree Ti is reverse mapped to int array Ai[] and morevoer Ai[] is
 * the longest among all the arrays (Bj[]s); so Bi[] is sufficient to build
 * all ADF trees Tjs.
 */
        public GEIndividual ReverseMap(IEvolutionState state, GPIndividual ind, int threadnum)
        {
            // create a dummy individual
            GEIndividual newind = (GEIndividual)I_Prototype.Clone();

            // The longest int will be able to contain all ADF trees.
            int longestIntLength = -1;

            int[] longestInt = null;
            // Now go through all the ADF trees.
            for (int treeIndex = 0; treeIndex < ind.Trees.Length; treeIndex++)
            {
                // Flatten the Lisp tree
                ArrayList flatSexp = (ArrayList)FlattenSexp(state, threadnum,
                                                            ind.Trees[treeIndex]);
                // Now convert the flatten list into an array of ints
                // no. of trees == no. of grammars
                int[] genomeVals = ParseSexp(flatSexp, GrammarParser[treeIndex]);
                // store the longest int array
                if (genomeVals.Length >= longestIntLength)
                {
                    longestIntLength = genomeVals.Length;
                    longestInt       = new int[genomeVals.Length];
                    Array.Copy(genomeVals, 0, longestInt, 0, genomeVals.Length);
                }
                genomeVals = null;
            }
            // assign the longest int to the individual's genome
            newind.genome = longestInt;

            // update the GPIndividual's fitness information
            newind.Fitness   = ind.Fitness;
            newind.Evaluated = false;

            // Set the species to me ? not sure.
            newind.Species = this;

            // return it
            return(newind);
        }