Skip to content

Latest commit

 

History

History
273 lines (178 loc) · 7.75 KB

common_model_interface.md

File metadata and controls

273 lines (178 loc) · 7.75 KB

Common Model Interface

Generally speaking, the following APIs are common to all optimizers except for adding constraint because different optimizers may support different types of constraints.

Model

Get/set model attributes


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

Variable

Add a variable to the model


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 multidimensional variables to the model as project:#pyoptinterface.tupledict


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 multidimensional variables to the model as numpy.ndarray


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

Get/set variable attributes


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 variable


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

Modify the bounds of variable


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

Expression

Get the value of an expression (including variable)


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 expression (including variable)


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

Constraint

Add a constraint to the model

  • 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


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

Get/set constraint attributes


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 constraint


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

Modify constraint


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

Objective

Set the objective function


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 linear part of the objective function


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