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:

ModelConstraint, SliceConstraint

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)

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)

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)

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)

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, boolean 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 (boolean) – 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:

(Constraint)