Пример #1
0
        /// <summary>
        ///   Maximizes the given function.
        /// </summary>
        ///
        /// <param name="function">The function to be maximized.</param>
        ///
        /// <returns>The maximum value found at the <see cref="Solution"/>.</returns>
        ///
        public double Maximize(NonlinearObjectiveFunction function)
        {
            if (function.NumberOfVariables != numberOfVariables)
            {
                throw new ArgumentOutOfRangeException("function",
                                                      "Incorrect number of variables in the objective function. " +
                                                      "The number of variables must match the number of variables set in the solver.");
            }

            this.Function = x => - function.Function(x);
            this.Gradient = x => function.Gradient(x).Multiply(-1);

            minimize();

            return(-Function(Solution));
        }
        /// <summary>
        ///   Maximizes the given function. 
        /// </summary>
        /// 
        /// <param name="function">The function to be maximized.</param>
        /// 
        /// <returns>The maximum value found at the <see cref="Solution"/>.</returns>
        /// 
        public double Maximize(NonlinearObjectiveFunction function)
        {
            if (function.NumberOfVariables != numberOfVariables)
                throw new ArgumentOutOfRangeException("function",
                    "Incorrect number of variables in the objective function. " +
                    "The number of variables must match the number of variables set in the solver.");

            this.Function = x => -function.Function(x);
            this.Gradient = x => function.Gradient(x).Multiply(-1);

            minimize();

            return -Function(Solution);
        }