示例#1
0
        /// <summary>
        /// Overridden to include the global best, neighborhood bests, personal bests, and previous Individuals in the stream.
        /// The neighborhood size, clamp range, and initial velocity scale are not included -- it's assumed you're using the
        /// same values for them on reading, or understand that the values are revised.
        /// </summary>
        public override void WriteSubpopulation(IEvolutionState state, BinaryWriter writer)
        {
            // global best
            if (GlobalBest == null)
            {
                writer.Write(false);
            }
            else
            {
                writer.Write(true);
                GlobalBest.WriteIndividual(state, writer);
            }

            // NeighborhoodBests
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (NeighborhoodBests[i] == null)
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    NeighborhoodBests[i].WriteIndividual(state, writer);
                }
            }

            // PersonalBests
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (PersonalBests[i] == null)
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    PersonalBests[i].WriteIndividual(state, writer);
                }
            }

            // previous Individuals
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (PreviousIndividuals[i] == null)
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    PreviousIndividuals[i].WriteIndividual(state, writer);
                }
            }

            base.WriteSubpopulation(state, writer);
        }
示例#2
0
        /// <summary>
        /// Overridden to include the global best, neighborhood bests, personal bests, and previous Individuals in the stream.
        /// The neighborhood size, clamp range, and initial velocity scale are not included -- it's assumed you're using the
        /// same values for them on reading, or understand that the values are revised.
        /// </summary>
        public override void PrintSubpopulation(IEvolutionState state, StreamWriter writer)
        {
            // global best
            writer.WriteLine(GLOBAL_BEST_PREAMBLE);
            if (GlobalBest == null)
            {
                writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false));
            }
            else
            {
                writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true));
                GlobalBest.PrintIndividual(state, writer);
            }

            // NeighborhoodBests
            writer.WriteLine(NEIGHBORHOOD_BEST_PREAMBLE);
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (NeighborhoodBests[i] == null)
                {
                    writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false));
                }
                else
                {
                    writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true));
                    NeighborhoodBests[i].PrintIndividual(state, writer);
                }
            }

            // PersonalBests
            writer.WriteLine(PERSONAL_BEST_PREAMBLE);
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (PersonalBests[i] == null)
                {
                    writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false));
                }
                else
                {
                    writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true));
                    PersonalBests[i].PrintIndividual(state, writer);
                }
            }

            // NeighborhoodBests
            writer.WriteLine(PREVIOUS_INDIVIDUAL_PREAMBLE);
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (PreviousIndividuals[i] == null)
                {
                    writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false));
                }
                else
                {
                    writer.WriteLine(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true));
                    PreviousIndividuals[i].PrintIndividual(state, writer);
                }
            }

            base.PrintSubpopulation(state, writer);
        }
示例#3
0
        /// <summary>
        /// Overridden to include the global best, neighborhood bests, personal bests, and previous Individuals in the stream.
        /// The neighborhood size, clamp range, and initial velocity scale are not included -- it's assumed you're using the
        /// same values for them on reading, or understand that the values are revised.
        /// </summary>
        public override void PrintSubpopulation(IEvolutionState state, int log)
        {
            // global best
            state.Output.PrintLn(GLOBAL_BEST_PREAMBLE, log);
            if (GlobalBest == null)
            {
                state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false), log);
            }
            else
            {
                state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true), log);
                GlobalBest.PrintIndividual(state, log);
            }

            // NeighborhoodBests
            state.Output.PrintLn(NEIGHBORHOOD_BEST_PREAMBLE, log);
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (NeighborhoodBests[i] == null)
                {
                    state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false), log);
                }
                else
                {
                    state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true), log);
                    NeighborhoodBests[i].PrintIndividual(state, log);
                }
            }

            // PersonalBests
            state.Output.PrintLn(PERSONAL_BEST_PREAMBLE, log);
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (PersonalBests[i] == null)
                {
                    state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false), log);
                }
                else
                {
                    state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true), log);
                    PersonalBests[i].PrintIndividual(state, log);
                }
            }

            // NeighborhoodBests
            state.Output.PrintLn(PREVIOUS_INDIVIDUAL_PREAMBLE, log);
            for (var i = 0; i < Individuals.Count; i++)
            {
                if (PreviousIndividuals[i] == null)
                {
                    state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(false), log);
                }
                else
                {
                    state.Output.PrintLn(INDIVIDUAL_EXISTS_PREAMBLE + Code.Encode(true), log);
                    PreviousIndividuals[i].PrintIndividual(state, log);
                }
            }

            base.PrintSubpopulation(state, log);
        }