Accord.Math.Optimization.QuadraticConstraint.QuadraticConstraint C# (CSharp) Method

QuadraticConstraint() public method

Constructs a new quadratic constraint in the form x'Ax + x'b.
public QuadraticConstraint ( IObjectiveFunction objective, double quadraticTerms, double linearTerms = null, ConstraintType shouldBe = ConstraintType.LesserThanOrEqualTo, double value, double withinTolerance = 0.0 ) : System
objective IObjectiveFunction The objective function to which this constraint refers.
quadraticTerms double The matrix of A quadratic terms.
linearTerms double The vector b of linear terms.
shouldBe ConstraintType How the left hand side of the constraint should be compared to /// the given .
value double The right hand side of the constraint equation.
withinTolerance double The tolerance for violations of the constraint. Equality /// constraints should set this to a small positive value. Default is 0.
return System
        public QuadraticConstraint(IObjectiveFunction objective,
            double[,] quadraticTerms, double[] linearTerms = null,
            ConstraintType shouldBe = ConstraintType.LesserThanOrEqualTo,
            double value = 0, double withinTolerance = 0.0)
        {
            int n = objective.NumberOfVariables;

            if (quadraticTerms == null)
                throw new ArgumentNullException("quadraticTerms");

            if (quadraticTerms.GetLength(0) != quadraticTerms.GetLength(1))
                throw new DimensionMismatchException("quadraticTerms", "Matrix must be square.");

            if (quadraticTerms.GetLength(0) != n)
                throw new DimensionMismatchException("quadraticTerms", 
                    "Matrix rows must match the number of variables in the objective function.");

            if (linearTerms != null)
            {
                if (linearTerms.Length != n)
                    throw new DimensionMismatchException("linearTerms",
                        "The length of the linear terms vector must match the "+
                        "number of variables in the objective function.");
            }
            else
            {
                linearTerms = new double[n];
            }

            this.QuadraticTerms = quadraticTerms;
            this.LinearTerms = linearTerms;

            Create(n, this.function, shouldBe, value, this.gradient, withinTolerance);
        }