14.2.42 Class Variable¶
- mosek.fusion.Variable¶
An abstract variable object. This is the base class for all variable types in Fusion, and it contains several methods for manipulating variable objects.
The
Variable
object can be an interface to the normal model variables, e.g.LinearVariable
andConicVariable
, to slices of other variables or to concatenations of other variables.Primal and dual solution values can be accessed through the
Variable
object.More static methods to manipulate variables are available in the
Var
class.- Implements
- Members
Expression.eval – Evaluate the expression and push the result onto the work stack.
Expression.getDim – Return the d’th dimension in the expression.
Variable.antidiag – Return the anti-diagonal of a variable matrix.
Variable.asExpr – Create an expression corresponding to the variable object.
Variable.diag – Return the diagonal of a variable matrix.
Variable.dual – Get the dual solution value of the variable.
Variable.fromTril – Convert from a linear representation of the lower triangular part of a square variable into a square variable.
Variable.getModel – Return the model to which the variable belongs.
Variable.getND – Get the number of dimensions in the variable shape.
Variable.getShape – Return the shape of the variable.
Variable.getSize – Get the total number of elements in the variable.
Variable.index ([]) – Return a single entry in the variable.
Variable.level – Return the primal value of the variable as an array.
Variable.makeContinuous – Drop integrality constraints on the variable, if any.
Variable.makeInteger – Apply integrality constraints on the variable. Has no effect on elements of semidefinite matrix variables.
Variable.pick ([]) – Create a one-dimensional variable by picking a list of indexes from this variable.
Variable.remove – Remove the variable from the model.
Variable.reshape – Reshape the variable. The new shape must have the same total size as the current.
Variable.setLevel – Input solution values for this variable
Variable.slice ([]) – Create a slice variable by picking a range of indexes for each variable dimension.
Variable.toString – Create a string representation of the variable.
Variable.transpose (.T) – Transpose the variable.
Variable.tril – Convert a square variable into a linear representation of the lower triangular part of the variable.
- Implemented by
- Variable.antidiag¶
antidiag(int index) -> Variable antidiag() -> Variable
Return the anti-diagonal of a variable matrix in a one-dimensional variable object. The main anti-diagonal is defined as starting with the element in the first row and last column.
- Parameters
index
(int
) – Index of the anti-diagonal. Index 0 means the main anti-diagonal, negative indices are below it and positive indices are above it.- Return
(
Variable
)
- Variable.asExpr¶
asExpr() -> Expression
Create an
Expression
object corresponding to \(I\cdot V\), where \(I\) is the identity matrix and \(V\) is this variable.- Return
- Variable.diag¶
diag(int index) -> Variable diag() -> Variable
Return the diagonal of a square variable matrix in a one-dimensional variable object. The main diagonal is defined as starting with the element in the first row and first column.
- Parameters
index
(int
) – Index of the diagonal. Index 0 means the main diagonal, negative indices are below it and positive indices are above it.- Return
(
Variable
)
- Variable.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
[])
- Variable.fromTril¶
fromTril(int dim) -> Variable
Convert from a linear representation of the lower triangular part of a square variable into a square variable.
- Parameters
dim
(int
) – Dimension of the square variable.- Return
(
Variable
)
- Variable.getModel¶
getModel() -> Model
Get the Model object that the variable belongs to.
- Return
(
Model
)
- Variable.getND¶
getND() -> int
Get the number of dimensions in the variable shape.
- Return
(
int
)
- Variable.getShape¶
getShape() -> int[]
Get the variable shape.
- Return
(
int
[])
- Variable.getSize¶
getSize() -> int
Get the total number of elements in the variable.
- Return
(
int
)
- Variable.index ([])¶
index(int i1) -> Variable index(int i1, int i2) -> Variable index(int i1, int i2, int i3) -> Variable index(int[] idx) -> Variable
Return a variable of size one 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
i1
(int
) – Index in the first dimension of the element requested.i2
(int
) – Index in the second dimension of the element requested.i3
(int
) – Index in the third dimension of the element requested.idx
(int
[]) – List of indexes of the elements requested.
- Return
(
Variable
)
- Variable.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
[])
- Variable.makeContinuous¶
makeContinuous()
Drop integrality constraints on the variable, if any.
- Variable.makeInteger¶
makeInteger()
Apply integrality constraints on the variable. Has no effect on elements of semidefinite matrix variables.
- Variable.pick ([])¶
pick(int[] idxs) -> Variable pick(int[][] midxs) -> Variable pick(int[] i1, int[] i2) -> Variable pick(int[] i1, int[] i2, int[] i3) -> 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.i1
(int
[]) – Index along the first dimension.i2
(int
[]) – Index along the second dimension.i3
(int
[]) – Index along the third dimension.
- Return
(
Variable
)
- Variable.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.
- Variable.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
)
- Variable.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.
- Variable.slice ([])¶
slice(int first, int last) -> Variable slice(int[] firsta, int[] lasta) -> 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.last
(int
) – The index after the last element of the slice.firsta
(int
[]) – The indices from which the slice of a multidimensional variable begins.lasta
(int
[]) – The indices after the last element of slice of a multidimensional variable.
- Return
(
Variable
)
- Variable.toString¶
toString() -> str
Create a string representation of the variable.
- Return
(
str
)
- Variable.transpose (.T)¶
transpose() -> Variable
Return the transpose of the current variable. The variable must have at most two dimensions.
The standard Python operator
.T
can also be used for this purpose. See Sec. 14.1.3 (Pythonic extensions) for details.- Return
(
Variable
)