# 14.2.8 Class Constraint¶

- mosek.fusion.Constraint¶
An abstract constraint object. This is the base class for all constraint types in Fusion.

The

`Constraint`

object can be an interface to the normal model constraint, e.g.`LinearConstraint`

and`ConicConstraint`

, to slices of other constraints or to concatenations of other constraints.Primal and dual solution values can be accessed through the

`Constraint`

object.- Members:
Constraint.dual – Get the dual solution values of the constraint.

Constraint.getModel – Return the model that the constraint belongs to.

Constraint.getND – Return the number of dimensions in the constraint shape.

Constraint.getShape – Return the constraint’s shape.

Constraint.getSize – Return the total number of elements in the constraint.

Constraint.index – Get a single element from a constraint.

Constraint.level – Get the primal solution values of the constraint.

Constraint.remove – Remove the constraint from the model.

Constraint.slice – Create a slice constraint.

Constraint.toString – Create a human readable string representation of the constraint.

Constraint.update – Update part of a constraint.

- Static members:
Constraint.hstack – Stack a number of constraints horizontally.

Constraint.stack – Stack a number of constraints.

Constraint.vstack – Stack a number of constraints vertically.

- Implemented by:

- Constraint.dual¶
dual() -> float[]

Get the dual solution values of the constraint or its slice. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.

- Return:
(

`float`

[])

- Constraint.getModel¶
getModel() -> Model

Return the model that the constraint belongs to.

- Return:
(

`Model`

)

- Constraint.getND¶
getND() -> int

Return the number of dimensions in the constraint shape.

- Return:
(

`int`

)

- Constraint.getShape¶
getShape() -> int[]

Return the constraint’s shape.

- Return:
(

`int`

[])

- Constraint.getSize¶
getSize() -> int

Return the total number of elements in the constraint.

- Return:
(

`int`

)

- Constraint.hstack¶
Constraint.hstack(Constraint v1, Constraint v2) -> Constraint Constraint.hstack(Constraint v1, Constraint v2, Constraint v3) -> Constraint Constraint.hstack(Constraint[] clist) -> Constraint

Stack a number of constraints horizontally.

- Parameters:
`v1`

(`Constraint`

) – The first constraint in the stack.`v2`

(`Constraint`

) – The second constraint in the stack.`v3`

(`Constraint`

) – The third constraint in the stack.`clist`

(`Constraint`

[]) – The constraints in the stack.

- Return:

- Constraint.index¶
index(int idx) -> Constraint index(int[] idxa) -> Constraint

Get a single element from a one-dimensional constraint.

- Parameters:
`idx`

(`int`

) – The index of the element.`idxa`

(`int`

[]) – A multi-dimensional index of the element.

- Return:

- Constraint.level¶
level() -> float[]

Get the primal solution values of the constraint. This amounts to evaluating the \(Ax\) part of the constraint expression for the relevant solution value. When the selected slice is multi-dimensional, this corresponds to the flattened slice of solution values.

- Return:
(

`float`

[])

- Constraint.remove¶
remove()

Remove the constraint from the model. Using the constraint object after this method has been called results in undefined behavior.

- Constraint.slice¶
slice(int first, int last) -> Constraint slice(int[] firsta, int[] lasta) -> Constraint

Create a slice constraint.

- Parameters:
`first`

(`int`

) – Index of the first element in the slice.`last`

(`int`

) – Index of the first element after the end of the slice.`firsta`

(`int`

[]) – The indexes of first elements in the slice along each dimension.`lasta`

(`int`

[]) – The indexes of first elements after the end of the slice along each dimension.

- Return:

- Constraint.stack¶
Constraint.stack(Constraint v1, Constraint v2, int dim) -> Constraint Constraint.stack(Constraint v1, Constraint v2, Constraint v3, int dim) -> Constraint Constraint.stack(Constraint[] clist, int dim) -> Constraint

Stack a number of constraints.

- Parameters:
`v1`

(`Constraint`

) – The first constraint in the stack.`v2`

(`Constraint`

) – The second constraint in the stack.`dim`

(`int`

) – The dimension in which to stack, 0 means vertically.`v3`

(`Constraint`

) – The third constraint in the stack.`clist`

(`Constraint`

[]) – The constraints in the stack.

- Return:

- Constraint.toString¶
toString() -> str

Create a human readable string representation of the constraint.

- Return:
(

`str`

)

- Constraint.update¶
update(Expression expr, Variable x) update(Expression expr, Variable x, bool bfixupdate) update(Expression expr) update(float[] bfix)

Update entire or part of the left-hand side of a constraint (the expression). See Sec. 7.10 (Problem Modification and Reoptimization) for a tutorial.

If only

`expr`

is given, replace the entire previous expression with`expr`

. The shape of`expr`

must match the shape of the constraint.If only

`bfix`

is given, replace the constant term of the expression with`bfix`

. The length of`bfix`

must match the size of the expression.If

`x`

is given, replace all columns in the constraint defined by`x`

by terms defined by`expr`

, possibly including constant terms. Currently it is only possible to update linear columns. Attempting to update columns of semidefinite variables will result in an error.- Parameters:
`expr`

(`Expression`

) – The expression to update with.`x`

(`Variable`

) – Variable object defining the columns to update.`bfixupdate`

(`bool`

) – Whether to include fixed terms as well.`bfix`

(`float`

[]) – The fixed term to update with.

- Constraint.vstack¶
Constraint.vstack(Constraint v1, Constraint v2) -> Constraint Constraint.vstack(Constraint v1, Constraint v2, Constraint v3) -> Constraint Constraint.vstack(Constraint[] clist) -> Constraint

Stack a number of constraints vertically.

- Parameters:
`v1`

(`Constraint`

) – The first constraint in the stack.`v2`

(`Constraint`

) – The second constraint in the stack.`v3`

(`Constraint`

) – The third constraint in the stack.`clist`

(`Constraint`

[]) – The constraints in the stack.

- Return: