Exemplo n.º 1
0
 /// <inheritdoc />
 /// <summary>
 /// This is a memberwise clone implementation.
 /// </summary>
 public virtual object Clone()
 {
     try
     {
         var myobj = (Individual)MemberwiseClone();
         if (myobj.Fitness != null)
         {
             myobj.Fitness = (IFitness)Fitness.Clone();
         }
         return(myobj);
     }
     catch (Exception ex)
     {
         throw new ApplicationException("Clone not supported", ex);
     } // never happens
 }
Exemplo n.º 2
0
        /// <summary>
        /// The default version of Setup(...) loads requested pipelines and calls Setup(...) on them and normalizes their probabilities.
        /// If your individual prototype might need to know special things about the species (like parameters stored in it),
        /// then when you override this Setup method, you'll need to set those parameters BEFORE you call super.Setup(...),
        /// because the Setup(...) code in Species sets up the prototype.
        /// </summary>
        /// <seealso cref="IPrototype.Setup(IEvolutionState, IParameter)" />
        public virtual void Setup(IEvolutionState state, IParameter paramBase)
        {
            var def = DefaultBase;

            // load the breeding pipeline
            Pipe_Prototype = (BreedingSource)state.Parameters.GetInstanceForParameter(paramBase.Push(P_PIPE), def.Push(P_PIPE), typeof(BreedingSource));
            Pipe_Prototype.Setup(state, paramBase.Push(P_PIPE));

            // I promised over in BreedingSource.java that this method would get called.
            state.Output.ExitIfErrors();

            // load our individual prototype
            I_Prototype = (Individual)(state.Parameters.GetInstanceForParameter(paramBase.Push(P_INDIVIDUAL), def.Push(P_INDIVIDUAL), typeof(Individual)));
            // set the species to me before setting up the individual, so they know who I am
            I_Prototype.Species = this;
            I_Prototype.Setup(state, paramBase.Push(P_INDIVIDUAL));

            // load our fitness
            F_Prototype = (Fitness)state.Parameters.GetInstanceForParameter(paramBase.Push(P_FITNESS), def.Push(P_FITNESS), typeof(Fitness));
            F_Prototype.Setup(state, paramBase.Push(P_FITNESS));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Reads the binary form of an individual from a BinaryReader, erasing the previous
 /// information stored in this Individual.  This is not for serialization:
 /// the object should only read in the data written out via PrintIndividual(state,writer).
 /// If you are trying to <i>create</i> an Individual
 /// from information read in from a stream or BinaryReader,
 /// see the various NewIndividual() methods in Species. The default form of this method
 /// simply reads in evaluation information, then fitness information, and then
 /// calls ReadGenotype() (which you will need to override -- its default form simply throws an error).
 /// The Species is not changed or attached, so you may need to do that elsewhere.  Feel free to override
 /// this method to produce more sophisticated behavior, though it is rare to need to -- instead you could
 /// just override ReadGenotype().
 /// </summary>
 public virtual void ReadIndividual(IEvolutionState state, BinaryReader reader)
 {
     Evaluated = reader.ReadBoolean();
     Fitness.ReadFitness(state, reader);
     ReadGenotype(state, reader);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Writes the binary form of an individual out to a BinaryWriter.  This is not for serialization:
 /// the object should only write out the data relevant to the object sufficient to rebuild it from a BinaryReader.
 /// The Species will be reattached later, and you should not write it.   The default version of this
 /// method writes the evaluated and fitness information, then calls WriteGenotype() to write the genotype
 /// information.  Feel free to override this method to produce more sophisticated behavior,
 /// though it is rare to need to -- instead you could just override WriteGenotype().
 /// </summary>
 public virtual void WriteIndividual(IEvolutionState state, BinaryWriter writer)
 {
     writer.Write(Evaluated);
     Fitness.WriteFitness(state, writer);
     WriteGenotype(state, writer);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Should print the individual in a way that can be read by computer,
 /// including its fitness.  You can get fitness to print itself at the
 /// appropriate time by calling fitness.PrintFitness(state,log,writer);
 /// Usually you should try to use PrintIndividual(state,log)
 /// instead -- use this method only if you can't print through the
 /// Output facility for some reason.
 /// <p/>The default form of this method simply prints out whether or not the
 /// individual has been evaluated, its fitness, and then calls Individual.GenotypeToString().
 /// Feel free to override this to produce more sophisticated behavior,
 /// though it is rare to need to -- instead you could just override GenotypeToString().
 /// </summary>
 public virtual void PrintIndividual(IEvolutionState state, StreamWriter writer)
 {
     writer.WriteLine(EVALUATED_PREAMBLE + Code.Encode(Evaluated));
     Fitness.PrintFitness(state, writer);
     writer.WriteLine(GenotypeToString());
 }
Exemplo n.º 6
0
 /// <summary>
 /// Should print the individual in a way that can be read by computer.
 /// </summary>
 public virtual void PrintIndividual(IEvolutionState state, int log)
 {
     state.Output.PrintLn(EVALUATED_PREAMBLE + Code.Encode(Evaluated), log);
     Fitness.PrintFitness(state, log);
     state.Output.PrintLn(GenotypeToString(), log);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Returns -1 if I am BETTER in some way than the other Individual, 1 if the other Individual is BETTER than me,
        /// and 0 if we are equivalent.  The default implementation assumes BETTER means FITTER, by simply calling
        /// CompareTo on the fitnesses themselves
        /// </summary>
        public int CompareTo(object o)
        {
            var other = (Individual)o;

            return(Fitness.CompareTo(other.Fitness));
        }