<commit_before>﻿using System;
using System.Collections.Generic;
using FireworksNet.Model;

namespace FireworksNet.Problems.Benchmark
{
    /// <summary>
    /// Represents Griewank test function, as used in 2010 paper.
    /// </summary>
    /// <remarks>http://mathworld.wolfram.com/GriewankFunction.html</remarks>
    public sealed class Griewank2010 : BenchmarkProblem
    {
        private const int dimensionality = 30;
        private const double minDimensionValue = -100.0;
        private const double maxDimensionValue = 100.0;
        private const double minInitialDimensionValue = 30.0;
        private const double maxInitialDimensionValue = 50.0;
        private const double knownBestQuality = 0.0;
        private const ProblemTarget problemTarget = ProblemTarget.Minimum;

        /// <summary>
        /// Initializes a new instance of the <see cref="Griewank2010"/> class.
        /// </summary>
        /// <param name="dimensions">Dimensions of the problem.</param>
        /// <param name="initialDimensionRanges">Initial dimension ranges, to be used to 
        /// create initial fireworks.</param>
        /// <param name="targetFunction">Quality function.</param>
        /// <param name="knownSolution">Known solution.</param>
        /// <param name="stopCondition">Algorithm stop condition.</param>
        /// <param name="target">Problem target.</param>
        private Griewank2010(IList<Dimension> dimensions, IDictionary<Dimension, Range> initialDimensionRanges, Func<IDictionary<Dimension, double>, double> targetFunction, Solution knownSolution, ProblemTarget target)
            : base(dimensions, initialDimensionRanges, targetFunction, knownSolution, target)
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="Griewank2010"/> class.
        /// </summary>
        /// <returns><see cref="Griewank2010"/> instance that represents
        /// Griewank test function, as used in 2010 paper.</returns>
        public static Griewank2010 Create()
        {
            Dimension[] dimensions = new Dimension[Griewank2010.dimensionality];
            IDictionary<Dimension, Range> initialDimensionRanges = new Dictionary<Dimension, Range>(Griewank2010.dimensionality);
            IDictionary<Dimension, double> knownBestCoordinates = new Dictionary<Dimension, double>(Griewank2010.dimensionality);
            for (int i = 0; i < Griewank2010.dimensionality; i++)
            {
                dimensions[i] = new Dimension(new Range(Griewank2010.minDimensionValue, Griewank2010.maxDimensionValue));
                initialDimensionRanges.Add(dimensions[i], new Range(Griewank2010.minInitialDimensionValue, Griewank2010.maxInitialDimensionValue));
                knownBestCoordinates.Add(dimensions[i], 0.0);
            }

            Func<IDictionary<Dimension, double>, double> func = new Func<IDictionary<Dimension, double>, double>(
                (c) =>
                {
                    double sum = 0.0;
                    double product = 1.0;
                    for (int i = 1; i <= Griewank2010.dimensionality; i++)
                    {
                        double value = c[dimensions[i]];
                        sum += Math.Pow(value, 2.0);
                        product *= Math.Cos(value) / Math.Sqrt(i);
                    }

                    return 1.0 + sum / 4000.0 - product;
                }
            );

            return new Griewank2010(dimensions, initialDimensionRanges, func, new Solution(knownBestCoordinates, Griewank2010.knownBestQuality), Griewank2010.problemTarget);
        }
    }
}<commit_msg>Correctly corrected an error in Griewank :)<commit_after>﻿using System;
using System.Collections.Generic;
using FireworksNet.Model;

namespace FireworksNet.Problems.Benchmark
{
    /// <summary>
    /// Represents Griewank test function, as used in 2010 paper.
    /// </summary>
    /// <remarks>http://mathworld.wolfram.com/GriewankFunction.html</remarks>
    public sealed class Griewank2010 : BenchmarkProblem
    {
        private const int dimensionality = 30;
        private const double minDimensionValue = -100.0;
        private const double maxDimensionValue = 100.0;
        private const double minInitialDimensionValue = 30.0;
        private const double maxInitialDimensionValue = 50.0;
        private const double knownBestQuality = 0.0;
        private const ProblemTarget problemTarget = ProblemTarget.Minimum;

        /// <summary>
        /// Initializes a new instance of the <see cref="Griewank2010"/> class.
        /// </summary>
        /// <param name="dimensions">Dimensions of the problem.</param>
        /// <param name="initialDimensionRanges">Initial dimension ranges, to be used to 
        /// create initial fireworks.</param>
        /// <param name="targetFunction">Quality function.</param>
        /// <param name="knownSolution">Known solution.</param>
        /// <param name="stopCondition">Algorithm stop condition.</param>
        /// <param name="target">Problem target.</param>
        private Griewank2010(IList<Dimension> dimensions, IDictionary<Dimension, Range> initialDimensionRanges, Func<IDictionary<Dimension, double>, double> targetFunction, Solution knownSolution, ProblemTarget target)
            : base(dimensions, initialDimensionRanges, targetFunction, knownSolution, target)
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="Griewank2010"/> class.
        /// </summary>
        /// <returns><see cref="Griewank2010"/> instance that represents
        /// Griewank test function, as used in 2010 paper.</returns>
        public static Griewank2010 Create()
        {
            Dimension[] dimensions = new Dimension[Griewank2010.dimensionality];
            IDictionary<Dimension, Range> initialDimensionRanges = new Dictionary<Dimension, Range>(Griewank2010.dimensionality);
            IDictionary<Dimension, double> knownBestCoordinates = new Dictionary<Dimension, double>(Griewank2010.dimensionality);
            for (int i = 0; i < Griewank2010.dimensionality; i++)
            {
                dimensions[i] = new Dimension(new Range(Griewank2010.minDimensionValue, Griewank2010.maxDimensionValue));
                initialDimensionRanges.Add(dimensions[i], new Range(Griewank2010.minInitialDimensionValue, Griewank2010.maxInitialDimensionValue));
                knownBestCoordinates.Add(dimensions[i], 0.0);
            }

            Func<IDictionary<Dimension, double>, double> func = new Func<IDictionary<Dimension, double>, double>(
                (c) =>
                {
                    double sum = 0.0;
                    double product = 1.0;
                    for (int i = 0; i < Griewank2010.dimensionality; i++)
                    {
                        double value = c[dimensions[i]];
                        sum += Math.Pow(value, 2.0);
                        product *= Math.Cos(value) / Math.Sqrt(i + 1);
                    }

                    return 1.0 + sum / 4000.0 - product;
                }
            );

            return new Griewank2010(dimensions, initialDimensionRanges, func, new Solution(knownBestCoordinates, Griewank2010.knownBestQuality), Griewank2010.problemTarget);
        }
    }
}
{'fraction_non_alphanumeric': 0.10692254969156957, 'fraction_numerical': 0.031665524331734064, 'mean_word_length': 2.3730929264909846, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1080820', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1866, 'n_words': 457}