Пример #1
0
        /// <summary>
        /// Returns the Manhattan difference between two Fitnesses in Objective space.
        /// </summary>
        public double ManhattanObjectiveDistance(MultiObjectiveFitness other)
        {
            double s = 0;

            for (var i = 0; i < Objectives.Length; i++)
            {
                s += Math.Abs(Objectives[i] - other.Objectives[i]);
            }
            return(s);
        }
Пример #2
0
        /// <summary>
        /// Returns the sum of the squared difference between two Fitnesses in Objective space.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public double SumSquaredObjectiveDistance(MultiObjectiveFitness other)
        {
            double s = 0;

            for (var i = 0; i < Objectives.Length; i++)
            {
                double a = Objectives[i] - other.Objectives[i];
                s += a * a;
            }
            return(s);
        }
Пример #3
0
        /// <summary>
        /// Logs the best individual of the run.
        /// </summary>
        public override void FinalStatistics(IEvolutionState state, int result)
        {
            BypassFinalStatistics(state, result);  // just call base.base.finalStatistics(...)

            if (DoFinal)
            {
                state.Output.PrintLn("\n\n\n PARETO FRONTS", StatisticsLog);
            }
            for (var s = 0; s < state.Population.Subpops.Count; s++)
            {
                if (DoFinal)
                {
                    state.Output.PrintLn("\n\nPareto Front of Subpopulation " + s, StatisticsLog);
                }

                // build front
                var front = MultiObjectiveFitness.PartitionIntoParetoFront(state.Population.Subpops[s].Individuals, null, null);

                // sort by objective[0]
                var sortedFront = front.ToArray();
                QuickSort.QSort(sortedFront, new MultiObjectiveFitnessComparator());


                // print out front to statistics log
                if (DoFinal)
                {
                    foreach (var ind in sortedFront)
                    {
                        ind.PrintIndividualForHumans(state, StatisticsLog);
                    }
                }

                // write short version of front out to disk
                if (FrontLog >= 0)
                {
                    if (state.Population.Subpops.Count > 1)
                    {
                        state.Output.PrintLn("Subpopulation " + s, FrontLog);
                    }
                    foreach (var ind in sortedFront)
                    {
                        var mof        = (MultiObjectiveFitness)ind.Fitness;
                        var objectives = mof.GetObjectives();

                        var line = objectives.Aggregate("", (current, t1) => current + (t1 + " "));
                        state.Output.PrintLn(line, FrontLog);
                    }
                }
            }
        }
Пример #4
0
        public void SetToMeanOf(IEvolutionState state, Fitness[] fitnesses)
        {
            // basically we compute the centroid of the fitnesses
            double sum = 0.0;

            for (int i = 0; i < Objectives.Length; i++)
            {
                for (int k = 0; k < fitnesses.Length; k++)
                {
                    MultiObjectiveFitness f = (MultiObjectiveFitness)fitnesses[k];
                    sum += f.Objectives[i];
                }
                Objectives[i] = (double)(sum / fitnesses.Length);
            }
        }
Пример #5
0
        /// <summary>
        /// Returns true if I'm better than _fitness. The rule I'm using is this: if
        /// I am better in one or more criteria, and we are equal in the others, then
        /// betterThan is true, else it is false.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool ParetoDominates(MultiObjectiveFitness other)
        {
            var abeatsb = false;

            if (Objectives.Length != other.Objectives.Length)
            {
                throw new ApplicationException(
                          "Attempt made to compare two multiobjective fitnesses; but they have different numbers of objectives.");
            }

            for (int x = 0; x < Objectives.Length; x++)
            {
                if (Maximize[x] != other.Maximize[x])  // uh oh
                {
                    throw new InvalidOperationException(
                              "Attempt made to compare two multiobjective fitnesses; but for objective #" + x +
                              ", one expects higher values to be better and the other expectes lower values to be better.");
                }

                if (Maximize[x])
                {
                    if (Objectives[x] > other.Objectives[x])
                    {
                        abeatsb = true;
                    }
                    else if (Objectives[x] < other.Objectives[x])
                    {
                        return(false);
                    }
                }
                else
                {
                    if (Objectives[x] < other.Objectives[x])
                    {
                        abeatsb = true;
                    }
                    else if (Objectives[x] > other.Objectives[x])
                    {
                        return(false);
                    }
                }
            }
            return(abeatsb);
        }