# 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¶
double[] Dual()

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
(

`double`

[])

- Constraint.GetModel¶
Model GetModel()

Return the model that the constraint belongs to.

- Return
(

`Model`

)

- Constraint.GetND¶
int GetND()

Return the number of dimensions in the constraint shape.

- Return
(

`int`

)

- Constraint.GetShape¶
int[] GetShape()

Return the constraint’s shape.

- Return
(

`int`

[])

- Constraint.GetSize¶
int GetSize()

Return the total number of elements in the constraint.

- Return
(

`int`

)

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

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¶
Constraint Index(int idx) Constraint Index(int[] idxa)

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¶
double[] Level()

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
(

`double`

[])

- Constraint.Remove¶
void Remove()

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

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

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 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)

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¶
string ToString()

Create a human readable string representation of the constraint.

- Return
(

`string`

)

- Constraint.Update¶
void Update(Expression expr, Variable x) void Update(Expression expr, Variable x, bool bfixupdate) void Update(Expression expr) void Update(double[] 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`

(`double`

[]) – The fixed term to update with.

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

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