14.2.2 Class BaseVariable¶
- mosek.fusion.BaseVariable¶
An abstract variable object. This is class provides various default implementations of methods in
Variable
.- Members
BaseVariable.antidiag – Return the antidiagonal of a square variable matrix.
BaseVariable.asExpr – Create an expression corresponding to the variable object.
BaseVariable.diag – Return the diagonal of a square variable matrix.
BaseVariable.dual – Get the dual solution value of the variable.
BaseVariable.eval – Evaluate the expression and push the result onto the work stack.
BaseVariable.fromTril – Convert from a trilinear representation into a square variable.
BaseVariable.getDim – Return the d’th dimension in the expression.
BaseVariable.getModel – Get the Model object that the variable belongs to.
BaseVariable.getND – Get the number of dimensions in the variable shape.
BaseVariable.getShape – Get the variable shape.
BaseVariable.getSize – Get the total number of elements in the variable.
BaseVariable.index ([]) – Return a variable slice of size 1 corresponding to a single element in the variable object..
BaseVariable.level – Get the primal solution value of the variable.
BaseVariable.makeContinuous – Drop integrality constraints on the variable, if any.
BaseVariable.makeInteger – Apply integrality constraints on the variable. Has no effect on elements of semidefinite matrix variables.
BaseVariable.pick ([]) – Create a one-dimensional variable by picking a list of indexes from this variable.
BaseVariable.remove – Remove the variable from the model.
BaseVariable.reshape – Reshape the variable. The new shape must have the same total size as the current.
BaseVariable.setLevel – Input solution values for this variable
BaseVariable.slice ([]) – Create a slice variable by picking a range of indexes for each variable dimension.
BaseVariable.toString – Create a string representation of the variable.
BaseVariable.transpose – Transpose the variable.
BaseVariable.tril – Convert from a square variable to a trilinear representation.
- Implemented by
- BaseVariable.antidiag¶
antidiag() -> Variable antidiag(int index) -> Variable
Return the antidiagonal of a square variable matrix.
- Parameters
index
(int
) – Index of the anti-diagonal- Return
(
Variable
)
- BaseVariable.asExpr¶
asExpr() -> Expression
Create an
Expression
object corresponding to \(I\cdot V\), where \(I\) is the identity matrix and \(V\) is this variable.- Return
- BaseVariable.diag¶
diag() -> Variable diag(int index) -> Variable
Return the diagonal of a square variable matrix.
- Parameters
index
(int
) – Index of the anti-diagonal- Return
(
Variable
)
- BaseVariable.dual¶
dual() -> float[]
Get the dual solution value of the variable as an array. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.
- Return
(
float
[])
- BaseVariable.eval¶
eval(WorkStack rs, WorkStack ws, WorkStack xs)
Evaluate the expression and push the result onto the
rs
work stack.
- BaseVariable.fromTril¶
fromTril(int d) -> Variable fromTril(int dim0, int d) -> Variable
Convert from a trilinear representation into a square variable.
- Parameters
d
(int
) – Dimension of the square variable.dim0
(int
) – Index of the trilinear variable slices in a multi-dimensional representation.
- Return
(
Variable
)
- BaseVariable.getDim¶
getDim(int d) -> int
Return the d’th dimension in the expression.
- Parameters
d
(int
)- Return
(
int
)
- BaseVariable.getModel¶
getModel() -> Model
Get the Model object that the variable belongs to.
- Return
(
Model
)
- BaseVariable.getND¶
getND() -> int
Get the number of dimensions in the variable shape.
- Return
(
int
)
- BaseVariable.getShape¶
getShape() -> int[]
Get the variable shape.
- Return
(
int
[])
- BaseVariable.getSize¶
getSize() -> int
Get the total number of elements in the variable.
- Return
(
int
)
- BaseVariable.index ([])¶
index(int index) -> Variable index(int[] index) -> Variable index(int i0, int i1) -> Variable index(int i0, int i1, int i2) -> Variable
Return a variable slice of size 1 corresponding to a single element in the variable object..
The standard Python operator
[]
can also be used for this purpose. See Sec. 14.1.3 (Pythonic extensions) for details.- Parameters
index
(int
)index
(int
[])i0
(int
) – Index in the first dimension of the element requested.i1
(int
) – Index in the second dimension of the element requested.i2
(int
) – Index in the second dimension of the element requested.
- Return
(
Variable
)
- BaseVariable.level¶
level() -> float[]
Get the primal solution value of the variable as an array. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.
- Return
(
float
[])
- BaseVariable.makeContinuous¶
makeContinuous()
Drop integrality constraints on the variable, if any.
- BaseVariable.makeInteger¶
makeInteger()
Apply integrality constraints on the variable. Has no effect on elements of semidefinite matrix variables.
- BaseVariable.pick ([])¶
pick(int[] idxs) -> Variable pick(int[][] midxs) -> Variable pick(int[] i0, int[] i1) -> Variable pick(int[] i0, int[] i1, int[] i2) -> Variable
Create a one-dimensional variable by picking a list of indexes from this variable.
The standard Python operator
[]
can also be used for this purpose. See Sec. 14.1.3 (Pythonic extensions) for details.- Parameters
idxs
(int
[]) – Indexes of the elements requested.midxs
(int
[][]) – A sequence of multi-dimensional indexes of the elements requested.i0
(int
[]) – Index along the first dimension.i1
(int
[]) – Index along the second dimension.i2
(int
[]) – Index along the third dimension.
- Return
(
Variable
)
- BaseVariable.remove¶
remove()
Remove the variable from the model and remove it from any constraints where it appears. Using the variable object after this method has been called results in undefined behavior.
- BaseVariable.reshape¶
reshape(int[] shape) -> Variable reshape(int dim0) -> Variable reshape(int dim0, int dim1) -> Variable reshape(int dim0, int dim1, int dim2) -> Variable
Reshape the variable. The new shape must have the same total size as the current.
- Parameters
shape
(int
[]) – The new shape.dim0
(int
) – First dimension of new shapedim1
(int
) – Second dimension of new shapedim2
(int
) – Third dimension of new shape
- Return
(
Variable
)
- BaseVariable.setLevel¶
setLevel(float[] v)
Set values for an initial solution for this variable. Note that these values are buffered until the solver is called; they are not available through the
level()
methods.- Parameters
v
(float
[]) – An array of values to be assigned to the variable.
- BaseVariable.slice ([])¶
slice(int first, int last) -> Variable slice(int[] first, int[] last) -> Variable
Create a slice variable by picking a range of indexes for each variable dimension.
The standard Python operator
[]
can also be used for this purpose. See Sec. 14.1.3 (Pythonic extensions) for details.- Parameters
first
(int
) – The index from which the slice begins.first
(int
[]) – The index from which the slice begins.last
(int
) – The index after the last element of the slice.last
(int
[]) – The index after the last element of the slice.
- Return
(
Variable
)
- BaseVariable.toString¶
toString() -> str
Create a string representation of the variable.
- Return
(
str
)
- BaseVariable.transpose¶
transpose() -> Variable
Return the transpose of the current variable. The variable must have at most two dimensions.
- Return
(
Variable
)
- BaseVariable.tril¶
tril() -> Variable tril(int dim1, int dim2) -> Variable
Convert from a square variable to a trilinear representation.
- Parameters
dim1
(int
) – First dimension in the current shape containing the square variables.dim2
(int
) – Second dimension in the current shape containing the square variables.
- Return
(
Variable
)