public void Problem_NegativeParams_ArgumentNullExceptionThrown(IList <Dimension> dimensions, IDictionary <Dimension, Range> initialRanges, Func <IDictionary <Dimension, double>, double> targetFunction, ProblemTarget target, string expectedParamName) { ArgumentNullException actualException = Assert.Throws <ArgumentNullException>(() => new TestProblem(dimensions, initialRanges, targetFunction, target)); Assert.NotNull(actualException); Assert.Equal(expectedParamName, actualException.ParamName); }
/// <summary> /// Initializes a new instance of <see cref="Problem"/> type. /// </summary> /// <param name="dimensions">The dimensions of the problem.</param> /// <param name="initialRanges">The initial ranges of the problem dimensions.</param> /// <param name="targetFunction">The quality function that needs to be optimized.</param> /// <param name="target">Target of the problem.</param> /// <exception cref="ArgumentNullException">if <paramref name="dimensions"/> or /// <paramref name="initialRanges"/> or <paramref name="targetFunction"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException">if <paramref name="dimensions"/>.Count is zero or /// <paramref name="dimensions"/>.Count differs from <paramref name="initialRanges"/>.Count /// or <paramref name="dimensions"/> does not contain same keys as <paramref name="initialRanges"/>. /// </exception> public Problem(IList <Dimension> dimensions, IDictionary <Dimension, Range> initialRanges, Func <IDictionary <Dimension, double>, double> targetFunction, ProblemTarget target) { if (dimensions == null) { throw new ArgumentNullException(nameof(dimensions)); } if (dimensions.Count == 0) { throw new ArgumentException(string.Empty, nameof(dimensions)); } if (initialRanges == null) { throw new ArgumentNullException(nameof(initialRanges)); } if (initialRanges.Count != dimensions.Count) { throw new ArgumentException(string.Empty, nameof(initialRanges)); } foreach (Dimension dimension in dimensions) { if (!initialRanges.ContainsKey(dimension)) { throw new ArgumentException(string.Empty, nameof(initialRanges)); } } if (targetFunction == null) { throw new ArgumentNullException(nameof(targetFunction)); } this.Dimensions = dimensions; this.InitialRanges = initialRanges; this.targetFunction = targetFunction; this.Target = target; }
public static TestProblem getTestProblem() { IList <Dimension> dimensions = new List <Dimension>(); IDictionary <Dimension, Range> initialRanges = new Dictionary <Dimension, Range>(); Func <IDictionary <Dimension, double>, double> targetFunction = new Func <IDictionary <Dimension, double>, double>( (c) => { return(29); } ); ProblemTarget target = ProblemTarget.Minimum; Range range = new Range(0, 1); dimensions.Add(new Dimension(range)); initialRanges.Add(new KeyValuePair <Dimension, Range>(dimensions[0], range)); TestProblem testProblem = new TestProblem(dimensions, initialRanges, targetFunction, target); return(testProblem); }
/// <summary> /// Initializes a new instance of the <see cref="Rastrigrin"/> 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="target">Problem target.</param> private Rastrigrin(IList <Dimension> dimensions, IDictionary <Dimension, Range> initialDimensionRanges, Func <IDictionary <Dimension, double>, double> targetFunction, Solution knownSolution, ProblemTarget target) : base(dimensions, initialDimensionRanges, targetFunction, knownSolution, target) { }
public TestProblem(IList <Dimension> dimensions, IDictionary <Dimension, Range> initialRanges, Func <IDictionary <Dimension, double>, double> targetFunction, ProblemTarget target) : base(dimensions, initialRanges, targetFunction, target) { }
/// <summary> /// Initializes a new instance of <see cref="ExtremumFireworkSelector"/> class. /// </summary> /// <param name="problemTarget">Target of the problem under investigation.</param> public ExtremumFireworkSelector(ProblemTarget problemTarget) { this.problemTarget = problemTarget; }
/// <summary> /// Initializes a new instance of the <see cref="BenchmarkProblem"/> class. /// Initial ranges of the problem dimensions match those from <paramref name="dimensions"/>. /// </summary> /// <param name="dimensions">The dimensions of the problem.</param> /// <param name="targetFunction">The quality function that needs to be optimized.</param> /// <param name="knownSolution">The known solution.</param> /// <param name="target">Target of the problem.</param> public BenchmarkProblem(IList <Dimension> dimensions, Func <IDictionary <Dimension, double>, double> targetFunction, Solution knownSolution, ProblemTarget target) : this(dimensions, null, targetFunction, knownSolution, target) { }
/// <summary> /// Initializes a new instance of the <see cref="BenchmarkProblem"/> class. /// </summary> /// <param name="dimensions">The dimensions of the problem.</param> /// <param name="initialDimensionRanges">The initial ranges of the problem dimensions.</param> /// <param name="targetFunction">The quality function that needs to be optimized.</param> /// <param name="knownSolution">The known solution.</param> /// <param name="target">Target of the problem.</param> /// <exception cref="System.ArgumentNullException"> if <paramref name="knownSolution"/> /// is <c>null</c>.</exception> /// <exception cref="System.ArgumentException"> if <paramref name="knownSolution"/> /// has neither coordinates nor quality.</exception> public BenchmarkProblem(IList <Dimension> dimensions, IDictionary <Dimension, Range> initialDimensionRanges, Func <IDictionary <Dimension, double>, double> targetFunction, Solution knownSolution, ProblemTarget target) : base(dimensions, initialDimensionRanges, targetFunction, target) { if (knownSolution == null) { throw new ArgumentNullException(nameof(knownSolution)); } if (knownSolution.Coordinates == null && double.IsNaN(knownSolution.Quality)) { // We have neither coordinates of a known solution nor its quality. // Therefore, such known solution is useless. throw new ArgumentException(string.Empty, nameof(knownSolution)); } this.KnownSolution = knownSolution; }
/// <summary> /// Initializes a new instance of <see cref="Problem"/> type with default initial ranges. /// </summary> /// <param name="dimensions">The dimensions of the problem.</param> /// <param name="targetFunction">The quality function that needs to be optimized.</param> /// <param name="target">Target of the problem.</param> /// <exception cref="ArgumentNullException">if <paramref name="dimensions"/> or /// <paramref name="targetFunction"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">if <paramref name="dimensions"/>.Count is zero. /// </exception> public Problem(IList <Dimension> dimensions, Func <IDictionary <Dimension, double>, double> targetFunction, ProblemTarget target) : this(dimensions, Problem.CreateDefaultInitialRanges(dimensions), targetFunction, target) { }