QuadraticProgrammingProblem

class QuadraticProgrammingProblem(*args)

Quadratic optimization problem.

Warning

This class is experimental and likely to be modified in future releases. To use it, import the openturns.experimental submodule.

This defines a convex quadratic problem as:

\min_{\vect{x} \in B} f(\vect{x}) = \frac{1}{2} \vect{x}^T \mat{Q} \vect{x} + \vect{c}^T \vect{x} + d
\quad \text{subject to} \quad \vect{L} \leq \mat{A} \vect{x} \leq \vect{U}

where B = \{\vect{x} \in \Rset^n : \vect{\ell} \leq \vect{x} \leq \vect{u}\} is the box defined by the problem bounds, \mat{Q} is the symmetric positive semi-definite Hessian, \vect{c} is the linear cost vector and d is a constant term.

The rows of \mat{A} define the linear constraints: row i reads L_i \leq \vect{A}_i \vect{x} \leq U_i, where L_i and U_i are the lower and upper bounds of the constraint interval. A one-sided constraint is obtained with an infinite bound. An equality constraint is obtained with equal lower and upper bounds, L_i = U_i. The lower and upper bounds \vect{\ell} and \vect{u} of B are stored as an Interval; an empty interval means that the problem is unbounded.

The constant d does not change the optimal point; it is included so that getOptimalValue() returns the value of the original objective, for instance the residual sum of squares when the problem is built with FromLeastSquares().

Available constructors:

QuadraticProgrammingProblem(hessian, linearCost, bounds)

QuadraticProgrammingProblem(hessian, linearCost, bounds, constant)

QuadraticProgrammingProblem(hessian, linearCost, bounds, A, cb)

QuadraticProgrammingProblem(hessian, linearCost, bounds, A, cb, constant)

Parameters:
hessianSymmetricMatrix

The Hessian matrix \mat{Q}.

linearCostsequence of float

The linear cost vector \vect{c}.

boundsInterval

Bound constraints B = \{\vect{x} : \vect{\ell} \leq \vect{x} \leq \vect{u}\}. An empty interval means no bounds.

constantfloat, optional

The constant term d. Default is 0.

AMatrix

Linear constraint matrix \mat{A}.

cbInterval

Linear constraint bounds \vect{L}, \vect{U}.

Methods

FromLeastSquares(matrix, rhs, bounds)

Build a least-squares problem.

getBounds()

Accessor to bounds.

getClassName()

Accessor to the object's name.

getConstant()

Accessor to the constant term of the objective.

getDimension()

Accessor to input dimension.

getEqualityConstraint()

Accessor to the equality constraints.

getHessian()

Accessor to the Hessian matrix.

getInequalityConstraint()

Accessor to the inequality constraints.

getLevelFunction()

Accessor to level function.

getLevelValue()

Accessor to level value.

getLinearConstraintBounds()

Accessor to the linear constraint bounds.

getLinearConstraintCoefficients()

Accessor to the linear constraint coefficients.

getLinearCost()

Accessor to the linear cost.

getName()

Accessor to the object's name.

getObjective()

Accessor to objective function.

getResidualFunction()

Accessor to level function.

getVariablesType()

Accessor to the variables type.

hasBounds()

Test whether bounds had been specified.

hasEqualityConstraint()

Test whether equality constraints are defined.

hasInequalityConstraint()

Test whether inequality constraints are defined.

hasLevelFunction()

Test whether level function had been specified.

hasMultipleObjective()

Test whether objective function is a scalar or vector function.

hasName()

Test if the object is named.

hasResidualFunction()

Test whether a least-square problem is defined.

isContinuous()

Check if the problem is continuous.

isLinear()

Check if the problem is linear.

isMinimization([marginalIndex])

Test whether this is a minimization or maximization problem.

isQuadratic()

Check if the problem is quadratic.

setBounds(bounds)

Accessor to bounds.

setConstant(constant)

Accessor to the constant term of the objective.

setEqualityConstraint(equalityConstraint)

Set the equality constraint function.

setHessian(hessian)

Accessor to the Hessian matrix.

setInequalityConstraint(inequalityConstraint)

Set the inequality constraint function.

setLevelFunction(levelFunction)

Accessor to level function.

setLevelValue(levelValue)

Accessor to level value.

setLinearConstraint(constraintCoefficients, ...)

Accessor to the linear constraints.

setLinearCost(linearCost)

Accessor to the linear cost.

setMinimization(minimization[, marginalIndex])

Tell whether this is a minimization or maximization problem.

setName(name)

Accessor to the object's name.

setObjective(objective)

Accessor to objective function.

setResidualFunction(residualFunction)

Accessor to level function.

setVariablesType(variableType)

Accessor to the variables type.

Examples

Define and solve a bounded quadratic problem:

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> Q = ot.SymmetricMatrix([[2.0, 0.0], [0.0, 2.0]])
>>> c = [-2.0, -4.0]
>>> bounds = ot.Interval([0.0, 0.0], [0.5, 10.0])
>>> problem = otexp.QuadraticProgrammingProblem(Q, c, bounds)
>>> algo = otexp.HiGHS(problem)
>>> algo.run()
>>> result = algo.getResult()
>>> x_star = result.getOptimalPoint()

Build the equivalent least-squares problem \min_{\vect{x} \in B} \|\mat{A} \vect{x} - \vect{b}\|^2:

>>> A = ot.Matrix([[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]])
>>> b = [1.0, 2.0, 3.0]
>>> problem = otexp.QuadraticProgrammingProblem.FromLeastSquares(A, b, bounds)
>>> problem.getConstant()
14.0
__init__(*args)
static FromLeastSquares(matrix, rhs, bounds)

Build a least-squares problem.

This builds the quadratic problem:

\min_{\vect{x} \in B} \norm{\mat{A} \vect{x} - \vect{b}}^2

which is equivalent to:

\min_{\vect{x} \in B} \frac{1}{2} \vect{x}^T \mat{Q} \vect{x} + \vect{c}^T \vect{x} + \norm{\vect{b}}^2

with \mat{Q} = 2 \mat{A}^T \mat{A} and \vect{c} = -2 \mat{A}^T \vect{b}.

Parameters:
AMatrix

The design matrix.

bsequence of float

The right hand side.

boundsInterval

Bound constraints B. An empty interval means no bounds.

Returns:
problemQuadraticProgrammingProblem

The equivalent quadratic problem.

getBounds()

Accessor to bounds.

Returns:
boundsInterval

Problem bounds.

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

The object class name (object.__class__.__name__).

getConstant()

Accessor to the constant term of the objective.

Returns:
constantfloat

Constant term.

getDimension()

Accessor to input dimension.

Returns:
dimensionint

Input dimension of objective function.

getEqualityConstraint()

Accessor to the equality constraints.

The equality constraints are derived from the linear constraints: a row whose lower and upper bounds are equal, L_i = U_i, defines the equality constraint \vect{A}_i \vect{x} = L_i.

Returns:
equalityFunction

Linear function \vect{x} \mapsto \mat{A}_{eq} \vect{x} - \vect{L}_{eq} built from the equality rows. Its input dimension is the problem dimension and its output dimension is the number of equality rows. When there is no equality row, the returned linear function has zero output dimension.

getHessian()

Accessor to the Hessian matrix.

Returns:
hessianSymmetricMatrix

The symmetric positive semi-definite Hessian matrix.

getInequalityConstraint()

Accessor to the inequality constraints.

The inequality constraints are derived from the linear constraints: each finite bound of a row that is not an equality constraint gives one component, with the convention h(\vect{x}) \geq 0. The row L_i \leq \vect{A}_i \vect{x} \leq U_i gives the components \vect{A}_i \vect{x} - L_i and U_i - \vect{A}_i \vect{x}.

Returns:
inequalityFunction

Linear function \vect{x} \mapsto \mat{A}_{ineq} \vect{x} - \vect{L}_{ineq} built from the inequality rows. Its input dimension is the problem dimension and its output dimension is the number of finite bounds of the rows that are not equality constraints. When there is no such row, the returned linear function has zero output dimension.

getLevelFunction()

Accessor to level function.

Returns:
levelFunction

Level function.

getLevelValue()

Accessor to level value.

Returns:
valuefloat

Level value.

getLinearConstraintBounds()

Accessor to the linear constraint bounds.

Returns:
cbInterval

Linear inequality constraint bounds.

getLinearConstraintCoefficients()

Accessor to the linear constraint coefficients.

Returns:
AMatrix

Linear inequality constraint matrix.

getLinearCost()

Accessor to the linear cost.

Returns:
linearCostPoint

Linear cost vector.

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

getObjective()

Accessor to objective function.

Returns:
objectiveFunction

Objective function.

getResidualFunction()

Accessor to level function.

Returns:
levelFunction

Level function.

getVariablesType()

Accessor to the variables type.

Returns:
variablesTypeIndices

Types of the variables.

Notes

Possible values for each variable are ot.OptimizationProblemImplementation.CONTINUOUS, ot.OptimizationProblemImplementation.INTEGER and ot.OptimizationProblemImplementation.`BINARY`.

hasBounds()

Test whether bounds had been specified.

Returns:
valuebool

True if bounds had been set for this problem, False otherwise.

hasEqualityConstraint()

Test whether equality constraints are defined.

Returns:
hasEqualityConstraintbool

True if at least one row of the linear constraints has equal lower and upper bounds.

hasInequalityConstraint()

Test whether inequality constraints are defined.

Returns:
hasInequalityConstraintbool

True if at least one row of the linear constraints has a finite bound and is not an equality constraint.

hasLevelFunction()

Test whether level function had been specified.

Returns:
valuebool

True if level function had been set for this problem, False otherwise.

hasMultipleObjective()

Test whether objective function is a scalar or vector function.

Returns:
valuebool

False if objective function is scalar, True otherwise.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

hasResidualFunction()

Test whether a least-square problem is defined.

Returns:
valuebool

True if this is a least-squares problem, False otherwise.

isContinuous()

Check if the problem is continuous.

Returns:
isContinuousbool

Returns True if all variables are continuous.

isLinear()

Check if the problem is linear.

Returns:
isLinearbool

Returns True if the problem is of linear type.

isMinimization(marginalIndex=0)

Test whether this is a minimization or maximization problem.

Parameters:
marginal_indexint, default=0

Index of the output marginal (for multi-objective only)

Returns:
valuebool

True if this is a minimization problem (default), False otherwise.

isQuadratic()

Check if the problem is quadratic.

Returns:
isQuadraticbool

Returns True if the problem is of quadratic type.

setBounds(bounds)

Accessor to bounds.

Parameters:
boundsInterval

Problem bounds.

setConstant(constant)

Accessor to the constant term of the objective.

Parameters:
constantfloat

Constant term.

setEqualityConstraint(equalityConstraint)

Set the equality constraint function.

The function must be linear: either a LinearFunction, or a Function whose isLinear() method returns True. It is converted to the linear constraints \mat{A} \vect{x} = \vect{L}, where \mat{A} is the transpose of its gradient at the origin and \vect{L} = -h(\vect{0}) for a function h such that h(\vect{x}) = \vect{0} is the expected equality constraint. Existing inequality constraints are preserved.

Parameters:
equalityConstraintFunction

Linear equality constraint h(\vect{x}) = \vect{0}. An empty function clears the equality constraints.

setHessian(hessian)

Accessor to the Hessian matrix.

Parameters:
hessianSymmetricMatrix

The symmetric positive semi-definite Hessian matrix.

setInequalityConstraint(inequalityConstraint)

Set the inequality constraint function.

The function must be linear: either a LinearFunction, or a Function whose isLinear() method returns True. It is converted to the linear constraints \mat{A} \vect{x} \geq \vect{L}, where \mat{A} is the transpose of its gradient at the origin and \vect{L} = -g(\vect{0}) for a function g such that g(\vect{x}) \geq 0 is the expected inequality constraint. Existing equality constraints are preserved.

Parameters:
inequalityConstraintFunction

Linear inequality constraint g(\vect{x}) \geq 0. An empty function clears the inequality constraints.

setLevelFunction(levelFunction)

Accessor to level function.

Parameters:
levelFunctionFunction

Level function.

setLevelValue(levelValue)

Accessor to level value.

Parameters:
levelValuefloat

Level value.

setLinearConstraint(constraintCoefficients, constraintBounds)

Accessor to the linear constraints.

Each row i of the constraint matrix defines L_i \leq \vect{A}_i \vect{x} \leq U_i, where L_i and U_i are the bounds of the constraint interval. Use an infinite bound for a one-sided constraint and equal lower and upper bounds for an equality constraint.

Parameters:
AMatrix

Linear constraint matrix.

cbInterval

Linear constraint bounds.

setLinearCost(linearCost)

Accessor to the linear cost.

Parameters:
linearCostsequence of float

Linear cost vector.

setMinimization(minimization, marginalIndex=0)

Tell whether this is a minimization or maximization problem.

Parameters:
minimizationbool

True if this is a minimization problem, False otherwise.

marginal_indexint, default=0

Index of the output marginal (for multi-objective only)

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

setObjective(objective)

Accessor to objective function.

Parameters:
objectiveFunctionFunction

Objective function.

Notes

Constraints and bounds are cleared if the objective has a different input dimension in order to keep the problem valid at all time.

setResidualFunction(residualFunction)

Accessor to level function.

Parameters:
levelFunctionFunction

Level function.

setVariablesType(variableType)

Accessor to the variables type.

Parameters:
variablesTypeIndices

Types of the variables.

Notes

Possible values for each variable are ot.OptimizationProblemImplementation.CONTINUOUS, ot.OptimizationProblemImplementation.INTEGER and ot.OptimizationProblemImplementation.BINARY.

Examples using the class

Optimization using HiGHS solvers

Optimization using HiGHS solvers