Accord.Math.Optimization.NonlinearConstraint.Create C# (CSharp) Method

Create() protected method

Creates a nonlinear constraint.
protected Create ( int numberOfVariables, double>.Func function, ConstraintType shouldBe, double value, double[]>.Func gradient, double tolerance ) : void
numberOfVariables int
function double>.Func
shouldBe ConstraintType
value double
gradient double[]>.Func
tolerance double
return void
        protected void Create(int numberOfVariables,
            Func<double[], double> function, ConstraintType shouldBe, double value,
            Func<double[], double[]> gradient, double tolerance)
        {

            if (gradient != null)
            {
                double[] probe = new double[numberOfVariables];
                double[] g = gradient(probe);

                if (g.Length != numberOfVariables)
                    throw new DimensionMismatchException("gradient",
                    "The length of the gradient vector must match the number of variables in the objective function.");
            }

            this.NumberOfVariables = numberOfVariables;
            this.ShouldBe = shouldBe;
            this.Value = value;
            this.Tolerance = tolerance;

            this.Function = function;
            this.Gradient = gradient;
        }