LinearProgrammingProblem

class LinearProgrammingProblem(*args)

Linear 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 linear problem as:

\min_{\vect{x} \in B} f(\vect{x}) = \vect{c}^T \vect{x} + d \\
\vect{lc_l} \leq \mat{A} \vect{x} \leq \vect{lc_u}

where B are the problem bounds, \vect{c} is the cost vector, d is a constant term, \mat{A} is the constraint matrix term, and \vect{cb_l}, \vect{cb_u} are the constraints bounds terms.

Parameters:
costsequence of float

The cost vector \vect{c}.

boundsInterval

Bound constraints B

AMatrix or SparseMatrix

Linear inequality constraints matrix \mat{A}. The sparse form avoids storing the zero coefficients of a large sparse problem.

cbInterval

Linear inequality constraints bounds terms \vect{cb_l}, \vect{cb_u}

constantfloat, optional

The constant term d. Default is 0.

Methods

Linearize(problem, location)

Transform a general optimization problem to a linear 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 term.

getLinearCost()

Accessor to the linear cost.

getName()

Accessor to the object's name.

getObjective()

Accessor to objective function.

getResidualFunction()

Accessor to level function.

getSparseLinearConstraintCoefficients()

Accessor to the linear constraint term in sparse form.

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.

setInequalityConstraint(inequalityConstraint)

Set the inequality constraint function.

setLevelFunction(levelFunction)

Accessor to level function.

setLevelValue(levelValue)

Accessor to level value.

setLinearConstraint(*args)

Accessor to the linear constraint term.

setLinearCost(cost)

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.

Notes

The constraint matrix is stored in compressed sparse column form (see SparseMatrix). Passing a dense Matrix converts it once and drops its zero coefficients; passing a SparseMatrix stores it as is. A large sparse problem should therefore be built from a sparse matrix, as a dense one would need 8 m n bytes for m constraints and n variables.

getLinearConstraintCoefficients() rebuilds the dense matrix, while getSparseLinearConstraintCoefficients() returns the sparse coefficients without densifying them.

Examples

Define a mixed integer linear optimization problem with objective:

f = 1.1 x_0 + x_1, x_0 \in \Zset, x_1 \in \Rset

with inequality constraints:

\begin{eqnarray*}
    & x_1 & \leq 7\\
    5 & \leq x_0 + 2x_1 & \leq 15\\
    6 & \leq 3x_0 + 2x_1 & \\
\end{eqnarray*}

and bound constraints:

\begin{eqnarray*}
    0 & \leq x_0 & \leq 4\\
    1 & \leq x_1 &
\end{eqnarray*}

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> cost = [1.1, 1.0]
>>> bounds = ot.Interval([0.0, 1.0], [4.0, 1e30], [True, True], [True, False])
>>> A = ot.Matrix([[0.0, 1.0], [1.0, 2.0], [3.0, 2.0]])
>>> lcb = ot.Interval([-1e9, 5.0, 6.0], [7.0, 15.0, 1e9], [False, True, True], [True, True, False])
>>> problem = otexp.LinearProgrammingProblem(cost, bounds, A, lcb)
>>> problem.setVariablesType([ot.OptimizationProblemImplementation.INTEGER, ot.OptimizationProblemImplementation.CONTINUOUS])

The same problem can be defined from the sparse constraint matrix, which only stores the non-zero coefficients. The triplets are given by their row index, their column index and their value; duplicate coordinates are summed:

>>> A = otexp.SparseMatrix(3, 2, [0, 1, 1, 2, 2], [1, 0, 1, 0, 1], [1.0, 1.0, 2.0, 3.0, 2.0])
>>> print(A.asDenseMatrix())
[[ 0 1 ]
 [ 1 2 ]
 [ 3 2 ]]
>>> problem = otexp.LinearProgrammingProblem(cost, bounds, A, lcb)
>>> print(problem.getSparseLinearConstraintCoefficients().getNbNonZeros())
5
__init__(*args)
static Linearize(problem, location)

Transform a general optimization problem to a linear problem.

Objective and inequality constraints coefficients are computed from their gradients at the specified location. The constant term of the linearized objective is set so that it matches the original objective at the location.

Parameters:
problemOptimizationProblem

The problem to linearize

locationsequence of float

The linearization location

Returns:
linearProblemLinearProgrammingProblem

The linear 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.

Only relevant for the quadratic problem type.

Returns:
hessianSymmetricMatrix

Hessian matrix of the quadratic objective.

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.

Only relevant for the linear problem type.

Returns:
LUInterval

Linear inequality constraint bounds.

getLinearConstraintCoefficients()

Accessor to the linear constraint term.

Only relevant for the linear problem type.

Returns:
AMatrix

Linear inequality constraint term.

Notes

A sparse problem materializes the dense matrix on demand. The experimental LinearProgrammingProblem provides getSparseLinearConstraintCoefficients() to avoid the densification.

getLinearCost()

Accessor to the linear cost.

Only relevant for the linear problem type.

Returns:
costPoint

Linear cost term.

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.

getSparseLinearConstraintCoefficients()

Accessor to the linear constraint term in sparse form.

The constraint matrix is returned in compressed sparse column form, without being densified.

Returns:
ASparseMatrix

Linear inequality constraint term.

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.

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(*args)

Accessor to the linear constraint term.

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 or SparseMatrix

Linear constraint matrix.

cbInterval

Linear constraint bounds.

setLinearCost(cost)

Accessor to the linear cost.

Parameters:
costPoint

Linear cost term.

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

Unit commitment

Unit commitment