Generally speaking, the following APIs are common to all optimizers except for adding constraint because different optimizers may support different types of constraints.
set the value of a model attribute
:param pyoptinterface.ModelAttribute attr: the attribute to set
:param value: the value to set
get the value of a model attribute
:param pyoptinterface.ModelAttribute attr: the attribute to get
:return: the value of the attribute
add a variable to the model
:param float lb: the lower bound of the variable, optional, defaults to $-\infty$
:param float ub: the upper bound of the variable, optional, defaults to $+\infty$
:param pyoptinterface.VariableDomain domain: the domain of the variable, optional, defaults to
continuous
:param str name: the name of the variable, optional
:return: the handle of the variable
add a multidimensional variable to the model
:param coords: the coordinates of the variable, can be a list of Iterables
:param float lb: the lower bound of the variable, optional, defaults to $-\infty$
:param float ub: the upper bound of the variable, optional, defaults to $+\infty$
:param pyoptinterface.VariableDomain domain: the domain of the variable, optional, defaults to
continuous
:param str name: the name of the variable, optional
:return: the multi-dimensional variable
:rtype: pyoptinterface.tupledict
add a multidimensional variable to the model as `numpy.ndarray`
:param shape: the shape of the variable, can be a tuple of integers or an integer
:param float lb: the lower bound of the variable, optional, defaults to $-\infty$
:param float ub: the upper bound of the variable, optional, defaults to $+\infty$
:param pyoptinterface.VariableDomain domain: the domain of the variable, optional, defaults to
continuous
:param str name: the name of the variable, optional
:return: the multidimensional variable
:rtype: numpy.ndarray
set the value of a variable attribute
:param var: the handle of the variable
:param pyoptinterface.VariableAttribute attr: the attribute to set
:param value: the value to set
get the value of a variable attribute
:param var: the handle of the variable
:param pyoptinterface.VariableAttribute attr: the attribute to get
:return: the value of the attribute
delete a variable from the model
:param var: the handle of the variable
query whether a variable is active
:param var: the handle of the variable
:return: whether the variable is active
:rtype: bool
set the lower and upper bounds of a variable
:param var: the handle of the variable
:param float lb: the new lower bound value
:param float ub: the new upper bound value
get the value of an expression or a variable after optimization
:param expr_or_var: the handle of the expression or the variable
:return: the value of the expression or the variable
:rtype: float
pretty print an expression in a human-readable format
:param expr_or_var: the handle of the expression or the variable
:return: the human-readable format of the expression
:rtype: str
- project:#model.add_linear_constraint
- project:#model.add_quadratic_constraint
- project:#model.add_second_order_cone_constraint
- project:#model.add_sos_constraint
add linear constraints as matrix form to the model $Ax \le b$ or $Ax = b$ or $Ax \ge b$
:param A: the matrix of coefficients, can be a dense `numpy.ndarray` or a sparse matrix `scipy.sparse.sparray`
:param vars: the variables in the constraints, can be a list or a 1-d `numpy.ndarray` returned by `add_m_variables`
:param pyoptinterface.ConstraintSense sense: the sense of the constraints
:param b: the right-hand side of the constraints, should be a 1-d `numpy.ndarray`
:param str name: the name of the constraints, optional
:return: the handles of linear constraints
:rtype: numpy.ndarray
set the value of a constraint attribute
:param con: the handle of the constraint
:param pyoptinterface.ConstraintAttribute attr: the attribute to set
:param value: the value to set
get the value of a constraint attribute
:param con: the handle of the constraint
:param pyoptinterface.ConstraintAttribute attr: the attribute to get
:return: the value of the attribute
delete a constraint from the model
:param con: the handle of the constraint
query whether a constraint is active
:param con: the handle of the constraint
:return: whether the variable is active
:rtype: bool
set the right-hand side of a normalized constraint
:param con: the handle of the constraint
:param value: the new right-hand side value
get the right-hand side of a normalized constraint
:param con: the handle of the constraint
:return: the right-hand side value
set the coefficient of a variable in a normalized constraint
:param con: the handle of the constraint
:param var: the handle of the variable
:param value: the new coefficient value
get the coefficient of a variable in a normalized constraint
:param con: the handle of the constraint
:param var: the handle of the variable
:return: the coefficient value
set the objective function of the model
:param expr: the handle of the expression
:param pyoptinterface.ObjectiveSense sense: the sense of the objective function (Minimize/Maximize), defaults to Minimize
modify the coefficient of a variable in the linear part of the objective function
:param var: the handle of the variable
:param float value: the new coefficient value
get the coefficient of a variable in the linear part of the objective function
:param var: the handle of the variable
:return: the coefficient value