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.experimentalsubmodule.This defines a convex quadratic problem as:
where
is the box defined by the problem bounds,
is the symmetric positive semi-definite Hessian,
is the linear cost vector and
is a constant term.
The rows of
define the linear constraints: row
reads
, where
and
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,
. The lower and upper bounds
and
of
are stored as an
Interval; an empty interval means that the problem is unbounded.The constant
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 withFromLeastSquares().- 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:
- hessian
SymmetricMatrix The Hessian matrix
.
- linearCostsequence of float
The linear cost vector
.
- bounds
Interval Bound constraints
. An empty interval means no bounds.
- constantfloat, optional
The constant term
. Default is 0.
- A
Matrix Linear constraint matrix
.
- cb
Interval Linear constraint bounds
.
- hessian
Methods
FromLeastSquares(matrix, rhs, bounds)Build a least-squares problem.
Accessor to bounds.
Accessor to the object's name.
Accessor to the constant term of the objective.
Accessor to input dimension.
Accessor to the equality constraints.
Accessor to the Hessian matrix.
Accessor to the inequality constraints.
Accessor to level function.
Accessor to level value.
Accessor to the linear constraint bounds.
Accessor to the linear constraint coefficients.
Accessor to the linear cost.
getName()Accessor to the object's name.
Accessor to objective function.
Accessor to level function.
Accessor to the variables type.
Test whether bounds had been specified.
Test whether equality constraints are defined.
Test whether inequality constraints are defined.
Test whether level function had been specified.
Test whether objective function is a scalar or vector function.
hasName()Test if the object is named.
Test whether a least-square problem is defined.
Check if the problem is continuous.
isLinear()Check if the problem is linear.
isMinimization([marginalIndex])Test whether this is a minimization or maximization problem.
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
:
>>> 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:
which is equivalent to:
with
and
.
- Parameters:
- Returns:
- problem
QuadraticProgrammingProblem The equivalent quadratic problem.
- problem
- 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,
, defines the equality constraint
.
- Returns:
- equality
Function Linear function
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.
- equality
- getHessian()¶
Accessor to the Hessian matrix.
- Returns:
- hessian
SymmetricMatrix The symmetric positive semi-definite Hessian matrix.
- hessian
- 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
. The row
gives the components
and
.
- Returns:
- inequality
Function Linear function
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.
- inequality
- getLevelValue()¶
Accessor to level value.
- Returns:
- valuefloat
Level value.
- getLinearConstraintBounds()¶
Accessor to the linear constraint bounds.
- Returns:
- cb
Interval Linear inequality constraint bounds.
- cb
- getLinearConstraintCoefficients()¶
Accessor to the linear constraint coefficients.
- Returns:
- A
Matrix Linear inequality constraint matrix.
- A
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getVariablesType()¶
Accessor to the variables type.
- Returns:
- variablesType
Indices Types of the variables.
- variablesType
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.
- 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 aFunctionwhoseisLinear()method returns True. It is converted to the linear constraints, where
is the transpose of its gradient at the origin and
for a function
such that
is the expected equality constraint. Existing inequality constraints are preserved.
- Parameters:
- equalityConstraint
Function Linear equality constraint
. An empty function clears the equality constraints.
- equalityConstraint
- setHessian(hessian)¶
Accessor to the Hessian matrix.
- Parameters:
- hessian
SymmetricMatrix The symmetric positive semi-definite Hessian matrix.
- hessian
- setInequalityConstraint(inequalityConstraint)¶
Set the inequality constraint function.
The function must be linear: either a
LinearFunction, or aFunctionwhoseisLinear()method returns True. It is converted to the linear constraints, where
is the transpose of its gradient at the origin and
for a function
such that
is the expected inequality constraint. Existing equality constraints are preserved.
- Parameters:
- inequalityConstraint
Function Linear inequality constraint
. An empty function clears the inequality constraints.
- inequalityConstraint
- setLevelFunction(levelFunction)¶
Accessor to level function.
- Parameters:
- levelFunction
Function Level function.
- levelFunction
- setLevelValue(levelValue)¶
Accessor to level value.
- Parameters:
- levelValuefloat
Level value.
- setLinearConstraint(constraintCoefficients, constraintBounds)¶
Accessor to the linear constraints.
Each row
of the constraint matrix defines
, where
and
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.
- 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:
- objectiveFunction
Function Objective function.
- objectiveFunction
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:
- levelFunction
Function Level function.
- levelFunction
- setVariablesType(variableType)¶
Accessor to the variables type.
- Parameters:
- variablesType
Indices Types of the variables.
- variablesType
Notes
Possible values for each variable are ot.OptimizationProblemImplementation.CONTINUOUS, ot.OptimizationProblemImplementation.INTEGER and ot.OptimizationProblemImplementation.BINARY.
OpenTURNS